On 7/28/11 12:54 PM, Gilles Lenfant wrote:
Le 28 juil. 2011 à 16:15, imran.azad a écrit :
Hi,
How can I workout if an object has been 'modified' or whether it's a new
object within the IObjectModifiedEvent event? The issue is that
IObjectModifiedEvent is trigged even if an object is added. I need the code
below to execute only when an object is 'modified:
You could mark the creation in the request. I know this seems somehow overkill
but, assuming the IObjectCreatedEvent comes first...
@grok.subscribe(IPerson, IObjectCreatedEvent)
def markCreationOnly(person, event):
# Other stuffs ?
request = person.REQUEST
request.set('__created_person__', person.getPhysicalPath())
@grok.subscribe(IPerson, IObjectModifiedEvent)
def rename(person, event):
request = person.REQUEST
created = request.get('__created_person__', False)
if created and person.getPhysicalPath() == created:
# Object created and modified
return
id = person.getId()
parent = person.aq_parent
parent.manage_renameObject(id, baseNormalize(person.title))
Thanks
Another possible approach would be to check if the item has a non-None
_p_oid attribute. That should only be set if the object has been
committed to the ZODB. (But test and make sure it works for your
case...there may be other scenarios like if savepoints are used.)
----------
David Glick
Web Developer
[email protected]
206.286.1235x32
Online tools and strategies for the environmental movement.
Sign up for our newsletter: http://www.groundwire.org/email-capture
_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers