Commit badd4128 authored by Jens Vagelpohl's avatar Jens Vagelpohl

- 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)
parent fb001e06
...@@ -4,6 +4,11 @@ Products.DCWorkflow Changelog ...@@ -4,6 +4,11 @@ Products.DCWorkflow Changelog
2.2.0 (unreleased) 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 - exportimport: Support for instance creation guards and manager
bypass added. bypass added.
(https://bugs.launchpad.net/zope-cmf/+bug/308947) (https://bugs.launchpad.net/zope-cmf/+bug/308947)
......
...@@ -226,12 +226,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder): ...@@ -226,12 +226,7 @@ class DCWorkflowDefinition(WorkflowUIMixin, Folder):
var_match_keys = qdef.getVarMatchKeys() var_match_keys = qdef.getVarMatchKeys()
if var_match_keys: if var_match_keys:
# Check the catalog for items in the worklist. # Check the catalog for items in the worklist.
catalog = getToolByName(self, 'portal_catalog') searchres = qdef.search(info)
kw = {}
for k in var_match_keys:
v = qdef.getVarMatch(k)
kw[k] = [ x % info for x in v ]
searchres = catalog.searchResults(**kw)
if not searchres: if not searchres:
continue continue
if fmt_data is None: if fmt_data is None:
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
$Id$ $Id$
""" """
import re
from AccessControl.SecurityInfo import ClassSecurityInfo from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_inner from Acquisition import aq_inner
from Acquisition import aq_parent from Acquisition import aq_parent
...@@ -23,11 +25,17 @@ from App.special_dtml import DTMLFile ...@@ -23,11 +25,17 @@ from App.special_dtml import DTMLFile
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from Persistence import PersistentMapping from Persistence import PersistentMapping
from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.ContainerTab import ContainerTab 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.Guard import Guard
from Products.DCWorkflow.permissions import ManagePortal from Products.DCWorkflow.permissions import ManagePortal
from Products.DCWorkflow.utils import _dtmldir from Products.DCWorkflow.utils import _dtmldir
tales_re = re.compile(r'(\w+:)?(.*)')
class WorklistDefinition(SimpleItem): class WorklistDefinition(SimpleItem):
"""Worklist definiton""" """Worklist definiton"""
...@@ -85,7 +93,7 @@ class WorklistDefinition(SimpleItem): ...@@ -85,7 +93,7 @@ class WorklistDefinition(SimpleItem):
def getVarMatch(self, id): def getVarMatch(self, id):
if self.var_matches: if self.var_matches:
matches = self.var_matches.get(id, ()) matches = self.var_matches.get(id, ())
if not isinstance(matches, tuple): if not isinstance(matches, (tuple, Expression)):
# Old version, convert it. # Old version, convert it.
matches = (matches,) matches = (matches,)
self.var_matches[id] = matches self.var_matches[id] = matches
...@@ -95,6 +103,8 @@ class WorklistDefinition(SimpleItem): ...@@ -95,6 +103,8 @@ class WorklistDefinition(SimpleItem):
def getVarMatchText(self, id): def getVarMatchText(self, id):
values = self.getVarMatch(id) values = self.getVarMatch(id)
if isinstance(values, Expression):
return values.text
return '; '.join(values) return '; '.join(values)
_properties_form = DTMLFile('worklist_properties', _dtmldir) _properties_form = DTMLFile('worklist_properties', _dtmldir)
...@@ -122,8 +132,15 @@ class WorklistDefinition(SimpleItem): ...@@ -122,8 +132,15 @@ class WorklistDefinition(SimpleItem):
if v: if v:
if not self.var_matches: if not self.var_matches:
self.var_matches = PersistentMapping() 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: else:
if self.var_matches and self.var_matches.has_key(key): if self.var_matches and self.var_matches.has_key(key):
del self.var_matches[key] del self.var_matches[key]
...@@ -139,6 +156,36 @@ class WorklistDefinition(SimpleItem): ...@@ -139,6 +156,36 @@ class WorklistDefinition(SimpleItem):
if REQUEST is not None: if REQUEST is not None:
return self.manage_properties(REQUEST, 'Properties changed.') 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) InitializeClass(WorklistDefinition)
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<tr> <tr>
<th align="left" valign="top"> <th align="left" valign="top">
<div class="form-label"> <div class="form-label">
Cataloged variable matches (formatted) Cataloged variable matches (formatted or expression)
</div> </div>
</th> </th>
<td> <td>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment