Back to index

plone3  3.1.7
wftransition.py
Go to the documentation of this file.
00001 from OFS.SimpleItem import SimpleItem
00002 
00003 from zope.interface import implements, Interface
00004 from zope.component import adapts
00005 from zope.component import queryUtility
00006 from zope.formlib import form
00007 from zope import schema
00008 
00009 from plone.contentrules.rule.interfaces import IExecutable, IRuleElementData
00010 
00011 from plone.app.contentrules.browser.formhelper import AddForm, EditForm 
00012 
00013 from Products.CMFCore.interfaces import IConfigurableWorkflowTool
00014 from Products.CMFCore.interfaces import IActionSucceededEvent
00015 from Products.CMFPlone import PloneMessageFactory as _
00016 
00017 class IWorkflowTransitionCondition(Interface):
00018     """Interface for the configurable aspects of a workflow transition condition.
00019     
00020     This is also used to create add and edit forms, below.
00021     """
00022     
00023     wf_transitions = schema.Set(title=u"Workflow transition",
00024                            description=u"The workflow transitions to check for.",
00025                            required=True,
00026                            value_type=schema.Choice(vocabulary="plone.app.vocabularies.WorkflowTransitions"))
00027          
00028 class WorkflowTransitionCondition(SimpleItem):
00029     """The actual persistent implementation of the workflow transition condition element.
00030     """
00031     implements(IWorkflowTransitionCondition, IRuleElementData)
00032     
00033     wf_transitions = []
00034     element = "plone.conditions.WorkflowTransition"
00035     
00036     @property
00037     def summary(self):
00038         return _(u"Workflow transitions are: ${transitions}", mapping=dict(transitions=", ".join(self.wf_transitions)))
00039 
00040 class WorkflowTransitionConditionExecutor(object):
00041     """The executor for this condition.
00042     """
00043     implements(IExecutable)
00044     adapts(Interface, IWorkflowTransitionCondition, IActionSucceededEvent)
00045          
00046     def __init__(self, context, element, event):
00047         self.context = context
00048         self.element = element
00049         self.event = event
00050 
00051     def __call__(self):
00052         return self.event.action in self.element.wf_transitions
00053         
00054 class WorkflowTransitionAddForm(AddForm):
00055     """An add form for workflow transition conditions.
00056     """
00057     form_fields = form.FormFields(IWorkflowTransitionCondition)
00058     label = _(u"Add Workflow Transition Condition")
00059     description = _(u"A workflow transition condition can restrict rules to execute only after a certain transition.")
00060     form_name = _(u"Configure element")
00061     
00062     def create(self, data):
00063         c = WorkflowTransitionCondition()
00064         form.applyChanges(c, self.form_fields, data)
00065         return c
00066 
00067 class WorkflowTransitionEditForm(EditForm):
00068     """An edit form for portal type conditions
00069     
00070     Formlib does all the magic here.
00071     """
00072     form_fields = form.FormFields(IWorkflowTransitionCondition)
00073     label = _(u"Edit Workflow Transition Condition")
00074     description = _(u"A workflow transition condition can restrict rules to execute only after a certain transition.")
00075     form_name = _(u"Configure element")