Back to index

plone3  3.1.7
Variables.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 """ Variables in a web-configurable workflow.
00014 
00015 $Id: Variables.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 OFS.SimpleItem import SimpleItem
00024 
00025 from ContainerTab import ContainerTab
00026 from Expression import Expression
00027 from Guard import Guard
00028 from permissions import ManagePortal
00029 from utils import _dtmldir
00030 
00031 
00032 class VariableDefinition(SimpleItem):
00033     """Variable definition"""
00034 
00035     meta_type = 'Workflow Variable'
00036 
00037     security = ClassSecurityInfo()
00038     security.declareObjectProtected(ManagePortal)
00039 
00040     description = ''
00041     for_catalog = 1
00042     for_status = 1
00043     default_value = ''
00044     default_expr = None  # Overrides default_value if set
00045     info_guard = None
00046     update_always = 1
00047 
00048     manage_options = (
00049         {'label': 'Properties', 'action': 'manage_properties'},
00050         )
00051 
00052     def __init__(self, id):
00053         self.id = id
00054 
00055     def getDefaultExprText(self):
00056         if not self.default_expr:
00057             return ''
00058         else:
00059             return self.default_expr.text
00060 
00061     def getInfoGuard(self):
00062         if self.info_guard is not None:
00063             return self.info_guard
00064         else:
00065             return Guard().__of__(self)  # Create a temporary guard.
00066 
00067     def getInfoGuardSummary(self):
00068         res = None
00069         if self.info_guard is not None:
00070             res = self.info_guard.getSummary()
00071         return res
00072 
00073     _properties_form = DTMLFile('variable_properties', _dtmldir)
00074 
00075     def manage_properties(self, REQUEST, manage_tabs_message=None):
00076         '''
00077         '''
00078         return self._properties_form(REQUEST,
00079                                      management_view='Properties',
00080                                      manage_tabs_message=manage_tabs_message,
00081                                      )
00082 
00083     def setProperties(self, description,
00084                       default_value='', default_expr='',
00085                       for_catalog=0, for_status=0,
00086                       update_always=0,
00087                       props=None, REQUEST=None):
00088         '''
00089         '''
00090         self.description = str(description)
00091         self.default_value = str(default_value)
00092         if default_expr:
00093             self.default_expr = Expression(default_expr)
00094         else:
00095             self.default_expr = None
00096 
00097         g = Guard()
00098         if g.changeFromProperties(props or REQUEST):
00099             self.info_guard = g
00100         else:
00101             self.info_guard = None
00102         self.for_catalog = bool(for_catalog)
00103         self.for_status = bool(for_status)
00104         self.update_always = bool(update_always)
00105         if REQUEST is not None:
00106             return self.manage_properties(REQUEST, 'Properties changed.')
00107 
00108 InitializeClass(VariableDefinition)
00109 
00110 
00111 class Variables(ContainerTab):
00112     """A container for variable definitions"""
00113 
00114     meta_type = 'Workflow Variables'
00115 
00116     all_meta_types = ({'name':VariableDefinition.meta_type,
00117                        'action':'addVariable',
00118                        },)
00119 
00120     _manage_variables = DTMLFile('variables', _dtmldir)
00121 
00122     def manage_main(self, REQUEST, manage_tabs_message=None):
00123         '''
00124         '''
00125         return self._manage_variables(
00126             REQUEST,
00127             management_view='Variables',
00128             manage_tabs_message=manage_tabs_message,
00129             )
00130 
00131     def addVariable(self, id, REQUEST=None):
00132         '''
00133         '''
00134         vdef = VariableDefinition(id)
00135         self._setObject(id, vdef)
00136         if REQUEST is not None:
00137             return self.manage_main(REQUEST, 'Variable added.')
00138 
00139     def deleteVariables(self, ids, REQUEST=None):
00140         '''
00141         '''
00142         for id in ids:
00143             self._delObject(id)
00144         if REQUEST is not None:
00145             return self.manage_main(REQUEST, 'Variable(s) removed.')
00146 
00147     def _checkId(self, id, allow_dup=0):
00148         wf_def = aq_parent(aq_inner(self))
00149         if id == wf_def.state_var:
00150             raise 'Bad Request', '"%s" is used for keeping state.' % id
00151         return ContainerTab._checkId(self, id, allow_dup)
00152 
00153     def getStateVar(self):
00154         wf_def = aq_parent(aq_inner(self))
00155         return wf_def.state_var
00156 
00157     def setStateVar(self, id, REQUEST=None):
00158         '''
00159         '''
00160         wf_def = aq_parent(aq_inner(self))
00161         if id != wf_def.state_var:
00162             self._checkId(id)
00163             wf_def.state_var = str(id)
00164         if REQUEST is not None:
00165             return self.manage_main(REQUEST, 'Set state variable.')
00166 
00167 InitializeClass(Variables)