[Zope] Accessing attributes - object with 'implicit' period in id

Casey Duncan casey@zope.com
Wed, 29 May 2002 10:06:44 -0400


thumbURL is just a string that contains the path to the image correct? I'=
m=20
assuming that thumbURL is a metadata element from you ZCatalog right?

If this is the case then the information you seek cannot be gotten from t=
he=20
URL unless you traverse it to find the original object. Now traversal is=20
expensive, so you want to do it as seldom as possible. Therefore I sugges=
t=20
that you do it exactly once when the object is cataloged and store the=20
generated image tag as catalog metadata.

In order to do this, write a short Python script called something like=20
"thumbTag" with this code in it:

thumb =3D container.restrictedTraverse(context.thumbURL)
return thumb.tag(alt=3Dcontext.caption)

Put this Python script somewhere where it can be acquired by the Catalog =
and=20
all the image objects. Inside the ZCatalog will also work. Now add a meta=
data=20
element to the ZCatalog with the same name as the Python script (thumbTag=
).=20
Update your catalog to fill in the metadata. Go to the catalog tab and se=
e if=20
the thumbTag values got filled in (they should contain image tags)

Your DTML can now be:

<a href=3D"&dtml-imageURL;"><dtml-var thumbTag></a>

hth,

Casey

On Wednesday 29 May 2002 02:26 am, John Schinnerer wrote:
> Aloha,
>=20
> I'm back with an example.  My situation seems different than solutions
> in recent threads, and I don't see how the answers thus far apply (if
> they do).
>=20
> I'm looping through the results of a catalog search, displaying
> thumbnail images, caption, date, etc..  A thumbnail, linked to a
> full-sized image, is displayed for each result:
>=20
> ...
> <a href=3D"<dtml-var imageURL>">
>   <img src=3D"<dtml-var thumbURL>" border=3D"0" alt=3D"<dtml-var captio=
n>">
> </a>
> ...
>=20
> imageURL and thumbURL are properties of each gallery item which point
> to the actual image, and will be something like:
>=20
> /gallery/thumbs/C03Valley001.jpg
>=20
> I want to get the height and width attributes from each thumbURL item
> and use them in the img tag attributes.  But:
>=20
> height=3D"<dtml-var thumbURL.height>" does not work, giving:
>=20
> Error Value: exceptions.KeyError on thumbURL.height in ""
>=20
> I am assuming this is because in my situation all thumbURL items
> returned are objects with periods in their IDs.  So it's choking on
> trying to find '/gallery/thumbs/C03Valley001.jpg.height' - is this the
> case?  Or is there some other problem here?
>=20
> In any case, how do I access the attributes (like height and width) in
> this situation, where the period in the actual ID is 'implicit' in
> thumbURL?
>=20
> thx,
> John S.