[Checkins] SVN: z3c.table/trunk/ Merge darrylcousins branche back to trunk

Roger Ineichen roger at projekt01.ch
Fri Apr 11 10:23:30 EDT 2008


Log message for revision 85254:
  Merge darrylcousins branche back to trunk
  Update buildout setup

Changed:
  U   z3c.table/trunk/buildout.cfg
  U   z3c.table/trunk/setup.py
  U   z3c.table/trunk/src/z3c/table/README.txt
  U   z3c.table/trunk/src/z3c/table/column.py
  A   z3c.table/trunk/src/z3c/table/header.py
  U   z3c.table/trunk/src/z3c/table/interfaces.py

-=-
Modified: z3c.table/trunk/buildout.cfg
===================================================================
--- z3c.table/trunk/buildout.cfg	2008-04-11 13:56:50 UTC (rev 85253)
+++ z3c.table/trunk/buildout.cfg	2008-04-11 14:23:24 UTC (rev 85254)
@@ -1,6 +1,6 @@
 [buildout]
 develop = .
-parts = test checker coverage
+parts = test checker coverage-test coverage-report
 
 
 [test]
@@ -13,6 +13,14 @@
 path = src/z3c/table
 
 
-[coverage]
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3c.table [test]
+defaults = ['--coverage', '../../coverage']
+
+
+[coverage-report]
 recipe = zc.recipe.egg
 eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')

Modified: z3c.table/trunk/setup.py
===================================================================
--- z3c.table/trunk/setup.py	2008-04-11 13:56:50 UTC (rev 85253)
+++ z3c.table/trunk/setup.py	2008-04-11 14:23:24 UTC (rev 85254)
@@ -23,7 +23,7 @@
 
 setup (
     name='z3c.table',
-    version='0.5.0',
+    version='0.5.0dev',
     author = "Stephan Richter, Roger Ineichen and the Zope Community",
     author_email = "zope3-dev at zope.org",
     description = "Modular table rendering implementation for Zope3",
@@ -55,7 +55,7 @@
             'zope.app.testing',
             'zope.publisher',
             'zope.security',
-            'zope.testbrowser',
+            'zope.testing',
             ],
         ),
     install_requires = [
@@ -63,6 +63,7 @@
         'z3c.batching',
         'zope.component',
         'zope.contentprovider',
+        'zope.dublincore',
         'zope.i18nmessageid',
         'zope.interface',
         'zope.location',
@@ -71,4 +72,4 @@
         'zope.traversing',
         ],
     zip_safe = False,
-)
\ No newline at end of file
+)

Modified: z3c.table/trunk/src/z3c/table/README.txt
===================================================================
--- z3c.table/trunk/src/z3c/table/README.txt	2008-04-11 13:56:50 UTC (rev 85253)
+++ z3c.table/trunk/src/z3c/table/README.txt	2008-04-11 14:23:24 UTC (rev 85254)
@@ -97,10 +97,8 @@
   >>> class TitleColumn(column.Column):
   ... 
   ...     weight = 10
+  ...     header = u'Title'
   ... 
-  ...     def renderHeadCell(self):
-  ...         return u'Title'
-  ... 
   ...     def renderCell(self, item):
   ...         return u'Title: %s' % item.title
 
@@ -245,7 +243,6 @@
     </tbody>
   </table>
 
-
 Setup columns
 -------------
 
@@ -722,7 +719,7 @@
   1
 
   >>> titleColumn.header
-  u''
+  u'Title'
 
   >>> titleColumn.cssClasses
   {}
@@ -792,7 +789,7 @@
 
 And add some more items to our container:
 
-  >>> container[u'sixt'] = Content('Sixt', 6)
+  >>> container[u'sixth'] = Content('Sixth', 6)
   >>> container[u'seventh'] = Content('Seventh', 7)
   >>> container[u'eighth'] = Content('Eighth', 8)
   >>> container[u'ninth'] = Content('Ninth', 9)
@@ -869,14 +866,14 @@
         <td>number: 7</td>
       </tr>
       <tr>
-        <td>Sixt item</td>
-        <td>number: 6</td>
-      </tr>
-      <tr>
         <td>Sixteenth item</td>
         <td>number: 16</td>
       </tr>
       <tr>
+        <td>Sixth item</td>
+        <td>number: 6</td>
+      </tr>
+      <tr>
         <td>Tenth item</td>
         <td>number: 10</td>
       </tr>
@@ -1029,7 +1026,7 @@
     </thead>
     <tbody>
       <tr>
-        <td>Sixt item</td>
+        <td>Sixth item</td>
         <td>number: 6</td>
       </tr>
       <tr>
@@ -1362,7 +1359,28 @@
 of items instead of a mapping. Define the same sequence of items we used before
 we added the other 1000 items: 
 
-  >>> dataSequence = sorted(container.values())[:20]
+  >>> dataSequence = []
+  >>> dataSequence.append(Content('Zero', 0))
+  >>> dataSequence.append(Content('First', 1))
+  >>> dataSequence.append(Content('Second', 2))
+  >>> dataSequence.append(Content('Third', 3))
+  >>> dataSequence.append(Content('Fourth', 4))
+  >>> dataSequence.append(Content('Fifth', 5))
+  >>> dataSequence.append(Content('Sixth', 6))
+  >>> dataSequence.append(Content('Seventh', 7))
+  >>> dataSequence.append(Content('Eighth', 8))
+  >>> dataSequence.append(Content('Ninth', 9))
+  >>> dataSequence.append(Content('Tenth', 10))
+  >>> dataSequence.append(Content('Eleventh', 11))
+  >>> dataSequence.append(Content('Twelfth', 12))
+  >>> dataSequence.append(Content('Thirteenth', 13))
+  >>> dataSequence.append(Content('Fourteenth', 14))
+  >>> dataSequence.append(Content('Fifteenth', 15))
+  >>> dataSequence.append(Content('Sixteenth', 16))
+  >>> dataSequence.append(Content('Seventeenth', 17))
+  >>> dataSequence.append(Content('Eighteenth', 18))
+  >>> dataSequence.append(Content('Nineteenth', 19))
+  >>> dataSequence.append(Content('Twentieth', 20))
 
 Now let's define a new SequenceTable:
 
@@ -1423,7 +1441,11 @@
         <td>number: 4</td>
       </tr>
       <tr>
-        <td>Sixt item</td>
+        <td>Fifth item</td>
+        <td>number: 5</td>
+      </tr>
+      <tr>
+        <td>Sixth item</td>
         <td>number: 6</td>
       </tr>
       <tr>
@@ -1566,7 +1588,62 @@
     </tbody>
   </table>
 
+Headers
+-------
 
+We can change the rendering of the header of, e.g, the Title column by
+registering a IHeaderColumn adapter. This may be useful for adding links to
+column headers for an existing table implementation.
+
+We'll use a fresh almost empty container.
+
+  >>> container = Container()
+  >>> root['container-1'] = container
+  >>> container[u'first'] = Content('First', 1)
+  >>> container[u'second'] = Content('Second', 2)
+  >>> container[u'third'] = Content('Third', 3)
+
+  >>> class myTableClass(table.Table):
+  ...     pass
+
+  >>> myTable = myTableClass(container, request)
+
+  >>> class TitleColumn(column.Column):
+  ... 
+  ...     header = u'Title'
+  ... 
+  ...     def renderCell(self, item):
+  ...         return item.title
+
+Now we can register a column adapter directly to our table class.
+
+  >>> zope.component.provideAdapter(TitleColumn,
+  ...     (None, None, myTableClass), provides=interfaces.IColumn,
+  ...      name='titleColumn')
+
+And add a registration for a column header - we'll use here the proveded generic
+sorting header implementation.
+
+  >>> from z3c.table.header import SortingColumnHeader
+  >>> zope.component.provideAdapter(SortingColumnHeader,
+  ...     (None, None, interfaces.ITable, interfaces.IColumn),
+  ...     provides=interfaces.IColumnHeader)
+
+Now we can render the table and we shall see a link in the header. Note that it
+is set to switch to descending as the the table initially will display the first
+column as ascending.
+
+  >>> myTable.update()
+  >>> print myTable.render()
+  <table>
+   <thead>
+    <tr>
+     <th><a
+      href="?table-sortOrder=descending&table-sortOn=table-titleColumn-0"
+      title="Sort">Title</a></th>
+  ...
+  </table>
+
 Miscellaneous
 -------------
 

Modified: z3c.table/trunk/src/z3c/table/column.py
===================================================================
--- z3c.table/trunk/src/z3c/table/column.py	2008-04-11 13:56:50 UTC (rev 85253)
+++ z3c.table/trunk/src/z3c/table/column.py	2008-04-11 14:23:24 UTC (rev 85254)
@@ -62,6 +62,7 @@
         return default
 
 
+
 class Column(zope.location.Location):
     """Column provider."""
 
@@ -95,6 +96,11 @@
 
     def renderHeadCell(self):
         """Header cell content."""
+        header = zope.component.queryMultiAdapter((self.context,
+            self.request, self.table, self), interfaces.IColumnHeader)
+        if header:
+            header.update()
+            return header.render()
         return self.header
 
     def renderCell(self, item):
@@ -121,7 +127,6 @@
 
 
 # predefined columns
-
 class NameColumn(Column):
     """Name column."""
 

Copied: z3c.table/trunk/src/z3c/table/header.py (from rev 85253, z3c.table/branches/darrylcousins/src/z3c/table/header.py)
===================================================================
--- z3c.table/trunk/src/z3c/table/header.py	                        (rev 0)
+++ z3c.table/trunk/src/z3c/table/header.py	2008-04-11 14:23:24 UTC (rev 85254)
@@ -0,0 +1,97 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from urllib import urlencode
+
+import zope.interface
+
+from z3c.table import interfaces
+
+
+class ColumnHeader(object):
+    """ColumnHeader renderer provider"""
+
+    zope.interface.implements(interfaces.IColumnHeader)
+
+    _request_args = []
+
+    def __init__(self, context, request, table, column):
+        self.__parent__ = context
+        self.context = context
+        self.request = request
+        self.table = table
+        self.column = column
+
+    def update(self):
+        """Override this method in subclasses if required"""
+        pass
+
+    def render(self):
+        """Override this method in subclasses"""
+        return self.column.header
+
+    def getQueryStringArgs(self):
+        """
+        Collect additional terms from the request and include in sorting column
+        headers
+
+        Perhaps this should be in separate interface only for sorting headers?
+
+        """
+        args = {}
+        for key in self._request_args:
+            value = self.request.get(key, None)
+            if value:
+                args.update({key: value})
+        return args
+
+
+class SortingColumnHeader(ColumnHeader):
+    """Sorting column header."""
+
+    def render(self):
+        table = self.table
+        prefix = table.prefix
+        colID = self.column.id
+
+        # this may return a string 'id-name-idx' if coming from request,
+        # otherwise in Table class it is intialised as a integer string
+        currentSortID = table.getSortOn()
+        try:
+            currentSortID = int(currentSortID)
+        except ValueError:
+            currentSortID = currentSortID.split('-')[2]
+
+        currentSortOrder = table.getSortOrder()
+
+        sortID = colID.split('-')[2]
+
+        sortOrder = table.sortOrder
+        if int(sortID) == int(currentSortID):
+            # ordering the same column so we want to reverse the order
+            if currentSortOrder == table.sortOrder:
+                sortOrder = table.reverseSortOrderNames[0]
+
+        args = self.getQueryStringArgs()
+        args.update({'%s-sortOn' % prefix: colID,
+                     '%s-sortOrder' % prefix: sortOrder})
+        queryString = '?%s' % (urlencode(args))
+
+        return '<a href="%s" title="Sort">%s</a>' % (queryString, 
+                                                self.column.header)
+

Modified: z3c.table/trunk/src/z3c/table/interfaces.py
===================================================================
--- z3c.table/trunk/src/z3c/table/interfaces.py	2008-04-11 13:56:50 UTC (rev 85253)
+++ z3c.table/trunk/src/z3c/table/interfaces.py	2008-04-11 14:23:24 UTC (rev 85254)
@@ -236,3 +236,21 @@
 
     def render():
         """Plain render method without keyword arguments."""
+
+class IColumnHeader(zope.interface.Interface):
+    """Multi-adapter for header rendering."""
+
+    def update():
+        """Override this method in subclasses if required"""
+
+    def render():
+        """Override this method in subclasses"""
+
+    def getQueryStringArgs():
+        """
+        Because the header will most often be used to add links for sorting the
+        columns it may also be necessary to collect other query arguments from
+        the request.
+
+        The initial use case here is to maintain a search term.
+        """



More information about the Checkins mailing list