Back to index

plone3  3.1.7
executor.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import adapts, getMultiAdapter
00003 
00004 from plone.contentrules.engine.interfaces import IRuleExecutor
00005 from plone.contentrules.engine.interfaces import IRuleAssignable
00006 from plone.contentrules.engine.interfaces import IRuleAssignmentManager
00007 
00008 from plone.contentrules.engine.interfaces import StopRule
00009 
00010 from plone.contentrules.rule.interfaces import IExecutable
00011 
00012 class RuleExecutor(object):
00013     """An object that can execute rules in its context.
00014     """
00015     
00016     implements(IRuleExecutor)
00017     adapts(IRuleAssignable)
00018     
00019     def __init__(self, context):
00020         self.context = context
00021     
00022     def __call__(self, event, bubbled=False, rule_filter=None):
00023         assignments = IRuleAssignmentManager(self.context)
00024         for rule in assignments.getRules(event, bubbled=bubbled):
00025             if rule_filter is None or rule_filter(self.context, rule, event) == True:
00026                 executable = getMultiAdapter((self.context, rule, event), IExecutable)
00027                 executable()
00028                 if rule.stop:
00029                     raise StopRule(rule)