[Checkins] SVN: zc.sourcefactory/branches/0.2/ - fixed bug in the new contextual token policy

Christian Theune ct at gocept.com
Sun Jun 10 08:44:25 EDT 2007


Log message for revision 76578:
   - fixed bug in the new contextual token policy
   - bumping version to micro release
  

Changed:
  U   zc.sourcefactory/branches/0.2/CHANGES.txt
  U   zc.sourcefactory/branches/0.2/setup.py
  U   zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/README.txt
  U   zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/source.py
  U   zc.sourcefactory/branches/0.2/src/zc/sourcefactory/policies.py

-=-
Modified: zc.sourcefactory/branches/0.2/CHANGES.txt
===================================================================
--- zc.sourcefactory/branches/0.2/CHANGES.txt	2007-06-10 12:42:38 UTC (rev 76577)
+++ zc.sourcefactory/branches/0.2/CHANGES.txt	2007-06-10 12:44:25 UTC (rev 76578)
@@ -2,6 +2,12 @@
 Changes
 =======
 
+0.2.1 - 2007-07-10
+==================
+
+    - Fixed a bug in the contextual token policy that was handling the
+      resolution of values for a given token incorrectly.
+
 0.2 - 2007-07-10
 ================
 

Modified: zc.sourcefactory/branches/0.2/setup.py
===================================================================
--- zc.sourcefactory/branches/0.2/setup.py	2007-06-10 12:42:38 UTC (rev 76577)
+++ zc.sourcefactory/branches/0.2/setup.py	2007-06-10 12:44:25 UTC (rev 76578)
@@ -3,7 +3,7 @@
 
 setup(
     name="zc.sourcefactory",
-    version="0.2",
+    version="0.2.1",
     author="Zope Corporation and Contributors",
     author_email="zope3-dev at zope.org",
     url="http://svn.zope.org/zc.sourcefactory",

Modified: zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/README.txt
===================================================================
--- zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/README.txt	2007-06-10 12:42:38 UTC (rev 76577)
+++ zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/README.txt	2007-06-10 12:44:25 UTC (rev 76578)
@@ -155,6 +155,8 @@
   ...         return context.keys()
   ...     def getTitle(self, context, value):
   ...         return context[value]
+  ...     def getToken(self, context, value):
+  ...         return 'token-%s' % value
   >>> source = DemoContextualSource()(zip_to_city)
   >>> sorted(list(source))
   ['06112', '06844']
@@ -176,7 +178,14 @@
   <zc.sourcefactory.browser.source.FactoredTerm object at 0x...>
   >>> terms.getTerm('06844').title
   'Dessau'
+  >>> terms.getTerm('06844').token
+  'token-06844'
 
+And in reverse we can get the value for a given token as well::
+
+  >>> terms.getValue('token-06844')
+  '06844'
+
 Interfaces
 ==========
 

Modified: zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/source.py
===================================================================
--- zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/source.py	2007-06-10 12:42:38 UTC (rev 76577)
+++ zc.sourcefactory/branches/0.2/src/zc/sourcefactory/browser/source.py	2007-06-10 12:44:25 UTC (rev 76578)
@@ -68,7 +68,11 @@
             self.source.context, self.source, value, title, token,
             self.request)
 
+    def getValue(self, token):
+        return self.source.factory.getValue(self.source.context, self.source,
+                                            token)
 
+
 class FactoredTerm(object):
     """A title tokenized term."""
 

Modified: zc.sourcefactory/branches/0.2/src/zc/sourcefactory/policies.py
===================================================================
--- zc.sourcefactory/branches/0.2/src/zc/sourcefactory/policies.py	2007-06-10 12:42:38 UTC (rev 76577)
+++ zc.sourcefactory/branches/0.2/src/zc/sourcefactory/policies.py	2007-06-10 12:44:25 UTC (rev 76578)
@@ -111,7 +111,10 @@
     zope.interface.implements(zc.sourcefactory.interfaces.IContextualTokenPolicy)
 
     def getValue(self, context, source, token):
-        return super(BasicContextualTokenPolicy, self).getValue(source, token)
+        for value in source:
+            if source.factory.getToken(context, value) == token:
+                return value
+        raise KeyError, "No value with token '%s'" % token
 
     def getToken(self, context, value):
         return super(BasicContextualTokenPolicy, self).getToken(value)



More information about the Checkins mailing list