hi, after an object is copied & paste, the following method is called: def manage_afterClone(self, item): """ """ as it happens, both self and item refer to the same object.... which severely limits the use of the method. You probably want a reference to the original object from which this one was cloned. I googled and found a mail with the same remarks posted in 1999: http://mail.python.org/pipermail/zope-dev/1999-November/002303.html from which I copy the relevant part for your convenience: <--------------- c & p -----------------------> In lib/OFS/CopySupport.py In the function manage_pasteObjects the following line appears: ob=ob._getCopy(self) ob.manage_afterClone(ob) Passing ob as an argument doesn't make sense because the function is being called on ob, (so self is already ob) it would make more sense to to something along the lines of: original_ob=ob ob=ob._getCopy(self) ob.manage_afterClone(original_ob) </--------------- c & p -----------------------> but there's no follow- up, no reply, no fix. :( Romain Slootmaekers
File a bug in the collector. I'm sure it'll be fixed that way, specially if a patch is included in the report. On Thu, 2003-08-28 at 17:14, Romain Slootmaekers wrote:
after an object is copied & paste, the following method is called:
def manage_afterClone(self, item):
as it happens, both self and item refer to the same object.... which severely limits the use of the method. You probably want a reference to the original object from which this one was cloned. [...]
Cheers, Leo -- Ideas don't stay in some minds very long because they don't like solitary confinement.
Romain Slootmaekers wrote:
hi,
after an object is copied & paste, the following method is called:
def manage_afterClone(self, item): """ """
as it happens, both self and item refer to the same object.... which severely limits the use of the method. You probably want a reference to the original object from which this one was cloned.
I googled and found a mail with the same remarks posted in 1999: http://mail.python.org/pipermail/zope-dev/1999-November/002303.html
from which I copy the relevant part for your convenience:
<--------------- c & p -----------------------> In lib/OFS/CopySupport.py In the function manage_pasteObjects the following line appears:
ob=ob._getCopy(self) ob.manage_afterClone(ob)
Passing ob as an argument doesn't make sense because the function is being called on ob, (so self is already ob) it would make more sense to to something along the lines of: original_ob=ob ob=ob._getCopy(self) ob.manage_afterClone(original_ob)
</--------------- c & p ----------------------->
but there's no follow- up, no reply, no fix. :(
Romain Slootmaekers
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
http://collector.zope.org/Zope/1028 have fun, Romain Slootmaekers
Romain Slootmaekers wrote at 2003-8-28 22:14 +0200:
after an object is copied & paste, the following method is called:
def manage_afterClone(self, item): """ """
as it happens, both self and item refer to the same object.... which severely limits the use of the method. You probably want a reference to the original object from which this one was cloned.
I am not so sure about this. I think, in most use cases, it is sufficient to have the copied object. At least for all currently handled use cases it is apparently sufficient. What use case do you have that needs the original object? Under no circumstances are you allowed to redefine the "item" parameter above to refer to the original object (as suggested in the quoted message): "manage_clone" is often implemented recursively and while in the top call "self" and "item" are identical, this changes in recursive calls. Knowing "item" (where the recursive "manage_clone" started) is essential to differentiate actions depending on the relative position of "item" with respect to other objects: e.g. initialize workflow when "item" is below the portal but do not when it is above. Code that makes these checks will break when you pass a differnt object as "item". Dieter
Dieter Maurer wrote:
Romain Slootmaekers wrote at 2003-8-28 22:14 +0200:
after an object is copied & paste, the following method is called:
def manage_afterClone(self, item): """ """
as it happens, both self and item refer to the same object.... which severely limits the use of the method. You probably want a reference to the original object from which this one was cloned.
I am not so sure about this.
I think, in most use cases, it is sufficient to have the copied object. At least for all currently handled use cases it is apparently sufficient. What use case do you have that needs the original object?
We have a content type that has 2 types of attributes: - private attributes (private as 'not shared') - shared attributes (btw, these reside in a RDB, the object only knows a primary key) Only the original content object can modify the shared attributes the others can view them but only edit their private attributes This all works fine. We want to delete all clones automatically when an original is deleted. For this, we need an accounting scheme that notifies the original about its clones. The designated place to do this is manage_afterClone, but we lack the necessary information in that method, hence the suggested change. So the official use case would be: "clone needs to call method on original."
Under no circumstances are you allowed to redefine the "item" parameter above to refer to the original object (as suggested in the quoted message):
"manage_clone" is often implemented recursively and while in the top call "self" and "item" are identical, this changes in recursive calls.
Knowing "item" (where the recursive "manage_clone" started) is essential to differentiate actions depending on the relative position of "item" with respect to other objects:
e.g. initialize workflow when "item" is below the portal but do not when it is above.
Code that makes these checks will break when you pass a differnt object as "item".
I changed my 2.6.1 and haven't noticed any defects (yet ;)) in the plone that uses this behaviour. I'm willing to run the whole testset against my changes but this will cost me significant setup time as I'm not a (registered) zope developer. as the changes only affect 10 lines, I was wondering if someone else would 'do the honours'. :)
Dieter
Romain
Romain Slootmaekers wrote at 2003-8-30 13:29 +0200:
... So the official use case would be: "clone needs to call method on original."
I customized "_getCopyOf" for a similar requirement. But, I see, you do not have the "id" in the method.
... I changed my 2.6.1 and haven't noticed any defects (yet ;)) in the plone that uses this behaviour.
I'm willing to run the whole testset against my changes but this will cost me significant setup time as I'm not a (registered) zope developer. as the changes only affect 10 lines, I was wondering if someone else would 'do the honours'. :)
It may not break the test suite but it will break my application (which relies on the current semantics). Moreover, the current behaviour is consistent with the "manage_afterClone" companion "manage_afterAdd" (which is called, too, after copying and moving). I would suggest: In "_getCopyOf", you put the necessary information about the original in the copy (as a volatile attribute). In your "manage_afterClone", you look for this attribute and take appropriate action. Dieter
Dieter Maurer wrote:
Romain Slootmaekers wrote at 2003-8-30 13:29 +0200:
... So the official use case would be: "clone needs to call method on original."
I customized "_getCopyOf" for a similar requirement. But, I see, you do not have the "id" in the method.
... I changed my 2.6.1 and haven't noticed any defects (yet ;)) in the plone that uses this behaviour.
I'm willing to run the whole testset against my changes but this will cost me significant setup time as I'm not a (registered) zope developer. as the changes only affect 10 lines, I was wondering if someone else would 'do the honours'. :)
It may not break the test suite but it will break my application (which relies on the current semantics).
Moreover, the current behaviour is consistent with the "manage_afterClone" companion "manage_afterAdd" (which is called, too, after copying and moving).
I would suggest:
In "_getCopyOf", you put the necessary information about the original in the copy (as a volatile attribute). In your "manage_afterClone", you look for this attribute and take appropriate action.
Yuk, this is ugly (but I guess I'll have to use it..) The fact remains that my use case: "clone wants to call method on original" is not something far fetched. An alternative solution would be to change the signature of the manage_afterClone method in something like def manage_afterClone(self,item,originalItem): """ even perhaps an originalItem = None parameter although that is ugly too (semantics) """ But that would require changes all over the code base, and in 3th party products too. So this probably isn't a feasible alternative either. Anyway, If you're reluctant to change anything about the zope-2.X copy-paste behaviour, can you guys atleast add the use case to the list for zope-3? Romain Slootmaekers.
Romain Slootmaekers wrote at 2003-9-1 10:07 +0200:
... Anyway, If you're reluctant to change anything about the zope-2.X copy-paste behaviour, can you guys atleast add the use case to the list for zope-3?
I am not really involved in Zope development. Thus, I cannot help you with this issue. But, there is a Zope3 wiki and a "zope3-dev" mailing list. These seem to be good places for your use case. Dieter
participants (3)
-
Dieter Maurer -
Leonardo Rochael Almeida -
Romain Slootmaekers