[Product-Developers] IObjectModifiedEvent, object modified or added?

Imran Azad imran.azad at bradfordhospitals.nhs.uk
Thu Jul 28 20:30:06 UTC 2011


Thanks David, much appreciated. 
-----Original Message-----
From: "David Glick-3 [via Plone]" <ml-node+6631229-1978482888-347795 at n2.nabble.com>
To: Imran Azad <Imran.Azad at bradfordhospitals.nhs.uk>

Sent: 28/07/2011 21:23:20
Subject: Re: IObjectModifiedEvent, object modified or added?



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
 davidglick at groundwire.org
 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
Product-Developers at lists.plone.org
https://lists.plone.org/mailman/listinfo/plone-product-developers


_______________________________________________
If you reply to this email, your message will be added to the discussion below:
http://plone.293351.n2.nabble.com/IObjectModifiedEvent-object-modified-or-added-tp6630019p6631229.html

To unsubscribe from IObjectModifiedEvent, object modified or added?, visit http://plone.293351.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6630019&code=aW1yYW4uYXphZEBicmFkZm9yZGhvc3BpdGFscy5uaHMudWt8NjYzMDAxOXw1MzM4MDY1MjU=
Your Hospital needs YOU! We need you to register as a Public, Patient or Staff member and help shape the future of your healthcare. Call 0800 280 2581 to register by phone or you can email  bradfordhospitals at capitaregistrars.com  and ask to be registered as a new member.  For more information about our hospitals and Foundation Trust Membership please visit www.bradfordhospitals.nhs.uk
This message is confidential. It may also contain privileged information. The contents of this e-mail and any attachments are intended for the named addressee only. Unless you are the named addressee or authorised to receive the e-mail of the named addressee you may not disclose, use or copy the contents of the e-mail. If you are not the person for whom the message was intended, please notify the sender immediately at Bradford Teaching Hospitals NHS Foundation Trust and delete the material from your computer. You must not use the message for any other purpose, nor disclose its contents to any person other than the intended recipient. Bradford Teaching Hospitals NHS Foundation Trust does not accept responsibility for this message and any views or opinions contained in this e-mail are solely those of the author unless expressly stated otherwise.



--
View this message in context: http://plone.293351.n2.nabble.com/IObjectModifiedEvent-object-modified-or-added-tp6630019p6631255.html
Sent from the Product Developers mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20110728/b6303393/attachment.html>


More information about the Product-Developers mailing list