Export dexterity contents in an excel file, one column by field
Project description
======================
collective.excelexport
======================
What does this product
======================
This product provides tools to provide excel exports to Plone users,
under xls or csv format.
A framework, with default utilities to export the dexterity contents of a folder,
the results of a catalog search,
and the results of a eea faceted navigation search.
Many field types are managed (text, list, file, boolean, datagrid...).
Try @@collective.excelexport view on any folder containing dexterity elements.
Try @@collective.excelexport?excelexport.policy=excelexport.search&review_state=published on site root.
Try @@collective.excelexportcsv view on any folder for csv export.
How to extend it
================
Datasources
-----------
If you want to implement a new way to get content to export,
you can register a #datasource#,
wich is an adapter for collective.excelexport.interfaces.IDataSource interface.
This adapter can be a named one.
You will call this datasource calling the view @@collective.excelexport?excelexport.policy=datasourcename
See the IDataSource interface for more information
Exportables (excel sheet columns)
---------------------------------
If you want to define new columns for your excel export, you will write or override: ::
- Exportable factories, adapters for IExportableFactory interface that provides a list of Exportables
- Exportables, that define columns.
Example of an exportable factory: ::
from plone.dexterity.interfaces import IDexterityFTI
from collective.excelexport.exportables.base import BaseExportableFactory
from collective.excelexport.exportables.dexterityfields import get_ordered_fields
from collective.excelexport.exportables.dexterityfields import get_exportable
from collective.excelexport.exportables.dexterityfields import ParentField
from collective.excelexport.exportables.dexterityfields import GrandParentField
class PSTActionFieldsFactory(BaseExportableFactory):
adapts(IDexterityFTI, Interface, Interface)
portal_types = ('pstaction',)
def get_exportables(self):
portal_types = api.portal.get_tool('portal_types')
action_fti = portal_types['pstaction']
oo_fti = portal_types['operationalobjective']
os_fti = portal_types['strategicobjective']
fields = []
fields.extend([get_exportable(
field[1], self.context, self.request)
for field in get_ordered_fields(action_fti)])
fields.extend([get_exportable(
ParentField(field[1]), self.context, self.request)
for field in get_ordered_fields(oo_fti)])
fields.extend([get_exportable(
GrandParentField(field[1]), self.context, self.request)
for field in get_ordered_fields(os_fti)])
return fields
Dexterity exportables
---------------------
You have a complete set of exportables for dexterity fields.
Those are multi-adapters of field, context and request.
You can override them declaring a more specific adapter.
You can also declare a named adapter with the field name if you want a specific
rendering for one field.
Styles
------
If you don't feel good with default styles, you can register a specific one for: ::
- the export policy
- the context
- the layer
You just have to register a new IStyle adapter, in a zcml: ::
<adapter for="zope.interface.Interface
.interfaces.IThemeSpecific"
factory=".excelstyles.MyNeutralStyle"
provides="collective.excelexport.interfaces.IStyles"
/>
If you do not specify the name, the styles will be registered for all policies.
and in python: ::
class MyNeutralStyle(Styles):
content = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold off; '
'align: wrap off, vert centre, horiz left;'
'borders: top thin, bottom thin, left thin, right thin;'
'pattern: pattern solid, back_colour white, fore_colour white'
)
headers = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold on; '
'align: wrap off, vert centre, horiz left; '
'borders: top thin, bottom thin, left thin, right thin; '
'pattern: pattern solid, back_colour white, fore_colour white; '
)
plone.restapi
=============
To get an export via rest api, query @collective.excelexport / @collective.excelexportcsv (with one @)
Tests
=====
This add-on is tested using Travis CI. The current status of the add-on is :
.. image:: https://secure.travis-ci.org/collective/collective.excelexport.png
:target: http://travis-ci.org/collective/collective.excelexport
.. image:: https://coveralls.io/repos/collective/collective.excelexport/badge.png?branch=master
:target: https://coveralls.io/r/collective/collective.excelexport?branch=master
Contributors
============
- Thomas Desvenain, thomas.desvenain@gmail.com
Changelog
=========
1.7 (2018-06-22)
----------------
- Added plone.restapi service.
[thomasdesvenain]
- Fixed csv export mimetype.
- Added helper method get_exportable_for_fieldname.
[gbastien]
1.6 (2018-01-05)
----------------
- Fix: no limit for number of results in eeafaceted datasource.
[cedricmessiant]
1.5 (2017-11-28)
----------------
- Upgrade bootstrap.
[sgeulette]
- Fix: render choice field with source vocabulary
[sgeulette]
1.4 (2017-05-31)
----------------
- Prevent removal of exportables with similar names when ordering them
[thomasdesvenain]
- Refactor: view exposes method that creates data buffer from sheet data.
[thomasdesvenain]
- Made correct release
[sgeulette]
1.3 (2016-11-28)
----------------
- Fix: check if value_type is empty for collection field render.
[bsuttor]
- Fix: try to get the value of a method if the field is a method and translate
DateTime results to a unicode, this fixes the export for objects with the IPublication
Behavior.
[pcdummy]
- Fix: be sure to not retrieve an attribute on an object by acquisition.
[vincentfretin]
- Feature: render_style can now return a Style object with content and headers
attribute to be able to customise the header style per exportable.
[vincentfretin]
- Feature: the passed obj to render_value is now
exportable.field.bind(obj).context to make it easier to get data from
parent or grandparent.
[vincentfretin]
- Feature: BaseFieldRenderer.render_header method returns now the translated field
title instead of the Message object.
[vincentfretin]
- Fix: Ignore reverse parameter when creating export url.
[cedricmessiant]
- Feature: Add sort exportables feature using exportables_order list.
Works with field and non-field exportables.
[cedricmessiant, ebrehault, thomasdevenain]
1.2 (2014-09-10)
----------------
- Feature: Added export under csv format.
[thomasdesvenain]
- API: Filter exportables by field name by default using excluded_exportables list.
[cedricmessiant]
- API: We can define a dexterity adapter for just one field using field name as
adapter name.
[thomasdesvenain]
- Fix: Faceted nav export link ignores results per page criterion.
[thomasdesvenain]
- Fix: Translate sheet title.
[thomasdesvenain]
- Fix: Improve text fields support.
[fngaha, thomasdesvenain]
1.1 (2014-06-19)
----------------
- Rename search policy excelexport.search to avoid conflict with 'search' view.
[thomasdesvenain]
1.0 (2014-06-02)
----------------
- Initial release.
[thomasdesvenain]
collective.excelexport
======================
What does this product
======================
This product provides tools to provide excel exports to Plone users,
under xls or csv format.
A framework, with default utilities to export the dexterity contents of a folder,
the results of a catalog search,
and the results of a eea faceted navigation search.
Many field types are managed (text, list, file, boolean, datagrid...).
Try @@collective.excelexport view on any folder containing dexterity elements.
Try @@collective.excelexport?excelexport.policy=excelexport.search&review_state=published on site root.
Try @@collective.excelexportcsv view on any folder for csv export.
How to extend it
================
Datasources
-----------
If you want to implement a new way to get content to export,
you can register a #datasource#,
wich is an adapter for collective.excelexport.interfaces.IDataSource interface.
This adapter can be a named one.
You will call this datasource calling the view @@collective.excelexport?excelexport.policy=datasourcename
See the IDataSource interface for more information
Exportables (excel sheet columns)
---------------------------------
If you want to define new columns for your excel export, you will write or override: ::
- Exportable factories, adapters for IExportableFactory interface that provides a list of Exportables
- Exportables, that define columns.
Example of an exportable factory: ::
from plone.dexterity.interfaces import IDexterityFTI
from collective.excelexport.exportables.base import BaseExportableFactory
from collective.excelexport.exportables.dexterityfields import get_ordered_fields
from collective.excelexport.exportables.dexterityfields import get_exportable
from collective.excelexport.exportables.dexterityfields import ParentField
from collective.excelexport.exportables.dexterityfields import GrandParentField
class PSTActionFieldsFactory(BaseExportableFactory):
adapts(IDexterityFTI, Interface, Interface)
portal_types = ('pstaction',)
def get_exportables(self):
portal_types = api.portal.get_tool('portal_types')
action_fti = portal_types['pstaction']
oo_fti = portal_types['operationalobjective']
os_fti = portal_types['strategicobjective']
fields = []
fields.extend([get_exportable(
field[1], self.context, self.request)
for field in get_ordered_fields(action_fti)])
fields.extend([get_exportable(
ParentField(field[1]), self.context, self.request)
for field in get_ordered_fields(oo_fti)])
fields.extend([get_exportable(
GrandParentField(field[1]), self.context, self.request)
for field in get_ordered_fields(os_fti)])
return fields
Dexterity exportables
---------------------
You have a complete set of exportables for dexterity fields.
Those are multi-adapters of field, context and request.
You can override them declaring a more specific adapter.
You can also declare a named adapter with the field name if you want a specific
rendering for one field.
Styles
------
If you don't feel good with default styles, you can register a specific one for: ::
- the export policy
- the context
- the layer
You just have to register a new IStyle adapter, in a zcml: ::
<adapter for="zope.interface.Interface
.interfaces.IThemeSpecific"
factory=".excelstyles.MyNeutralStyle"
provides="collective.excelexport.interfaces.IStyles"
/>
If you do not specify the name, the styles will be registered for all policies.
and in python: ::
class MyNeutralStyle(Styles):
content = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold off; '
'align: wrap off, vert centre, horiz left;'
'borders: top thin, bottom thin, left thin, right thin;'
'pattern: pattern solid, back_colour white, fore_colour white'
)
headers = xlwt.easyxf('font: height 200, name Arial, colour_index black, bold on; '
'align: wrap off, vert centre, horiz left; '
'borders: top thin, bottom thin, left thin, right thin; '
'pattern: pattern solid, back_colour white, fore_colour white; '
)
plone.restapi
=============
To get an export via rest api, query @collective.excelexport / @collective.excelexportcsv (with one @)
Tests
=====
This add-on is tested using Travis CI. The current status of the add-on is :
.. image:: https://secure.travis-ci.org/collective/collective.excelexport.png
:target: http://travis-ci.org/collective/collective.excelexport
.. image:: https://coveralls.io/repos/collective/collective.excelexport/badge.png?branch=master
:target: https://coveralls.io/r/collective/collective.excelexport?branch=master
Contributors
============
- Thomas Desvenain, thomas.desvenain@gmail.com
Changelog
=========
1.7 (2018-06-22)
----------------
- Added plone.restapi service.
[thomasdesvenain]
- Fixed csv export mimetype.
- Added helper method get_exportable_for_fieldname.
[gbastien]
1.6 (2018-01-05)
----------------
- Fix: no limit for number of results in eeafaceted datasource.
[cedricmessiant]
1.5 (2017-11-28)
----------------
- Upgrade bootstrap.
[sgeulette]
- Fix: render choice field with source vocabulary
[sgeulette]
1.4 (2017-05-31)
----------------
- Prevent removal of exportables with similar names when ordering them
[thomasdesvenain]
- Refactor: view exposes method that creates data buffer from sheet data.
[thomasdesvenain]
- Made correct release
[sgeulette]
1.3 (2016-11-28)
----------------
- Fix: check if value_type is empty for collection field render.
[bsuttor]
- Fix: try to get the value of a method if the field is a method and translate
DateTime results to a unicode, this fixes the export for objects with the IPublication
Behavior.
[pcdummy]
- Fix: be sure to not retrieve an attribute on an object by acquisition.
[vincentfretin]
- Feature: render_style can now return a Style object with content and headers
attribute to be able to customise the header style per exportable.
[vincentfretin]
- Feature: the passed obj to render_value is now
exportable.field.bind(obj).context to make it easier to get data from
parent or grandparent.
[vincentfretin]
- Feature: BaseFieldRenderer.render_header method returns now the translated field
title instead of the Message object.
[vincentfretin]
- Fix: Ignore reverse parameter when creating export url.
[cedricmessiant]
- Feature: Add sort exportables feature using exportables_order list.
Works with field and non-field exportables.
[cedricmessiant, ebrehault, thomasdevenain]
1.2 (2014-09-10)
----------------
- Feature: Added export under csv format.
[thomasdesvenain]
- API: Filter exportables by field name by default using excluded_exportables list.
[cedricmessiant]
- API: We can define a dexterity adapter for just one field using field name as
adapter name.
[thomasdesvenain]
- Fix: Faceted nav export link ignores results per page criterion.
[thomasdesvenain]
- Fix: Translate sheet title.
[thomasdesvenain]
- Fix: Improve text fields support.
[fngaha, thomasdesvenain]
1.1 (2014-06-19)
----------------
- Rename search policy excelexport.search to avoid conflict with 'search' view.
[thomasdesvenain]
1.0 (2014-06-02)
----------------
- Initial release.
[thomasdesvenain]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file collective.excelexport-1.7.tar.gz.
File metadata
- Download URL: collective.excelexport-1.7.tar.gz
- Upload date:
- Size: 36.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ebaf8d4297e0dff8689119b67704203252c77639d35871e749374c98f20bc63
|
|
| MD5 |
36aa10bf66a8d2447ad76343c68372f2
|
|
| BLAKE2b-256 |
e57260b185e4db09fda6a949ff19071b33b0e76fe2c54af2aa208fdd63482884
|