Back to index

plone3  3.1.7
rule.py
Go to the documentation of this file.
00001 from persistent import Persistent
00002 from persistent.list import PersistentList
00003 
00004 from zope.interface import implements, Interface
00005 from zope.component import adapts, getMultiAdapter
00006 
00007 from plone.contentrules.rule.interfaces import IRule
00008 from plone.contentrules.rule.interfaces import IExecutable
00009 
00010 class Rule(Persistent):
00011     """A rule.
00012     """
00013 
00014     implements(IRule)
00015     
00016     title = u''
00017     description = u''
00018     event = None
00019     enabled = True
00020     stop = False
00021     
00022     __name__ = None
00023     __parent__ = None
00024     
00025     def __init__(self):
00026         self.conditions = PersistentList()
00027         self.actions = PersistentList()
00028 
00029 class RuleExecutable(object):
00030     """An adapter capable of executing a rule
00031     """
00032     
00033     implements(IExecutable)
00034     adapts(Interface, IRule, Interface)
00035     
00036     def __init__(self, context, rule, event):
00037         self.context = context
00038         self.rule = rule
00039         self.event = event
00040     
00041     def __call__(self):
00042         for condition in self.rule.conditions:
00043             executable = getMultiAdapter((self.context, condition, self.event), IExecutable)
00044             if not executable():
00045                 return False
00046         for action in self.rule.actions:
00047             executable = getMultiAdapter((self.context, action, self.event), IExecutable)
00048             if not executable():
00049                 return False
00050         return True