RE: [Zope] Beginner DTML question: dereferencing a variable
-----Original Message----- From: Martin Dougiamas [mailto:martin@complex.curtin.edu.au] Sent: Tuesday, April 06, 1999 7:00 AM To: zope@zope.org Subject: Re: [Zope] Beginner DTML question: dereferencing a variable
Martin Dougiamas wrote:
I want to check if a folder of that name already exists under the current folder, so I can decide to create it or not.
Intuitively, I first tried:
<!--#if "theusername"--> <H3>FOLDER EXISTS</H3> <!--#else--> <H3>FOLDER DOES NOT EXIST</H3> <!--#/if-->
I seem to found a solution myself. This seems to work:
<!--#if "_.has_key(theusername)"--> <H3>FOLDER <!--#var "theusername"--> EXISTS</H3> <!--#else--> <H3>FOLDER <!--#var "theusername"--> DOES NOT EXIST</H3> <!--#/if-->
...as long as there's not a object with that name UP the hierarchy, I suppose.
Yes, acquisition could defeat you with this method. Try the objectIds method. From /lib/python/OFS/ObjectManager.py, def objectIds(self, spec=None): """Return a list of subobject ids. Returns a list of subobject ids of the current object. If 'spec' is specified, returns objects whose meta_type matches 'spec'. """ So you can use the sequence that objectIds returns in your DTML to find out if any subobjects if meta_type 'Folder' exist with the username your looking for. <!--#in "objectIds('Folder')--> <!--#if "id == theusername"--> Folder Exists <!--#/if--> <!--#/in--> You want to use a DTML Method to get the expected result. -Michel
If there's a cleaner way to do this I'd still like to know it.
Cheers! Martin
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(For developer-specific issues, use the companion list, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
On Tue, 6 Apr 1999, Michel Pelletier wrote:
Martin Dougiamas wrote:
I want to check if a folder of that name already exists under the current folder, so I can decide to create it or not.
<!--#in "objectIds('Folder')--> <!--#if "id == theusername"--> Folder Exists <!--#/if--> <!--#/in-->
You want to use a DTML Method to get the expected result.
OK, that handles the case where you want to find the object and do something to it. How do you propose to handle the opposite case (which Dougiamas-san requested) -- do something if the entry DOES NOT exist. IMHO, this calls for a local variable to set and test. You might use REQUEST.set('I_found_the_folder' ... However, the use of the global REQUEST namespace has its hazards :-(
participants (2)
-
Michel Pelletier -
Richard Wackerbarth