[Zope] Random images--but with a caveat

Oliver Bleutgen myzope@gmx.net
Fri, 21 Jun 2002 23:00:33 +0200


Chris Muldrow wrote:
> I'm trying to do random image generation on our site, and I've found lots of
> messages that suggest using whrandom inside a DTML tag like so:
> 
> <dtml-var expr="_.whrandom.choice(objectValues('Image'))">
I'd use (untested, but probably right)
<dtml-var expr="_.getitem(_.whrandom.choice(objectIds('Image')))">

for performace reasons. First, choose your image from the list of ids 
(objectIds), which is much faster to get, and the get the object with 
this id.

> Or code to that effect...
> But here's my catch: I need to check the image that is returned randomly for
> a Cutline property. If the property is not there, I need to kick that image
> out and randomly grab another that does have a Cutline. I'm thinking a
> Python Script would be better suited for this, but I can't seem to get the
> syntax to work out the way it should. Any ideas?
> Thanks! - Chris

In light of what you say here, what I wrote above doesn't help you, 
because to get the property, you need the object.
OTOH, in light of what I said above, you might reconsider what you are 
doing now ;-).
Really, wouldn't it be possible to just put the images in two different 
folder instead of tacking a property to them?

If you really want to do it your way, just build a list of images with 
the Cutline property and do a random choice on this list.

cheers,
oliver