Hi all, I am starting to figure out things about Zope. And to this problem I have not yet figured out an answer: I have a lot of metadata about photos stored in a MySQL database. I have developed a Zope interface to show the metadata per picture using Zope and it works fine. I store small thumbnails in Zope for some, but not all the pictures. The thumbnail files have the same id as the MySQL variable idnumber which I show on the screen together with other metadata. My problem is that I cant figure out how to a/ test if there is a thumbnail file for the idnumber variable and b/ if so - show it together with the metadata - and if not - show a dummy picture instead I have tried many things but it seems impossible to have Zope test if the contents of the <dtml-var idnumber> variable can be used to check the exsitence of a possible thumbnail file with the same name. Is there a solution? Best regards from sunny but rather cold Stockholm, Ebbe _____________________________________________________________ Här börjar internet! Skaffa gratis e-mail och gratis internet på Spray http://www.spray.se
Hi Ebbe, b/ Once you have figured out a 'test' for the existence of the picture file, you can write something like: <dtml-in list_of_Pictures> <dtml-if test> <dtml-call "REQUEST.set('tempPict', _['sequence-item'][0])"> <dtml-else> <dtml-call "REQUEST.set('tempPict', dummyPicture)"> </dtml-if> ... here you show the metadata and tempPict ... </dtml-in> providing that 'list_of_Pictures' is the full list you must show and sequence-item is the list containing the picture itself and metadata of your picture. a/ if the picture has a correspondent thumbnail in Zope, you can test by size (if is >0 ) or by content_type (if it's not 'application/octet-stream'). My suggestion is to make Zope objects for all the images and to keep an extra Boolean property of the Zope object like 'has_largerImage'. If not, it depends on how you keep the picture in a database: the file you probably keep in a blob. If the blob is on the same record with the metadata (which is not recommended), you should have at list a field like 'content_type' or 'size' that you can test. If you have the blob in a separate table, it's fine, since you have a filed saying what's the id of the record from the other table a, let's say, 0 for nothing. Tell me if that solves the problem Cheers, Miruna || -----Original Message----- || From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Ebbe || Kvist || Sent: Friday, October 25, 2002 3:17 AM || To: zope@zope.org || Subject: [Zope] showing images || || Hi all, || || I am starting to figure out things about Zope. And to this problem I have || not yet figured out an answer: || I have a lot of metadata about photos stored in a MySQL database. I have || developed a Zope interface to show the metadata per picture using Zope || and it works fine. I store small thumbnails in Zope for some, but not all || the pictures. The thumbnail files have the same id as the MySQL variable || idnumber which I show on the screen together with other metadata. || My problem is that I cant figure out how to || || a/ test if there is a thumbnail file for the idnumber variable and || b/ if so - show it together with the metadata - and if not - show a dummy || picture instead || || I have tried many things but it seems impossible to have Zope test if the || contents of the <dtml-var idnumber> variable can be used to check the || exsitence of a possible thumbnail file with the same name. || || Is there a solution? || || Best regards from sunny but rather cold Stockholm, || Ebbe || || || _____________________________________________________________ || Här börjar internet! || Skaffa gratis e-mail och gratis internet på Spray http://www.spray.se ||
Ebbe Kvist writes:
... a/ test if there is a thumbnail file for the idnumber variable and You can use the following Python Script to check whether a folder as a given child (which is the Id):
hasChild: Parameters: folder,child Body: try: folder[child] return 1 except KeyError: return 0 You use it in the form hasChild(your_folder_containing_the_thumbnails,str(idnumber)) (If you use it in "DTML", "str" becomes "_.str").
b/ if so - show it together with the metadata - and if not - show a dummy picture instead In DTML: <img src="<dtml-if expr="hasChild(...)" ><dtml-var expr="your_folder...[_.str(idnumber)].absolute_url() ><dtml-else>dummy_picture_url</dtml-if>">
In ZPT: <img src="dummy_picture_url" tal:define="idnumber python: str(idnumber)" tal:attributes=" src python:here.hasChild(your_folder,idnumber) and your_folder[idnumber].absolute_url() or default; " > Dieter
participants (3)
-
Dieter Maurer -
Ebbe Kvist -
Miruna Badescu