Search code examples
pythonplonezopearchetypes

How can I tell if a field has changed value in an AT object in plone?


I have an AT content type in Plone. It has a number of fields, including a file field. When the user edits an object of this type, how can I tell if a new file was uploaded?

For that matter, how can I tell if any of the fields have been changed?

I am currently using subscribers to hook into the IObjectEditedEvent to do some after the object changes - can I do these things here?


Solution

  • Yes, IObjectEditedEvent (a direct subclass of IObjectModifiedEvent) is emitted when an Archetypes content object is being changed.

    However, the event itself will not tell you if a new file was uploaded. It should be possible however, to obtain the request (context.REQUEST should give you the current request through acquisition, for example) and see if there is a file object there matching the field. If so, the user uploaded a new file for that field and the FileField will have been updated.