[gen] Added wrapper.getLastEvent, allowing to perform kinds of queries into an object's history.
This commit is contained in:
parent
6206dbe59c
commit
c5930edd2d
|
@ -49,7 +49,7 @@ class Computed(Field):
|
|||
maxChars=None, colspan=1, method=None, plainText=False,
|
||||
master=None, masterValue=None, focus=False, historized=False,
|
||||
sync=True, mapping=None, label=None, sdefault='', scolspan=1,
|
||||
swidth=None, sheight=None, context={}):
|
||||
swidth=None, sheight=None, context=None):
|
||||
# The Python method used for computing the field value, or a PX.
|
||||
self.method = method
|
||||
# Does field computation produce plain text or XHTML?
|
||||
|
@ -74,7 +74,7 @@ class Computed(Field):
|
|||
obj = obj.appy()
|
||||
ctx = {'obj': obj, 'field': self,
|
||||
'_': obj.translate, 'tool': obj.tool}
|
||||
ctx.update(self.context)
|
||||
if self.context: ctx.update(self.context)
|
||||
return self.method(ctx)
|
||||
else:
|
||||
# self.method is a method that will return the field value
|
||||
|
|
|
@ -1026,6 +1026,25 @@ class AbstractWrapper(object):
|
|||
whose values are the previous field values.'''
|
||||
self.o.addDataChange(data)
|
||||
|
||||
def getLastEvent(self, transition, notBefore=''):
|
||||
'''Gets, from the object history, the last occurrence of transition
|
||||
named p_transition. p_transition can be a list of names: in this
|
||||
case, it returns the most recent occurrence of those transitions. If
|
||||
p_notBefore is given, it corresponds to a kind of start transition
|
||||
for the search: we will not search in the history preceding the last
|
||||
occurrence of this transition.'''
|
||||
history = self.history
|
||||
i = len(history)-1
|
||||
while i >= 0:
|
||||
event = history[i]
|
||||
if notBefore and (event['action'] == notBefore): return
|
||||
if isinstance(transition, basestring):
|
||||
condition = event['action'] == transition
|
||||
else:
|
||||
condition = event['action'] in transition
|
||||
if condition: return event
|
||||
i -= 1
|
||||
|
||||
def formatText(self, text, format='html'):
|
||||
'''Produces a representation of p_text into the desired p_format, which
|
||||
is 'html' by default.'''
|
||||
|
|
Loading…
Reference in a new issue