[Zope] checking for existing object in dtml (localFS)

Andreas Elvers andreas@gomorrha.de
Sun, 2 Apr 2000 13:05:22 +0200 (CEST)


Hi,

I'm right now in the phase of gaining some zope enlightenment. Here we go
:-)

Problem: From an SQL query I get some info stuff and the filename of
         a picture. This picture may be inside the /images Folder.
         Now I want to give a summary of the data with the picture when
         existing.

First solution: (found this one here in the mailinglist)
         
> <dtml-if "_.hasattr(images, image_name)">  # if it exists
>    <dtml-var "_.getattr(images, image_name)"></a> # display it
> <dtml-else> # otherwise
>     Some other thing to do (I used a text link)
> </dtml-if>

This works fine with a normal zope folder object. My images reside on the
local filesystem and are mounted via the supercool LocalFS product.

But...

the above code didn't work for me. hasattr always returned 'false' for any
file inside the localfs Folder.

I came up with the following solution (this works for me):

<!--#in "images.objectIds([image_name])"-->
  picture: <IMG SRC="/images/<!--#var sequence-item-->">
<!--#/in-->

(From this point on I began to experiment.)


Fine. Now I thought about doing the IMG part in the zope way. Thus I have
to use objectValue instead of objectIds... Let's see:

<!--#in "images.objectValues([image_name])"-->
  picture: <!--#var sequence-item-->    
<!--#/in-->

Nope... This will not work with LocalFS.

Let's test this one on a normal zope folder:

<!--#in "zopeFolderWithImages.objectValues(['someimage.gif'])"-->
  picture: <!--#var sequence-item-->
<!--#/in-->

no way. It's not working...

This one is working for a normal Zope Folder:

<!--#in "zopeFolderWithImages.objectValues(['Image'])"-->
  picture: <!--#var sequence-item-->
<!--#/in-->

This will give me all images in the folder... But I only want to test for
one picture. Anyway...

Let's test the last example with LocalFS ! It's not working. 

I'm a bit confused.

To summarize:

- I can not use _.hasattr(folder,'nameofimg.gif') to test for the
  existence of an image within localFS folder. But it works for
  normal Zope folders.

- folder.objectIds(['Image']) won't return a list of IDs of images
  within a LocalFS folder. But it does in a normal Folder.

- within LocalFS folder.objectIds(['someimage.gif']) will return 
  a list with only 'someimage.gif' within it. But 
  folder.objectValues(['someimage.gif']) will not return a list with
  the file object.

- further folder.objectIds(['someimage.gif']) won't work inside normal
  Zope folder objects but will work inside LocalFS folders.

I would be glad to have some testing method that will work on both types
of folder. And easy. And small. And dtml :-)

Greetings
- Andreas


--------------------------------------------------------------------------
                 i s   t i m e   l o n g  ?   o r   i s   i t   w i d e  ?