Darryl Cousins wrote:
Following a post on grok-dev I learnt about additional arguments to


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:


Sadly, zope.formlib doesn't send this info along either, therefore setting a bad example. I filed https://bugs.launchpad.net/zope3/+bug/98483 a while ago, just never got around to fix it... Thanks for reminding.

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:
        # 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]:
            # 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():
                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

http://worldcookery.com -- Professional Zope documentation and training
Zope3-users mailing list

Reply via email to