allow for more than one 'doBefore' function in a transition
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@4202 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
c7060245e1
commit
bf8a85453c
1 changed files with 6 additions and 5 deletions
|
@ -53,6 +53,7 @@ class Action(object):
|
||||||
allowed = True
|
allowed = True
|
||||||
permission = None
|
permission = None
|
||||||
roles = []
|
roles = []
|
||||||
|
doBefore = []
|
||||||
|
|
||||||
def __init__(self, name, title=None, **kw):
|
def __init__(self, name, title=None, **kw):
|
||||||
self.name = self.__name__ = name
|
self.name = self.__name__ = name
|
||||||
|
@ -60,10 +61,6 @@ class Action(object):
|
||||||
for k, v in kw.items():
|
for k, v in kw.items():
|
||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def doBefore(context):
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class Transition(Action):
|
class Transition(Action):
|
||||||
|
|
||||||
|
@ -106,6 +103,10 @@ class StatesDefinition(object):
|
||||||
if trans not in self.getAvailableTransitionsFor(obj):
|
if trans not in self.getAvailableTransitionsFor(obj):
|
||||||
raise ValueError("Transition '%s' is not reachable from state '%s'."
|
raise ValueError("Transition '%s' is not reachable from state '%s'."
|
||||||
% (transition, obj.getState()))
|
% (transition, obj.getState()))
|
||||||
|
if isinstance(trans.doBefore, (list, tuple)):
|
||||||
|
for fct in trans.doBefore:
|
||||||
|
fct(obj)
|
||||||
|
else:
|
||||||
trans.doBefore(obj)
|
trans.doBefore(obj)
|
||||||
obj.state = trans.targetState
|
obj.state = trans.targetState
|
||||||
obj.getStateObject().setSecurity(obj)
|
obj.getStateObject().setSecurity(obj)
|
||||||
|
|
Loading…
Add table
Reference in a new issue