[Zope] Finding an object in a folder
Chris Withers
chris at simplistix.co.uk
Mon May 23 15:02:05 EDT 2005
Dieter Maurer wrote:
> Allen Huang wrote at 2005-5-8 02:28 -0700:
>
>>Here is the problem. I want to use a form to upload a file (with a specific name) but first I want to check if another file with the same name already exist in that folder. How do I use a if or dtml-if to solve this problem??
>
> <dtml-if expr="hasattr(the_folder.aq_inner.aq_explicit, the_id)">
> "the_id" exists
> <dtml-else>
> "the_id" does not exist
> </dtml-if>
Dieter, I'm shocked ;-)
Why in DTML? Even though Allen mentions DTML, this never belongs in DTML.
Worse still, you use hasattr with ZODB... hastattr swallows all
exceptions, including ConflictErrors, and especially in this example
that would be a bad thing...
if getattr(thefolder.aq_inner.aq_explicit,the_id,None):
print the_id + ' is in use'
else:
print the_id + ' is in use'
return printed
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list