[Zope] throwing exceptions when <img src=...> does not exist
John Morton
John Morton <jwm@plain.co.nz>
Tue, 20 Feb 2001 13:01:13 +1300 (NZDT)
On Mon, 19 Feb 2001 23:29:17 +0000 Lee <lee.reilly@ntlworld.com> wrote:
> hi,
>=20
> i have a little problem re: img and dtml-try tags:
>=20
> there are images stored on an external server - these are named after
> student's universtity usernames e.g. lreilly.gif. represents moi, lee
> reilly. the problem is that it is not guaranteed that such an image is
> stored for *every* student so i want to do something like...
>=20
> <dtml-try>
> <img src=3D"d:\<dtml-var uname>.gif" width=3D"240" height=3D"180">
> <dtml-except>
> <img src=3D"d:\dilbert.gif" width=3D"240" height=3D"180">
> </dtml-try>
>=20
> i.e. if the student gif exists display it otherwise display the file
> dilbert.gif.
This code will only throw an exception if the attribute 'uname'
doesn't exist, which is not what you're looking for. The whole 'd:/'
business looks like it might be a source of trouble too, but maybe that's
just the way your setup works.
> if the files were stored on zope then modifying the <img> tags to plain
> <dtml-var uname> would work fine except that
>=20
> (i) they're not stored on my server
You have a complicated problem then :-)
> (ii) <dtml-var uname> would display the username and not the image
> (id=3Dusername) - i think this can be overcome though.
>=20
> is there anyway to adapt the above code to actually *throw* an exception
> when the image is not located. the results of the above code are as
> follows:
>=20
> if the files exist =3D> it is displayed
> if the file doesn't exist =3D> nothing is displayed
I'd try one of three things:
- Move the images onto your Zope server as either images stored in the
ZODB, or use the ExtImage product to store the image data on the
filesystem and the metadata inside Zope. This is probably a nuisance, or
you would have done it already.
- Store information per user to indicate whether they have an image on
that server or not. Which involves determining that information in the
first place and keeping it up to date, which is not fun.
- Write an external method that goes out and checks whether the image in
question actually exists on the server. You might need to do an HTTP HEAD
on the expected image URL, but this is roughly what the user's browser
will have to do, so it's pretty much the canonical test.
John