[Product-Developers] Re: Intercepting the copy event to generate a custom id
Arno Blumer
arnoblumer at gmail.com
Sat Jun 7 08:41:29 UTC 2008
Thanks for the extensive reply!
I have since used the following test, since it seems that a newly created
object does not have the
_at_creation_flag attribute, whereas a copied object does have it:
if hasattr(object, '_at_creation_flag'):
ce_id = object.generateUniqueId('CostEstimate')
object.edit(id=ce_id, title=ce_id)
With the new information you've given me, I'll rather check the clipboard.
On Fri, Jun 6, 2008 at 9:30 PM, Maurits van Rees <m.van.rees at zestsoftware.nl>
wrote:
> Arno Blumer, on 2008-06-06:
> > Yes, I'm going to use that event now.
> > However, is there a better way of testing whether an object has been
> copied,
> > or whether there
> > is something on the clipboard?
> > At the moment I use:
> > if event.newName.startswith('copy'),
> > and this is of course only the case when the object is copied to
> somewhere
> > in the same folder.
>
> You can call context.cb_dataValid() to see if whatever is on the
> clipboard is valid data for copying.
>
> You can call context.cb_dataItems() to get the actual items that are
> referenced on the clipboard. You can walk through those items and see
> if one of them matches the object that the ObjectAddedEvent is fired
> for.
>
> As an example, here is some code I wrote for a client at Zest
> Software. It is a variation on object_paste.cpy. In this case it
> pastes objects and sets the old object as a related item on the new
> object.
>
> results = context.manage_pasteObjects(request['__cp'])
> try:
> originals = context.cb_dataItems()
> except AttributeError:
> # This happens when doing a cut/paste.
> pass
> else:
> # Set related items on the copy.
> for result in results:
> new = context[result['new_id']]
> old = [o for o in originals if o.id == result['id']][0]
> new.setRelatedItems([old])
> transaction_note('Pasted content to %s' %
> (context.absolute_url()))
>
> > I thought of testing with event.oldParent, but this always seems to
> > be None, whether the object is copied or newly created.
>
> This file contains some comments by me about when old and new parent
> are None. It is for the more general ObjectMovedEvent, of which
> ObjectAddedEvent is a subset, but most of the triggered events I
> mention are in fact ObjectAddedEvents.
>
>
> http://dev.plone.org/collective/browser/xm.booking/trunk/xm/booking/timing/events.py
>
> --
> Maurits van Rees | http://maurits.vanrees.org/
> Work | http://zestsoftware.nl/
> "This is your day, don't let them take it away." [Barlow Girl]
>
>
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> http://lists.plone.org/mailman/listinfo/product-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20080607/077ba3f5/attachment-0002.html>
More information about the Product-Developers
mailing list