Shallow copies/links/references
Hi: OK everyone, I've managed to get object links to work. As discussed previously by others (re: object references) and asked by myself: I had the need to be able to refer to objects from different points of the folder hierarchy without duplicating those objects. Yes I know that can be done *programatically*. That is not the idea. The idea is to have a folder with differente widgets/components and to be able to copy and paste references to those widgets throughout the folder hierarchy. Of course that the usual copy/paste is not OK, since that *duplicates* the objects and as such further changes to the original object wont be reflected in the copies. With something like this + Ordered Folders you are able to have an index_html that just renders the objects within a folder and you can then drop objects/widgets into the folder to produce a page. What I did: - edited CopySupport.py - copied the manage_pasteObjects method to a manage_pasteMonikers method - commented the #ob=ob._getCopy(self) line (the duplicate object part) - added a "Paste Ref" button to the lib/python/OFS/dtml/main.dtml file that calls the pasteMonikers method """ <input class="form-element" type="submit" name="manage_pasteMonikers:method" value="Paste Ref." /> """ It works. It does what I want/need. When you change a reference, the original also changes. When you change the original, the references change. You can delete either the reference or the original and all is OK. Issues/TODO - find a way to distinguish references from the original (tried to change the meta_type at paste time but no luck). At least the meta_type/icon should change to provide a visual cue. - provide tool(s) to find impact of changing a reference. Provide a link from a reference object to the original. Provide a link from an object to its several references. Comments and experiences are welcome. C U! -- Mario Valente
On 07 Aug 2001 19:04:42 +0100, Mario Valente wrote:
OK everyone, I've managed to get object links to work.
As discussed previously by others (re: object references) and asked by myself: I had the need to be able to refer to objects from different points of the folder hierarchy without duplicating those objects.
The idea is to have a folder with differente widgets/components and to be able to copy and paste references to those widgets throughout the folder hierarchy. Of course that the usual copy/paste is not OK, since that *duplicates* the objects and as such further changes to the original object wont be reflected in the copies.
[snip details]
It works. It does what I want/need. When you change a reference, the original also changes. When you change the original, the references change. You can delete either the reference or the original and all is OK.
This looks useful, but I have some questions: - Acquisition works according to a 'containment before context' rule. The object that has been 'cloned' here arguably now has two containments. Which one gets used? - If I set a proxy role on the cloned object, does it get the same proxy role in it's original container? - What does PARENTS evaluate to? - If the clone is in a location where it wouldn't be able to acquire something, but the original is, can the clone still acquire that something? Thanks, Michael Bernstein.
Hi: Regarding my previous proposal.....
I would like to propose my "Paste Reference"/symlink hack for inclusion into Zope 2.6
And referring to my previous msg..... At 19:04 07-08-2001 +0100, Mario Valente wrote:
As discussed previously by others (re: object references) and asked by myself: I had the need to be able to refer to objects from different points of the folder hierarchy without duplicating those objects.
- edited CopySupport.py - copied the manage_pasteObjects method to a manage_pasteMonikers method - commented the #ob=ob._getCopy(self) line (the duplicate object part) - added a "Paste Ref" button to the lib/python/OFS/dtml/main.dtml file that calls the pasteMonikers method
""" <input class="form-element" type="submit" name="manage_pasteMonikers:method" value="Paste Ref." /> """
Issues/TODO
- find a way to distinguish references from the original (tried to change the meta_type at paste time but no luck). At least the meta_type/icon should change to provide a visual cue. - provide tool(s) to find impact of changing a reference. Provide a link from a reference object to the original. Provide a link from an object to its several references.
I have now solved the issues/TODO. I now have implemented a way to distinguish references from the original. Links have a name like "copy_of_XXXX" but instead its "shortcut_to_XXX" and they also have a different metatype and a different icon. There's also crude management screens to get to the original object. Here's the *major* hack :-) (its such a kludge that even I am shocked :-) But it serves to demonstrate the purpose. Like previously described I edited CopySupport.py and created a new method called pasteMonikers. This method is accessed by the interface button referred above. The coding difference is that this method now creates a *new* object (instead of copying the old one, which is the semantics of usual Copy/Paste, and instead of using the original object, which is the semantics of the PasteReference I created and described before). This is the relevant piece of code: #ob=ob._getCopy(self) id=self._get_linkid(ob.getId()) ob = SimpleItem.ItemShortcut(ob) ob._setId(id) self._setObject(id, ob) ob = self._getOb(id) ob.manage_afterClone(ob) As you can see a new id is created for the new object (method _get_linkid is identical to method get_id but returns ids with the format "shortcut_to_%s") and a new object of class ItemShortcut is created and pasted into the current folder. The ItemShortcut class was created at the SimpleItem.py file and its basically a Proxy pattern. This is the relevant code, added at the end of SimpleItem.py: class ItemShortcut(SimpleItem): """Proxying class for shortcut implementation """ meta_type = "Shortcut" icon ='shortcut.gif' manage_options= SimpleItem.manage_options + ( {'label':'View', 'action':'index_html', 'help':''}, ) manage_options= SimpleItem.manage_options + ( {'label':'Properties', 'action':'manage_properties', 'help':''}, ) #__ac_permissions__=(('View', ()),) __ac_permissions__=(('View', ('__call__', '')),) def __init__(self, obj=None): self.__obj__ = obj def __repr__(self): return "Proxy for "+`self.__obj__` def index_html(self): """Proxying class for shortcut implementation """ return self.__obj__.__call__() def manage_properties(self): """Proxying class for shortcut implementation """ return """<HTML><head></head> <body> Shortcut for """+`self.__obj__`+""" <p> <a href="""+`self.__obj__.absolute_url()`+""">View original object</a> <p> <a href="""+self.__obj__.absolute_url()+"""/manage_workspace>Edit original object</a> </body></html>""" Once again, this is just proof of concept, and should be correctly (read 'nicely' :-) implemented for Zope 2.6. C U! -- Mario Valente
participants (2)
-
Mario Valente -
Michael R. Bernstein