Skip to main content

Table generator utility for use within zope.

Project description

Introduction
============

The `ftw.table` package provides a utility for generating HTML tables of
dicts, catalog brains and other objects.

It comes with a jQuery plugin installable with a Plone Generic Setup profile,
providing features such as sorting, filter, grouping checkboxes and more.


Purpose
-------

The main purpose of this library package is to abstract the table generation
for the ``ftw.tabbedview``_ package but it can also be used in a plain
plone / zope installation.


Table generator utility
-----------------------

The table generator utility can generate HTML or JSON output.
It expects a list of data objects, accessible either in dict-like syntax by
using ``item.get(attrname)`` or in a object-like syntax by using
``item.attrname``.
It also expects a column configuration indicating which columns / attributes
are displayed in the table and how they are presented.

Examples:

>>> from ftw.table.interfaces import ITableGenerator
>>> from zope.component import getUtility
>>>
>>> generator = getUtility(ITableGenerator, name="ftw.tablegenerator")
>>>
>>> data = [
... {'id': 1,
... 'name': 'Ptolemy I Soter',
... 'dates': '305-285 BC',
... },
... {'id': 2,
... 'name': 'Ptolemy II Philadelphos',
... 'dates': '288-246 BC',
... }]
>>>
>>> columns = ['id', 'name', 'dates']
>>> print generator.generate(data, columns)
<table class="listing">
<colgroup>
<col class="col-id" />
<col class="col-name" />
<col class="col-dates" />
</colgroup>
<thead>
<tr>
<BLANKLINE>
<th id="header-id">
<span>id</span>
</th>
<BLANKLINE>
<BLANKLINE>
<th id="header-name">
<span>name</span>
</th>
<BLANKLINE>
<BLANKLINE>
<th id="header-dates">
<span>dates</span>
</th>
<BLANKLINE>
</tr>
</thead>
<tbody>
<tr>
<td>
1
</td>
<td>
Ptolemy I Soter
</td>
<td>
305-285 BC
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Ptolemy II Philadelphos
</td>
<td>
288-246 BC
</td>
</tr>
</tbody>
</table>
<BLANKLINE>

>>> columns = ['id', 'name', 'dates']
>>> print generator.generate(data, columns, output='json')
{"totalCount": 2, "rows": [{"dates": "305-285 BC", "id": 1, "name": "Ptolemy I Soter"}, {"dates": "288-246 BC", "id": 2, "name": "Ptolemy II Philadelphos"}], "metaData": {"fields": [{"type": "string", "name": "id"}, {"type": "string", "name": "name"}, {"type": "string", "name": "dates"}], "translations": {"dragDropLocked": "dragDropLocked", "sortDescText": "sortDescText", "columnsText": "columnsText", "showGroupsText": "showGroupsText", "groupByText": "groupByText", "itemsSingular": "itemsSingular", "sortAscText": "sortAscText", "selectedRowen": "selectedRowen", "itemsPlural": "itemsPlural"}, "totalProperty": "totalCount", "root": "rows", "config": {"sort": null, "dir": "ASC", "gridstate": null}, "columns": [{"header": "id", "sortable": true, "id": "id", "dataIndex": "id"}, {"header": "name", "sortable": true, "id": "name", "dataIndex": "name"}, {"header": "dates", "sortable": true, "id": "dates", "dataIndex": "dates"}]}}

**Defining columns**

The column definition can be either a list of attribute names or a dict with
a more complex configuration:

>>> advanced_columns = [
... {'column': 'the_attribute_name',
... 'column_title': 'Title to display',
... 'condition': lambda: True,
... 'sort_index': 'sortable_title',
... 'transform': lambda item, value: str(value)}
... ]

**Sorting**

The *sortable* argument adds a "sortable" css class is added to each
column header in HTML output mode.

>>> 'sortable' in generator.generate(data, columns, sortable=True)
True



Data sources and configurations
-------------------------------

For generating listing tables from a data source such as the Plone Catalog
there is an advanced abstraction layer.
It allows to create generic listing views of different sources such as the
Plone Catalog, SQL Alchemy or python dictionaries.

A table source is an adapter retrieving data for a table source configuration.
It is a generic way to get the data. For example there is a built-in catalog
source which has the Plone Catalog as source.

The table source config specifies which data the source has to load and how
the are sorted and presented.

See the interfaces definitions and the built in sources and configurations
for further details.


Links
=====

- Main github project repository: https://github.com/4teamwork/ftw.table
- Issue tracker: https://github.com/4teamwork/ftw.table/issues
- Package on pypi: http://pypi.python.org/pypi/ftw.table
- Continuous integration: https://jenkins.4teamwork.ch/search?q=ftw.table


Copyright
=========

This package is copyright by `4teamwork <http://www.4teamwork.ch/>`_.

``ftw.table`` is licensed under GNU General Public License, version 2.


.. _ftw.tabbedview: https://github.com/4teamwork/ftw.tabbedview

Changelog
=========


1.7.8 (2012-05-09)
------------------

- Adjust comment in ITableSource inteface.
[eschmutz]

- Reduce duplicate request when using with tabbedview in non-extjs mode.
[jone]


1.7.7 (2012-03-28)
------------------

- Remove registerPackage directive.
[jone]


1.7.6 (2012-03-12)
------------------

- Improve spinner integration with tabbedview, use new helper functions.
[jone]

- Fix extjs bug when switching between listing tabs and non-listing with tabbed view.
[jone]


1.7.5 (2012-03-05)
------------------

- Fixed helpers, so they works with solr flares.
[Julian Infanger]

- Get portal_url in helpers with getToolByName
[Julian Infanger]

- Icon helper should not return a image if no icon is defined for this type.
[Julian Infanger]


1.7.4 (2012-02-28)
------------------

- Fixed stray single-quote in path_checkbox and path_radiobutton helpers
[lgraf]

- Show contenttype class in linked-helper if there is no icon for this type.
[Julian Infanger]

- Add extjs reset_grid_state function.
[jone]


1.7.3 (2012-02-27)
------------------

- removed contenttype span tag for sprites.
[mathias.leimgruber]

- Adjust different helpers: Made sure the tag content, and tag titles are correctly escaped.
[phgross]


1.7.2 (2012-02-24)
------------------

- Added Tests
[mathias.leimgruber]

- Add nosort class to all Columns that aren't sortable.
[ttschanz]

- Added some French translations
[ttschanz]

- Wrap icon class around objects icon.
[Julian Infanger]

- Show html structure in table header.
[Julian Infanger]

- Add support for condition functions in dict-based column definitions.
[jone]

- Add missing features of the default ftwtable jquery plugin implementation:

- Implement selecting of checkboxes.
- Use prepared features of the jquery plugin for supporting both implementations (extjs + default) better.
- Trigger events properly.
- Various javascript cleanup, remove unused stuff.

[jone]


1.7.1 (2011-11-17)
------------------

- Fix readable_author: should also work if fullname of user is None.
[jone]


1.7 (2011-10-07)
----------------

- fixed translations for extjs-table
[eschmutz]


1.6 (2011-09-29)
----------------

- adjust all translations, so that they use now the zope.i18n translate method
[eschmutz]

- added test-buildout for plone 4.1
[eschmutz]


1.5 (2011-07-13)
----------------

- enabled resizable also for the last column
[fsprenger]

- fixed batching_enabled attribute for the CatalogTableSource
[phgross]


1.4
---

- cleaned up package, moved it to github (https://github.com/4teamwork/ftw.table)
and prepared for release on pypi
[jbaumann]


1.3
---

- removed umlauts
[fsprenger]


1.2
---

- IE8 fix for selecting rows
[fsprenger]


1.1
---

- Make date helper methods failsave, if there's no valid date return None.
[25.01.2011, mathias.leimgruber]


1.1c11
------


1.1c10
------

- fixed translations
[ttschanz]

1.1c9
-----

- Extjs: fixed updating of static contents.
[jbaumann]


1.1c8
-----

- Do not show "groupBy" column in column menu -> make it not hideable.
[jbaumann]

- Do not allow to sort by "draggable" and to group at the same - this is contradicting.
[jbaumann]

- Extjs Checkbox: Protect-Layer was too small (firefox)
[jbaumann]

- Extjs: Fix for making batching work even when grouping enabled
[jbaumann]

- Extjs: removed ftwtable-prefix for state storage, since this is used for guessing the view later.
Also fixed typo in tabbedview check.
[jbaumann]


1.1c7
-----

- Fixed bug in extjs implementation: do not expect tabbedview to be there, but use it if it is
[jbaumann]


1.1c6
-----

- Do not allow to sort descending on the "draggable" column in extjs, because it does not make sense at may break the ordering.
[jbaumann]

- Fix ordering bug, which caused that the ID of the row was missing in the extjs store
[jbaumann]

- Read sort_on attribute from grid storage
[jbaumann]


1.1c5
-----

- Implemented server-side grouping in table sources.
[jbaumann]


1.1c4
-----


1.1c3
-----

- Disabled translation of column titles in template, since it would not work in json mode too.
You need to switch from tuple column definition to dict column definition or to Column-object
definition where you can translate the column title in your own domain using Message objects.
[jbaumann]


1.1
---

- added htmlentities replacing in the linked and quick_preview helper
[phgross]


1.0a5
-----

- added quick_preview helper
[phgross]


1.0a4
-----

- changed TableGenerator to use without the standard listing template and use a specific template
[pgross]


1.0a3
-----


1.0a2
-----


1.0
---

- Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftw.table-1.7.8.tar.gz (35.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page