[Zope-dev] manage_clone? (amongst others!)

Shane Hathaway shane@digicool.com
Tue, 11 Jul 2000 08:32:14 -0400


Chris,

I'm sorry to hear about your challenges.  I've had some myself.

I think you're being bitten by a bug which prevented manage_clone from
working in a lot of situations, but is solved in 2.2.  The problem was
that when a new object was placed in a container, it didn't get a _p_jar
attribute until the database transaction was completed (which is
standard practice).  But _getCopy() depends on a _p_jar.  So if you
tried to copy an object into an object which has just been placed in the
object hierarchy (a common thing to do), _getCopy() failed.

To fix this, change ObjectManager._setObject() to this:

    def _setObject(self,id,object,roles=None,user=None, set_owner=1):
        v=self._checkId(id)
        if v is not None: id=v
        try:    t=object.meta_type
        except: t=None
        self._objects=self._objects+({'id':id,'meta_type':t},)
        # Prepare the _p_jar attribute immediately. _getCopy() may need
it.
        object._p_jar = self._p_jar
        self._setOb(id,object)
        object=self._getOb(id)

This will probably work fine in 2.1.x.

manage_addProduct[] gives you access to the object factories.  I wonder
if it would be clearer if you could use "productFactory[]" as a synonym?

Shane

Chris Withers wrote:
> 
> I was going to title this 'I should give up using Zope' but I thought
> I'd give it one last go...
> 
> Yesterday's 6hrs failing to do a tree-walk-and-copy in DTML failed, so I
> thought I'd try in an external method today...
> 
> ..well, that proved to be just as stupid.
> 
> Okay, firstup, has anything happened on this issue:
> http://zope.nipltd.com/public/lists/dev-archive.nsf/ByKey/37C533B80F56E22A
> 
> Basically, it seems like doing anything with ZClasses in python (an
> external method in my case) is likely to lead to suicide on your part.
> 
> How shoudl I be instantiating one?
> 
> Secondly, AFAIU, the following should copy o and put it in the folder
> object 'where' with an id of 'new_id':
> 
> where.manage_clone(o,'new_id')
> 
> It does, for DTML Methods, but for anything else I get:
> 
> Error Type: AttributeError
> Error Value: 'None' object has no attribute 'importFile'
> (the traceback is in a PS ;-)
> 
> Why? How should I be doing this?!
> 
> Lastly, in the following:
> where.manage_addProduct['OFSP'].manage_addFolder(id,title)
> 
> What does the manage_addProduct['OFSP'] actually do?
> In what way does the above differ from:
> where.manage_addFolder(id,title)
> 
> ...which works just fine for me...
> 
> Hope _someone_ can help,
> 
> Chris
> 
> PS:
> Traceback (innermost last):
>   File /usr/local/zope/2-1-6/lib/python/ZPublisher/Publish.py, line 214,
> in publish_module
>   File /usr/local/zope/2-1-6/lib/python/ZPublisher/Publish.py, line 179,
> in publish
>   File /usr/local/zope/2-1-6/lib/python/Zope/__init__.py, line 202, in
> zpublisher_exception_hook
>     (Object: ElementWithAttributes)
>   File /usr/local/zope/2-1-6/lib/python/ZPublisher/Publish.py, line 165,
> in publish
>   File /usr/local/zope/2-1-6/lib/python/ZPublisher/mapply.py, line 160,
> in mapply
>     (Object: start)
>   File /usr/local/zope/2-1-6/lib/python/ZPublisher/Publish.py, line 102,
> in call_object
>     (Object: start)
>   File /usr/local/zope/2-1-6/lib/python/OFS/DTMLMethod.py, line 150, in
> __call__
>     (Object: start)
>   File /usr/local/zope/2-1-6/lib/python/DocumentTemplate/DT_String.py,
> line 502, in __call__
>     (Object: start)
>   File /usr/local/zope/2-1-6/lib/python/DocumentTemplate/DT_With.py,
> line 148, in render
>     (Object: o-e-s)
>   File /usr/local/zope/2-1-6/lib/python/DocumentTemplate/DT_Util.py,
> line 335, in eval
>     (Object: iterate(this(),where=REQUEST['where']))
>     (Info: this)
>   File <string>, line 0, in ?
>   File
> /usr/local/zope/2-1-6/lib/python/Products/ExternalMethod/ExternalMethod.py,
> line 248, in __call__
>     (Object: iterate)
>     (Info: ((<Folder instance at 86b5fb8>,), {'where': <Folder instance
> at 869c2c0>}, None))
>   File /usr/local/zope/dev/2-1-6/Extensions/chris.py, line 36, in
> iterate
>     (Object: ElementWithAttributes)
>   File /usr/local/zope/dev/2-1-6/Extensions/chris.py, line 42, in
> iterate
>     (Object: ElementWithAttributes)
>   File /usr/local/zope/2-1-6/lib/python/OFS/CopySupport.py, line 290, in
> manage_clone
>     (Object: ElementWithAttributes)
>   File /usr/local/zope/2-1-6/lib/python/OFS/CopySupport.py, line 402, in
> _getCopy
>     (Object: index_html)
> AttributeError: (see above)
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )