Re: Zope digest, Vol 1 #704 - 52 msgs
John Morton <jwm@plain.co.nz>
Date: Mon, 27 Mar 2000 16:29:30 +1200 (NZST) To: zope@zope.org Subject: [Zope] Problems with adding ZClass instances
I'm have problems with a ZClass I'm working on that uses Folder as it's base class and is supposed to install a set of default methods when it's created. The trouble is that it won't when the webDirectory is created, but it will when I invoke the same method from a tab afterwards.
Here's the body of webDirectory_add:
<dtml-with "webDirectory.createInObjectManager(REQUEST['id'], REQUEST)"> <dtml-if createDefaultMethods> <dtml-in "default_methods.objectIds()"> <dtml-try> <dtml-call "manage_delObjects(ids=[_['sequence-item']])"> <dtml-except> </dtml-try> <dtml-call "manage_clone( _.getattr(default_methods, _['sequence-item']), _['sequence-item'], REQUEST)"> </dtml-in> </dtml-if> </dtml-with>
I'm assuming that the code within the <dtml-with ...> is effectively opperating in the context of the newly created object, but when the first manage_clone() is executed, it bombs out in _getCopy, tripping over on this line:
ob=container._p_jar.importFile(f)
...because whatever container is, it's not a folderish object.
So what do I need to do to switch to the new webDirectory object at creation time, so adding methods is automatic?
I do something very similar in the ZGotW product's root factory:: <dtml-in "defaults.objectIds( 'DTML Method' )"> <dtml-let si=sequence-item> <dtml-with newRoot> <dtml-call "manage_addDTMLMethod( si, '', defaults[ si ] )"> </dtml-with> </dtml-let> </dtml-in> The key here may be the inner '<dtml-with newRoot>', which is forcing the newly-created root folder to the top of the namespace stack, so that 'manage_addDTMLMethod()' is being invoked on it, rather than on the sequence-item. Hope this helps! Tres. -- ========================================================= Tres Seaver tseaver@digicool.com tseaver@palladion.com
Tres Seaver writes: [I couldn't add default methods to a ZClass instance, Tres provided a method.]
The key here may be the inner '<dtml-with newRoot>', which is forcing the newly-created root folder to the top of the namespace stack, so that 'manage_addDTMLMethod()' is being invoked on it, rather than on the sequence-item.
Hope this helps!
Yes and no :-) Your product's add method creates a folder object, then switches to it and adds the default methods with each appropriate add method. What I was trying to do was add a ZClass based product with the createInObjectManager method, then use manage_clone to copy my default objects across. It turns out I was doing this from the right place (inside the dtml-with that is used to create the object), but manage_clone is broken - it let you copy objects into a thing you've just created inside the same method at all. I'm pretty sure this is a bug - I'd be interested to know if anyone has actually got this working at all. In the process of testing this out, I discovered another piece of unexpected behaviour - you can do this: <dtml-with "manage_addFolder( rootID, rootTitle )"> </dtml-with> ...and you can then switch to using that object straight away, but if you do this: <dtml-with "webDirectory.createInObjectManager(REQUEST['id'], REQUEST)"> </dtml-with> ...the object you've just created doesn't appear to exist as far as the rest of your dtml method is concerned. So I've got something working, using the various object add methods, but I need to make sure I have one for each type of object in my default set, and I have a feeling that I'll need to recurse into folders to add those and their contents. Thank, John.
John Morton writes:
So I've got something working, using the various object add methods, but I need to make sure I have one for each type of object in my default set, and I have a feeling that I'll need to recurse into folders to add those and their contents.
Arg! I don't seem to be able to add anything other than DTML methods and properties inside a Zclass creation. So it looks like I'm back to doing it all by had. What a time saver... John.
John Morton writes:
John Morton writes:
So I've got something working, using the various object add methods, but I need to make sure I have one for each type of object in my default set, and I have a feeling that I'll need to recurse into folders to add those and their contents.
Arg! I don't seem to be able to add anything other than DTML methods and properties inside a Zclass creation. So it looks like I'm back to doing it all by had. What a time saver...
Take three. I've solved the problem for all cases by having the ZClass add method redirect to a method that copies the default methods into the new ZClass instance, then redirects back to the management screen. Might have to write a howto for this one. John.
(Sorry for omitting to re-title the previous posts!) John Morton wrote:
John Morton writes:
John Morton writes:
So I've got something working, using the various object add methods, but I need to make sure I have one for each type of object in my default set, and I have a feeling that I'll need to recurse into folders to add those and their contents.
Arg! I don't seem to be able to add anything other than DTML methods and properties inside a Zclass creation. So it looks like I'm back to doing it all by had. What a time saver...
Take three. I've solved the problem for all cases by having the ZClass add method redirect to a method that copies the default methods into the new ZClass instance, then redirects back to the management screen.
Might have to write a howto for this one.
John.
I'm glad you found a workaround. Just offhand, did you try to just call that additional method, before redirecting to it? I have seen a couple of cases where I refactored code like that into a new method and then things got simpler. Tres. -- ========================================================= Tres Seaver tseaver@digicool.com tseaver@palladion.com
Tres Seaver writes:
Take three. I've solved the problem for all cases by having the ZClass add method redirect to a method that copies the default methods into the new ZClass instance, then redirects back to the management screen.
Might have to write a howto for this one.
I'm glad you found a workaround. Just offhand, did you try to just call that additional method, before redirecting to it? I have seen a couple of cases where I refactored code like that into a new method and then things got simpler.
Tried that - I in-lined it on the list for brevity's sake. The problem is definitely with manage_clone not wanting to be used on a thing inside the transaction that creates that thing. John.
participants (2)
-
John Morton -
Tres Seaver