[Zope3-Users] z3c.form, applyChanges, IModifiedEvent
Darryl Cousins
darryl at darrylcousins.net.nz
Sun Aug 12 17:31:28 EDT 2007
Hi,
Following a post on grok-dev I learnt about additional arguments to
ModifiedEvent.
http://mail.zope.org/pipermail/grok-dev/2007-August/001807.html
By changing z3c.form.form.applyChanges to return a dictionary of
interfaces and names of the attributes changed (instead of the current
bool value) then I can easily create the correct additional attributes
within the applyChanges method of EditForm:
def applyChanges(form, content, data):
changes = {}
for name, field in form.fields.items():
# If the field is not in the data, then go on to the next one
if name not in data:
continue
# Get the datamanager and get the original value
dm = zope.component.getMultiAdapter(
(content, field.field), IDataManager)
oldValue = dm.get()
# Only update the data, if it is different
if dm.get() != data[name]:
dm.set(data[name])
# get the interface and collect changed attribute names
changes.setdefault(dm.field.interface, []).append(name)
return changes
class EditForm(Form):
....
def applyChanges(self, data):
content = self.getContent()
changes = applyChanges(self, content, data)
if changes: # testing a dict as a bool is prone to error???
descriptions = []
for interface, names in changes.items():
descriptions.append(zope.lifecycleevent.Attributes(interface,
*names))
zope.event.notify(
zope.lifecycleevent.ObjectModifiedEvent(content, *descriptions))
return changes
Hopefully pypi will be back up again later today so I can do a fresh
build of z3c.form and run the tests with my changes as set out above.
Best regards,
Darryl Cousins
More information about the Zope3-users
mailing list