[Checkins] SVN: z3c.table/trunk/ Implemented
GetAttrFormatterColumn. This column can be used for simple
value formatting columns.
Roger Ineichen
cvs-admin at zope.org
Fri Jun 13 09:48:20 EDT 2008
Log message for revision 87364:
Implemented GetAttrFormatterColumn. This column can be used for simple value formatting columns.
Added tests for GetAttrFormatterColumn
Changed:
U z3c.table/trunk/CHANGES.txt
U z3c.table/trunk/src/z3c/table/README.txt
U z3c.table/trunk/src/z3c/table/column.py
U z3c.table/trunk/src/z3c/table/column.txt
-=-
Modified: z3c.table/trunk/CHANGES.txt
===================================================================
--- z3c.table/trunk/CHANGES.txt 2008-06-13 10:58:17 UTC (rev 87363)
+++ z3c.table/trunk/CHANGES.txt 2008-06-13 13:48:19 UTC (rev 87364)
@@ -5,6 +5,9 @@
Version 0.5.1dev (unreleased)
-----------------------------
+- Implemented GetAttrFormatterColumn. This column can be used for simple
+ value formatting columns.
+
- Bad typo in columns.py: Renamed ``getLinkConent`` to ``getLinkContent``
- Bug: Changed return string in getLinkCSS. It was using css="" instead of
Modified: z3c.table/trunk/src/z3c/table/README.txt
===================================================================
--- z3c.table/trunk/src/z3c/table/README.txt 2008-06-13 10:58:17 UTC (rev 87363)
+++ z3c.table/trunk/src/z3c/table/README.txt 2008-06-13 13:48:19 UTC (rev 87364)
@@ -1644,6 +1644,7 @@
...
</table>
+
Miscellaneous
-------------
Modified: z3c.table/trunk/src/z3c/table/column.py
===================================================================
--- z3c.table/trunk/src/z3c/table/column.py 2008-06-13 10:58:17 UTC (rev 87363)
+++ z3c.table/trunk/src/z3c/table/column.py 2008-06-13 13:48:19 UTC (rev 87364)
@@ -64,7 +64,6 @@
return default
-
class Column(zope.location.Location):
"""Column provider."""
@@ -245,6 +244,17 @@
self.formatterCalendar)
+class GetAttrFormatterColumn(FormatterColumn, GetAttrColumn):
+ """Get attribute and formatter column."""
+
+ def renderCell(self, item):
+ formatter = self.getFormatter()
+ value = self.getValue(item)
+ if value:
+ value = formatter.format(value)
+ return value
+
+
class CreatedColumn(FormatterColumn, GetAttrColumn):
"""Created date column."""
Modified: z3c.table/trunk/src/z3c/table/column.txt
===================================================================
--- z3c.table/trunk/src/z3c/table/column.txt 2008-06-13 10:58:17 UTC (rev 87363)
+++ z3c.table/trunk/src/z3c/table/column.txt 2008-06-13 13:48:19 UTC (rev 87364)
@@ -465,7 +465,7 @@
GetAttrColumn
-------------
-The ``GetAttrColumn`` column is a mixin whihc is used in ``CreatedColumn`` and
+The ``GetAttrColumn`` column is a mixin which is used in ``CreatedColumn`` and
in ``ModifiedColumn``. Not all code get used if everything is fine. So let's
test the column itself and force some usecase:
@@ -612,6 +612,111 @@
u'missing'
+GetAttrFormatterColumn
+----------------------
+
+The ``GetAttrFormatterColumn`` column is a get attr column which is able to
+format the value. Let's use the dubline core adapter for our sample:
+
+ >>> from zope.dublincore.interfaces import IZopeDublinCore
+ >>> class GetCreatedColumn(column.GetAttrFormatterColumn):
+ ...
+ ... def getValue(self, item):
+ ... dc = IZopeDublinCore(item, None)
+ ... return dc.created
+
+ >>> class GetAttrFormatterColumnTable(table.Table):
+ ...
+ ... def setUpColumns(self):
+ ... return [
+ ... column.addColumn(self, GetCreatedColumn, u'created'),
+ ... ]
+
+Render and update the table:
+
+ >>> request = TestRequest()
+ >>> getAttrFormatterColumnTable = GetAttrFormatterColumnTable(container,
+ ... request)
+ >>> getAttrFormatterColumnTable.update()
+ >>> print getAttrFormatterColumnTable.render()
+ <table>
+ <thead>
+ <tr>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>2001 1 1 01:01:01 </td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 </td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 </td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 </td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 </td>
+ </tr>
+ </tbody>
+ </table>
+
+
+We can also change the formatter settings in such a column:
+
+ >>> class LongCreatedColumn(column.GetAttrFormatterColumn):
+ ...
+ ... formatterCategory = u'dateTime'
+ ... formatterLength = u'long'
+ ... formatterCalendar = u'gregorian'
+ ...
+ ... def getValue(self, item):
+ ... dc = IZopeDublinCore(item, None)
+ ... return dc.created
+
+ >>> class LongFormatterColumnTable(table.Table):
+ ...
+ ... def setUpColumns(self):
+ ... return [
+ ... column.addColumn(self, LongCreatedColumn, u'created'),
+ ... ]
+
+Render and update the table:
+
+ >>> request = TestRequest()
+ >>> longFormatterColumnTable = LongFormatterColumnTable(container,
+ ... request)
+ >>> longFormatterColumnTable.update()
+ >>> print longFormatterColumnTable.render()
+ <table>
+ <thead>
+ <tr>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>2001 1 1 01:01:01 +000</td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 +000</td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 +000</td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 +000</td>
+ </tr>
+ <tr>
+ <td>2001 1 1 01:01:01 +000</td>
+ </tr>
+ </tbody>
+ </table>
+
+
LinkColumn
----------
More information about the Checkins
mailing list