issue a 'modified' event on state change; track details of the state change in the change record
This commit is contained in:
parent
66c26e77cd
commit
65ece8b807
2 changed files with 19 additions and 7 deletions
|
@ -23,7 +23,9 @@ Views and actions for states management.
|
|||
from zope import component
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.event import notify
|
||||
from zope.i18n import translate
|
||||
from zope.lifecycleevent import ObjectModifiedEvent, Attributes
|
||||
|
||||
from cybertools.browser.action import Action, actions
|
||||
from cybertools.composer.schema.field import Field
|
||||
|
@ -132,8 +134,7 @@ class ChangeStateForm(ObjectForm, ChangeStateBase):
|
|||
|
||||
@Lazy
|
||||
def schema(self):
|
||||
# TODO: create schema directly, use field information specified
|
||||
# in transition
|
||||
# TODO: use field information specified in transition
|
||||
commentsField = Field('comments', _(u'label_transition_comments'),
|
||||
'textarea',
|
||||
description=_(u'desc_transition_comments'))
|
||||
|
@ -145,8 +146,11 @@ class ChangeStateForm(ObjectForm, ChangeStateBase):
|
|||
class ChangeState(EditObject, ChangeStateBase):
|
||||
|
||||
def update(self):
|
||||
print '***', self.request.form
|
||||
comments = self.request.form.get('comments') or u''
|
||||
self.stateful.doTransition(self.action)
|
||||
notify(ObjectModifiedEvent(self.view.virtualTargetObject,
|
||||
dict(transition=self.action, comments=comments)))
|
||||
#Attributes(IStateful, 'state', 'comments')))
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -70,6 +70,12 @@ class ChangeManager(BaseRecordManager):
|
|||
if relation is not None:
|
||||
data['predicate'] = util.getUidForObject(relation.predicate)
|
||||
data['second'] = util.getUidForObject(relation.second)
|
||||
event = kw.get('event')
|
||||
if event is not None:
|
||||
desc = getattr(event, 'descriptions', ())
|
||||
for item in desc:
|
||||
if isinstance(item, dict):
|
||||
data.update(item)
|
||||
if update:
|
||||
self.storage.updateTrack(last, data)
|
||||
else:
|
||||
|
@ -90,16 +96,18 @@ class ChangeRecord(Track):
|
|||
|
||||
@adapter(ILoopsObject, IObjectModifiedEvent)
|
||||
def recordModification(obj, event):
|
||||
ChangeManager(obj).recordModification()
|
||||
ChangeManager(obj).recordModification(event=event)
|
||||
|
||||
@adapter(ILoopsObject, IObjectAddedEvent)
|
||||
def recordAdding(obj, event):
|
||||
ChangeManager(obj).recordModification('add')
|
||||
ChangeManager(obj).recordModification('add', event=event)
|
||||
|
||||
@adapter(ILoopsObject, IAssignmentEvent)
|
||||
def recordAssignment(obj, event):
|
||||
ChangeManager(obj).recordModification('assign', relation=event.relation)
|
||||
ChangeManager(obj).recordModification('assign',
|
||||
event=event, relation=event.relation)
|
||||
|
||||
@adapter(ILoopsObject, IDeassignmentEvent)
|
||||
def recordDeassignment(obj, event):
|
||||
ChangeManager(obj).recordModification('deassign', relation=event.relation)
|
||||
ChangeManager(obj).recordModification('deassign',
|
||||
event=event, relation=event.relation)
|
||||
|
|
Loading…
Add table
Reference in a new issue