문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top