[gen] Added wrapper.getLastEvent, allowing to perform kinds of queries into an object's history.

This commit is contained in:
Gaetan Delannay 2013-09-20 23:15:54 +02:00
parent 6206dbe59c
commit c5930edd2d
2 changed files with 21 additions and 2 deletions

View file

@ -49,7 +49,7 @@ class Computed(Field):
maxChars=None, colspan=1, method=None, plainText=False, maxChars=None, colspan=1, method=None, plainText=False,
master=None, masterValue=None, focus=False, historized=False, master=None, masterValue=None, focus=False, historized=False,
sync=True, mapping=None, label=None, sdefault='', scolspan=1, 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. # The Python method used for computing the field value, or a PX.
self.method = method self.method = method
# Does field computation produce plain text or XHTML? # Does field computation produce plain text or XHTML?
@ -74,7 +74,7 @@ class Computed(Field):
obj = obj.appy() obj = obj.appy()
ctx = {'obj': obj, 'field': self, ctx = {'obj': obj, 'field': self,
'_': obj.translate, 'tool': obj.tool} '_': obj.translate, 'tool': obj.tool}
ctx.update(self.context) if self.context: ctx.update(self.context)
return self.method(ctx) return self.method(ctx)
else: else:
# self.method is a method that will return the field value # self.method is a method that will return the field value

View file

@ -1026,6 +1026,25 @@ class AbstractWrapper(object):
whose values are the previous field values.''' whose values are the previous field values.'''
self.o.addDataChange(data) 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'): def formatText(self, text, format='html'):
'''Produces a representation of p_text into the desired p_format, which '''Produces a representation of p_text into the desired p_format, which
is 'html' by default.''' is 'html' by default.'''