Back to index

plone3  3.1.7
interfaces.py
Go to the documentation of this file.
00001 """
00002 """
00003 __docformat__ = 'restructuredtext'
00004 
00005 from zope.interface import Interface
00006 from zope.interface.interfaces import IInterface
00007 
00008 from zope.app.container.interfaces import IContained
00009 
00010 from zope import schema
00011 from zope.configuration import fields as configuration_fields
00012 
00013 from plone.contentrules import PloneMessageFactory as _
00014 
00015 
00016 class IRuleElementData(Interface):
00017     """Metadata for rule element data (the configuration of actions
00018     or conditions).
00019     """
00020     
00021     element = schema.ASCII(title=u"Rule element",
00022                               description=u"The name of the rule action or condition",
00023                               required=True)
00024                               
00025     summary = schema.Text(title=u"Summary",
00026                           description=u"A human-readable description of this element as it is configured",
00027                           required=True)
00028         
00029 class IRuleElement(Interface):
00030     """Base interface for rule elements (actions and conditions)
00031     
00032     A rule element is either a condition or an action that can be combined to
00033     form a rule.Rules can be constructed by the user and invoked by the
00034     IRuleExecuter
00035     """
00036     title = schema.TextLine(
00037         title = u'Title',
00038         required = True)
00039    
00040     description = schema.Text(
00041         title = u'Description',
00042         required = False)
00043 
00044     for_ = configuration_fields.GlobalInterface(
00045         title = u'Available for',
00046         description = u'The interface this component is available for',
00047         required = False)
00048     
00049     event = configuration_fields.GlobalInterface(
00050         title = u'Applicable event',
00051         description = u'The event that can trigger this element, None meaning '
00052                        'it is not event specific.',
00053         required = False)
00054         
00055     addview = schema.TextLine(
00056         title = u'Add view',
00057         description = u'The name of the add view',
00058         required = True)
00059     
00060     editview = schema.TextLine(
00061         title = u"Edit view",
00062         description = u"The name of the edit view",
00063         required = True)
00064         
00065     schema = configuration_fields.GlobalInterface(
00066         title = u'Schema',
00067         description = u'Schema interface for configuring the element',
00068         required = False)
00069         
00070     factory = configuration_fields.GlobalInterface(
00071         title = u'Factory',
00072         description = u'Callable which creates an instance of the element',
00073         required = False)
00074 
00075 class IRuleCondition(IRuleElement):
00076     """A condition of a rule
00077     
00078     Rule execution will stop if the condition fails. If the condition does not
00079     fail, the next element will be executed.
00080     """
00081 
00082 class IRuleAction(IRuleElement):
00083     """An action executed as part of a rule.
00084     
00085     Actions can perform operations, presuming preceding conditions do not fail.
00086     Once an action is finished, the next element will be executed.
00087     """
00088                              
00089 class IRuleEventType(IInterface):
00090     """Marker interface for event interfaces that can be used as the 'event'
00091     type of an IRule.
00092     """
00093 
00094 class IRuleConfiguration(Interface):
00095     """Configurable options for a rule
00096     """
00097     
00098     title = schema.TextLine(title = _(u'Title'),
00099                             description = _(u'The title of the rule'),
00100                             required = True)
00101 
00102     description = schema.Text(title = _(u'Description'),
00103                               description = _(u'A summary of the rule'),
00104                               required = False)
00105 
00106     event = schema.Choice(title = _(u'Triggering event'),
00107                           description = _(u'The event that can trigger this rule'),
00108                           required = True,
00109                           vocabulary="plone.contentrules.events")
00110 
00111     enabled = schema.Bool(title = _(u'Enabled'),
00112                           description = _(u'Whether or not the rule is currently enabled'),
00113                           default = True)
00114 
00115     stop = schema.Bool(title = _(u"Stop executing rules"),
00116                        description = _(u"Whether or not execution of further rules should stop after this rule is executed"),
00117                        default = False)
00118 
00119 class IRule(IContained, IRuleConfiguration):
00120     """A rule - a collection of rule elements.
00121     
00122     A rule is composed, normally through the user interface, of conditions and
00123     actions. Upon some event, rules that are relevant in the given context will
00124     be executed by adapting them to IExecutable and running its execute()
00125     method.
00126     
00127     When saved in a rule storage, it will be given a name.
00128     """
00129     
00130     
00131     conditions = schema.List(title = u'Conditions',
00132                              description = u'The conditions of this rule',
00133                              required = True)
00134 
00135     actions = schema.List(title = u'Actions',
00136                           description = u'The actions of this rule',
00137                           required = True)
00138                            
00139 
00140 class IExecutable(Interface):
00141     """An item which can be executed.
00142     
00143     The execution of a rule involves the execution of each one of its elements
00144     (i.e. conditions and actions). The IRule will be adapted to IExecutable in
00145     order to execute it (e.g. by iterating through the elements and executing
00146     each one), in a multi-adaptation of (context, rule, event), making it
00147     possible to customise the execution based on the type of event or context.
00148     
00149     Similarly, any object created via the 'addview' of an IRuleElement (i.e. 
00150     the configuration object for that particular instance of that particular 
00151     condition or action) will be adapted to IExecutable, in a multi-adaptation 
00152     from (context, element, event),  in order to be executed when the rule that 
00153     contains it is executed.
00154     """
00155     
00156     def __call__():
00157         """Execute the rule or rule element.
00158                 
00159         If this method returns False, execution will stop. If it returns True,
00160         execution will continue if possible.
00161         """