Back to index

plone3  3.1.7
Worklists.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Worklists in a web-configurable workflow.
00014 
00015 $Id: Worklists.py 36911 2005-04-07 16:38:47Z yuppie $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Acquisition import aq_inner
00020 from Acquisition import aq_parent
00021 from Globals import DTMLFile
00022 from Globals import InitializeClass
00023 from Globals import PersistentMapping
00024 from OFS.SimpleItem import SimpleItem
00025 
00026 from ContainerTab import ContainerTab
00027 from Guard import Guard
00028 from permissions import ManagePortal
00029 from utils import _dtmldir
00030 
00031 
00032 class WorklistDefinition(SimpleItem):
00033     """Worklist definiton"""
00034 
00035     meta_type = 'Worklist'
00036 
00037     security = ClassSecurityInfo()
00038     security.declareObjectProtected(ManagePortal)
00039 
00040     description = ''
00041     var_matches = None  # Compared with catalog when set.
00042     actbox_name = ''
00043     actbox_url = ''
00044     actbox_category = 'global'
00045     guard = None
00046 
00047     manage_options = (
00048         {'label': 'Properties', 'action': 'manage_properties'},
00049         )
00050 
00051     def __init__(self, id):
00052         self.id = id
00053 
00054     def getGuard(self):
00055         if self.guard is not None:
00056             return self.guard
00057         else:
00058             return Guard().__of__(self)  # Create a temporary guard.
00059 
00060     def getGuardSummary(self):
00061         res = None
00062         if self.guard is not None:
00063             res = self.guard.getSummary()
00064         return res
00065 
00066     def getWorkflow(self):
00067         return aq_parent(aq_inner(aq_parent(aq_inner(self))))
00068 
00069     def getAvailableCatalogVars(self):
00070         res = []
00071         res.append(self.getWorkflow().state_var)
00072         for id, vdef in self.getWorkflow().variables.items():
00073             if vdef.for_catalog:
00074                 res.append(id)
00075         res.sort()
00076         return res
00077 
00078     def getVarMatchKeys(self):
00079         if self.var_matches:
00080             return self.var_matches.keys()
00081         else:
00082             return []
00083 
00084     def getVarMatch(self, id):
00085         if self.var_matches:
00086             matches = self.var_matches.get(id, ())
00087             if not isinstance(matches, tuple):
00088                 # Old version, convert it.
00089                 matches = (matches,)
00090                 self.var_matches[id] = matches
00091             return matches
00092         else:
00093             return ()
00094 
00095     def getVarMatchText(self, id):
00096         values = self.getVarMatch(id)
00097         return '; '.join(values)
00098 
00099     _properties_form = DTMLFile('worklist_properties', _dtmldir)
00100 
00101     def manage_properties(self, REQUEST, manage_tabs_message=None):
00102         '''
00103         '''
00104         return self._properties_form(REQUEST,
00105                                      management_view='Properties',
00106                                      manage_tabs_message=manage_tabs_message,
00107                                      )
00108 
00109     def setProperties(self, description,
00110                       actbox_name='', actbox_url='', actbox_category='global',
00111                       props=None, REQUEST=None):
00112         '''
00113         '''
00114         if props is None:
00115             props = REQUEST
00116         self.description = str(description)
00117         for key in self.getAvailableCatalogVars():
00118             # Populate var_matches.
00119             fieldname = 'var_match_%s' % key
00120             v = props.get(fieldname, '')
00121             if v:
00122                 if not self.var_matches:
00123                     self.var_matches = PersistentMapping()
00124                 v = [ var.strip() for var in v.split(';') ]
00125                 self.var_matches[key] = tuple(v)
00126             else:
00127                 if self.var_matches and self.var_matches.has_key(key):
00128                     del self.var_matches[key]
00129         self.actbox_name = str(actbox_name)
00130         self.actbox_url = str(actbox_url)
00131         self.actbox_category = str(actbox_category)
00132         g = Guard()
00133         if g.changeFromProperties(props or REQUEST):
00134             self.guard = g
00135         else:
00136             self.guard = None
00137         if REQUEST is not None:
00138             return self.manage_properties(REQUEST, 'Properties changed.')
00139 
00140 InitializeClass(WorklistDefinition)
00141 
00142 
00143 class Worklists(ContainerTab):
00144     """A container for worklist definitions"""
00145 
00146     meta_type = 'Worklists'
00147 
00148     security = ClassSecurityInfo()
00149     security.declareObjectProtected(ManagePortal)
00150 
00151     all_meta_types = ({'name':WorklistDefinition.meta_type,
00152                        'action':'addWorklist',
00153                        },)
00154 
00155     _manage_worklists = DTMLFile('worklists', _dtmldir)
00156 
00157     def manage_main(self, REQUEST, manage_tabs_message=None):
00158         '''
00159         '''
00160         return self._manage_worklists(
00161             REQUEST,
00162             management_view='Worklists',
00163             manage_tabs_message=manage_tabs_message,
00164             )
00165 
00166     def addWorklist(self, id, REQUEST=None):
00167         '''
00168         '''
00169         qdef = WorklistDefinition(id)
00170         self._setObject(id, qdef)
00171         if REQUEST is not None:
00172             return self.manage_main(REQUEST, 'Worklist added.')
00173 
00174     def deleteWorklists(self, ids, REQUEST=None):
00175         '''
00176         '''
00177         for id in ids:
00178             self._delObject(id)
00179         if REQUEST is not None:
00180             return self.manage_main(REQUEST, 'Worklist(s) removed.')
00181 
00182 InitializeClass(Worklists)