[Checkins] SVN: Products.DCWorkflow/trunk/Products/DCWorkflow/ - Worklists: The catalog variable match setting can now be a

Jens Vagelpohl jens at dataflake.org
Sun May 24 05:15:30 EDT 2009


Log message for revision 100326:
  - Worklists: The catalog variable match setting can now be a 
    formatted string (as before), but also a qualified TAL
    expression, meaning it has a prefix like "string:", "python:".
    (https://bugs.launchpad.net/zope-cmf/+bug/378292)
  

Changed:
  U   Products.DCWorkflow/trunk/Products/DCWorkflow/CHANGES.txt
  U   Products.DCWorkflow/trunk/Products/DCWorkflow/DCWorkflow.py
  U   Products.DCWorkflow/trunk/Products/DCWorkflow/Worklists.py
  U   Products.DCWorkflow/trunk/Products/DCWorkflow/dtml/worklist_properties.dtml

-=-
Modified: Products.DCWorkflow/trunk/Products/DCWorkflow/CHANGES.txt
===================================================================
--- Products.DCWorkflow/trunk/Products/DCWorkflow/CHANGES.txt	2009-05-24 09:10:10 UTC (rev 100325)
+++ Products.DCWorkflow/trunk/Products/DCWorkflow/CHANGES.txt	2009-05-24 09:15:29 UTC (rev 100326)
@@ -4,6 +4,11 @@
 2.2.0 (unreleased)
 ------------------
 
+- Worklists: The catalog variable match setting can now be a 
+  formatted string (as before), but also a qualified TAL 
+  expression, meaning it has a prefix like "string:", "python:".
+  (https://bugs.launchpad.net/zope-cmf/+bug/378292)
+
 - exportimport: Support for instance creation guards and manager 
   bypass added.
   (https://bugs.launchpad.net/zope-cmf/+bug/308947)

Modified: Products.DCWorkflow/trunk/Products/DCWorkflow/DCWorkflow.py
===================================================================
--- Products.DCWorkflow/trunk/Products/DCWorkflow/DCWorkflow.py	2009-05-24 09:10:10 UTC (rev 100325)
+++ Products.DCWorkflow/trunk/Products/DCWorkflow/DCWorkflow.py	2009-05-24 09:15:29 UTC (rev 100326)
@@ -226,12 +226,7 @@
                     var_match_keys = qdef.getVarMatchKeys()
                     if var_match_keys:
                         # Check the catalog for items in the worklist.
-                        catalog = getToolByName(self, 'portal_catalog')
-                        kw = {}
-                        for k in var_match_keys:
-                            v = qdef.getVarMatch(k)
-                            kw[k] = [ x % info for x in v ]
-                        searchres = catalog.searchResults(**kw)
+                        searchres = qdef.search(info)
                         if not searchres:
                             continue
                     if fmt_data is None:

Modified: Products.DCWorkflow/trunk/Products/DCWorkflow/Worklists.py
===================================================================
--- Products.DCWorkflow/trunk/Products/DCWorkflow/Worklists.py	2009-05-24 09:10:10 UTC (rev 100325)
+++ Products.DCWorkflow/trunk/Products/DCWorkflow/Worklists.py	2009-05-24 09:15:29 UTC (rev 100326)
@@ -15,6 +15,8 @@
 $Id$
 """
 
+import re
+
 from AccessControl.SecurityInfo import ClassSecurityInfo
 from Acquisition import aq_inner
 from Acquisition import aq_parent
@@ -23,12 +25,18 @@
 from OFS.SimpleItem import SimpleItem
 from Persistence import PersistentMapping
 
+from Products.CMFCore.utils import getToolByName
 from Products.DCWorkflow.ContainerTab import ContainerTab
+from Products.DCWorkflow.Expression import createExprContext
+from Products.DCWorkflow.Expression import Expression
+from Products.DCWorkflow.Expression import StateChangeInfo
 from Products.DCWorkflow.Guard import Guard
 from Products.DCWorkflow.permissions import ManagePortal
 from Products.DCWorkflow.utils import _dtmldir
 
+tales_re = re.compile(r'(\w+:)?(.*)')
 
+
 class WorklistDefinition(SimpleItem):
     """Worklist definiton"""
 
@@ -85,7 +93,7 @@
     def getVarMatch(self, id):
         if self.var_matches:
             matches = self.var_matches.get(id, ())
-            if not isinstance(matches, tuple):
+            if not isinstance(matches, (tuple, Expression)):
                 # Old version, convert it.
                 matches = (matches,)
                 self.var_matches[id] = matches
@@ -95,6 +103,8 @@
 
     def getVarMatchText(self, id):
         values = self.getVarMatch(id)
+        if isinstance(values, Expression):
+            return values.text
         return '; '.join(values)
 
     _properties_form = DTMLFile('worklist_properties', _dtmldir)
@@ -122,8 +132,15 @@
             if v:
                 if not self.var_matches:
                     self.var_matches = PersistentMapping()
-                v = [ var.strip() for var in v.split(';') ]
-                self.var_matches[key] = tuple(v)
+
+                if tales_re.match(v).group(1):
+                    # Found a TALES prefix
+                    self.var_matches[key] = Expression(v)
+                else:
+                    # Falling back to formatted string
+                    v = [ var.strip() for var in v.split(';') ]
+                    self.var_matches[key] = tuple(v)
+
             else:
                 if self.var_matches and self.var_matches.has_key(key):
                     del self.var_matches[key]
@@ -139,6 +156,36 @@
         if REQUEST is not None:
             return self.manage_properties(REQUEST, 'Properties changed.')
 
+    def search(self, info=None, **kw):
+        """ Perform the search corresponding to this worklist
+
+        Returns sequence of ZCatalog brains
+        - info is a mapping for resolving formatted string variable references
+        - additional keyword/value pairs may be used to restrict the query
+        """
+        if not self.var_matches:
+            return
+
+        if info is None:
+            info = {}
+
+        catalog = getToolByName(self, 'portal_catalog')
+        criteria = {}
+
+        for key, values in self.var_matches.items():
+            if isinstance(values, Expression):
+                wf = self.getWorkflow()
+                portal = wf._getPortalRoot()
+                context = createExprContext(StateChangeInfo(portal, wf))
+                criteria[key] = values(context)
+            else:
+                criteria[key] = [x % info for x in values]
+
+        criteria.update(kw)
+
+        return catalog.searchResults(**criteria)
+
+
 InitializeClass(WorklistDefinition)
 
 

Modified: Products.DCWorkflow/trunk/Products/DCWorkflow/dtml/worklist_properties.dtml
===================================================================
--- Products.DCWorkflow/trunk/Products/DCWorkflow/dtml/worklist_properties.dtml	2009-05-24 09:10:10 UTC (rev 100325)
+++ Products.DCWorkflow/trunk/Products/DCWorkflow/dtml/worklist_properties.dtml	2009-05-24 09:15:29 UTC (rev 100326)
@@ -19,7 +19,7 @@
 <tr>
 <th align="left" valign="top">
   <div class="form-label">
-  Cataloged variable matches (formatted)
+  Cataloged variable matches (formatted or expression)
   </div>
 </th>
 <td>



More information about the Checkins mailing list