[Zope] - Copying Zope objects programmatically
Jim Fulton
jim@digicool.com
Thu, 31 Dec 1998 12:39:53 +0000
"A.M. Kuchling" wrote:
>
> Continuing on my channeling, I'm now trying to let users enter a
> selected ID; a folder named with that ID would then be created and set
> up.
>
> Creating the folder in DTML is easy:
>
> <!--#call expr="_['user'].manage_addFolder(userid)"-->
>
> I can even set a property on the newly created folder:
>
> <!--#call expr="_['user'][userid].manage_addProperty('cl', 'c1 c2 c3', 'tokens')"-->
>
> (Incidentally, these expression lines are getting awfully long. Is
> there any way to insert newlines in them?)
Sure. For example:
<!--#call expr="_['user'][userid].manage_addProperty(
'cl', 'c1 c2 c3', 'tokens')"-->
>
> However, I can't figure out how to create a new index_html object
> whose content is a duplicate of another default object; the third
> argument to the manage_addDocument() is never right.
>
> <!--call expr="_['user'].manage_addDocument('index_html',
> 'User Page:'+userid,
> _['default_user_page'].data)"-->
Is default_user_page a file or a document?
From the text below, I assume a document, but then
I wonder where you got the 'data' attribute from.
>
> _['default_user_page'].data doesn't work.
Right, because if _[] returns a document template, it renders it.
This is problematic. "_['name']" should be equivalent to: "name",
but it isn't if the value of name is callable. :(
I really should figure out a fix for this.
> str(_['default_user_page'])
> creates the page, but it also replaces < with <, so the DTML on the
> resulting page doesn't work.
That's odd. Since _[] renders DTML, you shouldn't
get the quoting.
> How do you get the contents of the
> Document object without it being escaped?
First, you need to get the DocumentTemplate without rendering
it. Due to details in _, which is a template dictionary,
you have to use:
_.getitem(name, 0)
although, if the name is a legal Python name, just
use the name directly (without _[]).
Second, to get the source, call it's 'read' method.
So, in your example, the following should work:
<!--call expr="_['user'].manage_addDocument('index_html',
'User Page:'+userid,
default_user_page.read())"-->
Note that 'read' is not the greatest method name for this
and this interface isn't documented because I never thought anyone
would want it. I've seen this question enough, however, that there
should definately be a nicer interface for it.
> Or am I barking up the wrong tree?
No.
> Should this sort of thing be
> implemented as an ExternalMethod?
You would still need to know about the read method.
Jim
--
Jim Fulton mailto:jim@digicool.com
Technical Director (540) 371-6909 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.