I have an AT content type in Plone. It has a number of fields, including a file field. When the user e开发者_JAVA技巧dits 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?
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.
Here is what I tied to the IObjectEditedEvent:
Using the default form created from subclassing ATBlob, implementing (IATBlobFile, IATFile, IFileContent)
def editObjectEvent(context, event):
status = context.REQUEST.form.get('file_delete')
if status in ("nochange", NONE):
print "Don't do anything, no change to file."
else:
print "Do something, the file has changed"
I'd like to know what other values form['file_delete']
can have. It seems useful.
精彩评论