[Checkins] SVN: z3c.table/trunk/src/z3c/table/ Added an additional IValues adapter for ITable, this allows

Roger Ineichen roger at projekt01.ch
Sat Apr 12 11:17:14 EDT 2008


Log message for revision 85274:
  Added an additional IValues adapter for ITable, this allows 
  us to manipulate values from an adapted context.
  This will become a part of our new search API

Changed:
  U   z3c.table/trunk/src/z3c/table/batch.py
  U   z3c.table/trunk/src/z3c/table/configure.zcml
  U   z3c.table/trunk/src/z3c/table/interfaces.py
  U   z3c.table/trunk/src/z3c/table/table.py
  U   z3c.table/trunk/src/z3c/table/testing.py
  U   z3c.table/trunk/src/z3c/table/tests.py
  A   z3c.table/trunk/src/z3c/table/value.py

-=-
Modified: z3c.table/trunk/src/z3c/table/batch.py
===================================================================
--- z3c.table/trunk/src/z3c/table/batch.py	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/batch.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -45,7 +45,7 @@
     Note, the additional factor 3 is the placeholder for the first, current and
     last item.
 
-    Such a batch look like:
+    Such a batch looks like:
 
     Renders the link for the first batch, spacers, the amount of links for 
     previous batches, the current batch link, spacers, the amount of links for 

Modified: z3c.table/trunk/src/z3c/table/configure.zcml
===================================================================
--- z3c.table/trunk/src/z3c/table/configure.zcml	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/configure.zcml	2008-04-12 15:17:13 UTC (rev 85274)
@@ -2,6 +2,14 @@
     xmlns="http://namespaces.zope.org/zope"
     i18n_domain="z3c">
 
+  <!-- IValues-->
+  <adapter
+      factory=".value.ValuesForContainer"
+      />
+  <adapter
+      factory=".value.ValuesForSequence"
+      />
+
   <!-- batch provider -->
   <adapter
       name="batch"

Modified: z3c.table/trunk/src/z3c/table/interfaces.py
===================================================================
--- z3c.table/trunk/src/z3c/table/interfaces.py	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/interfaces.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -25,6 +25,12 @@
 _ = zope.i18nmessageid.MessageFactory('z3c')
 
 
+class IValues(zope.interface.Interface):
+    """Table value adapter."""
+
+    values = zope.interface.Attribute('Iterable table row data sequence.')
+
+
 class ITable(IContentProvider):
     """Table provider"""
 

Modified: z3c.table/trunk/src/z3c/table/table.py
===================================================================
--- z3c.table/trunk/src/z3c/table/table.py	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/table.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -100,7 +100,9 @@
 
     @property
     def values(self):
-        return self.context.values()
+        adapter = zope.component.getMultiAdapter(
+            (self.context, self.request, self), interfaces.IValues)
+        return adapter.values
 
 # setup
 
@@ -322,7 +324,3 @@
     """
 
     zope.interface.implements(interfaces.ISequenceTable)
-
-    @property
-    def values(self):
-        return self.context

Modified: z3c.table/trunk/src/z3c/table/testing.py
===================================================================
--- z3c.table/trunk/src/z3c/table/testing.py	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/testing.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -23,6 +23,7 @@
 from zope.security import checker
 from zope.app.testing import setup
 
+import z3c.table.value
 
 class DublinCoreAdapterStub(object):
     """Dublin core adapter stub."""
@@ -45,9 +46,15 @@
     modified = datetime.datetime(2002, 2, 2, 2, 2, 2)
 
 
+def setUpAdapters():
+    zope.component.provideAdapter(z3c.table.value.ValuesForContainer)
+    zope.component.provideAdapter(z3c.table.value.ValuesForSequence)
+
+
 def setUp(test):
     test.globs['root'] = setup.placefulSetUp(True)
     zope.component.provideAdapter(DublinCoreAdapterStub)
+    setUpAdapters()
 
 
 def tearDown(test):

Modified: z3c.table/trunk/src/z3c/table/tests.py
===================================================================
--- z3c.table/trunk/src/z3c/table/tests.py	2008-04-12 13:09:38 UTC (rev 85273)
+++ z3c.table/trunk/src/z3c/table/tests.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -29,9 +29,17 @@
 from z3c.table import batch
 
 
+class FakeContainer(object):
+    def values(self):
+        pass
+
+
 # table
 class TestTable(z3c.testing.InterfaceBaseTest):
 
+    def setUp(test):
+        testing.setUpAdapters()
+
     def getTestInterface(self):
         return interfaces.ITable
 
@@ -39,9 +47,24 @@
         return table.Table
 
     def getTestPos(self):
-        return ({}, TestRequest())
+        return (FakeContainer(), TestRequest())
 
 
+class TestSequenceTable(z3c.testing.InterfaceBaseTest):
+
+    def setUp(test):
+        testing.setUpAdapters()
+
+    def getTestInterface(self):
+        return interfaces.ITable
+
+    def getTestClass(self):
+        return table.SequenceTable
+
+    def getTestPos(self):
+        return (None, TestRequest())
+
+
 # column
 class TestColumn(z3c.testing.InterfaceBaseTest):
 
@@ -134,6 +157,7 @@
             optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
             ),
         unittest.makeSuite(TestTable),
+        unittest.makeSuite(TestSequenceTable),
         unittest.makeSuite(TestColumn),
         unittest.makeSuite(TestNoneCell),
         unittest.makeSuite(TestNameColumn),

Added: z3c.table/trunk/src/z3c/table/value.py
===================================================================
--- z3c.table/trunk/src/z3c/table/value.py	                        (rev 0)
+++ z3c.table/trunk/src/z3c/table/value.py	2008-04-12 15:17:13 UTC (rev 85274)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# 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"
+
+import zope.interface
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+from z3c.table import interfaces
+
+
+class ValuesMixin(object):
+    """Mixin for different value adapters."""
+
+    zope.interface.implements(interfaces.IValues)
+
+    def __init__(self, context, request, table):
+        self.context = context
+        self.request = request
+        self.table = table
+
+
+class ValuesForContainer(ValuesMixin):
+    """Values from a simple IContainer."""
+
+    zope.component.adapts(zope.interface.Interface, IBrowserRequest,
+        interfaces.ITable)
+
+    @property
+    def values(self):
+        return self.context.values()
+
+
+class ValuesForSequence(ValuesMixin):
+    """Values from a simple IContainer."""
+
+    zope.component.adapts(zope.interface.Interface, IBrowserRequest,
+        interfaces.ISequenceTable)
+
+
+    @property
+    def values(self):
+        return self.context
\ No newline at end of file


Property changes on: z3c.table/trunk/src/z3c/table/value.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list