Forum OpenACS Q&A: Random photo from photo-album?

Collapse
Posted by Jade Rubick on
Is there an easy way to get a random image from your photo-album app, and return it in another page?

Also, is there a reason Jeff's(?) improvements (I'm not sure what they are, but I've heard about them) haven't been folded into the photo-album in CVS? Or maybe they have?

Collapse
Posted by Don Baccus on
If they're not in it's because Jeff hasn't put them in, nag him in e-mail if you want!
Collapse
Posted by Robert Locke on
Hi Jade,

I don't think it's been folded into CVS.

Regarding the first part of your question, I've never done it, but poking into Jeff's code, you could use the photo-album/www/photo.* page as a model.

The idea would be to create a simple "include" that would return the image tag for the photo.

First, change the query in photo.xql:

* remove the "ci.item_id = :photo_id"

* add a security check in the where clause:
    and acs_permission__permission_p(ci.item_id, :user_id, 'read') = 't'

* grab a random image by appending:
    order by random()
    limit 1

Copy the relevant parts of the adp (ie, the image tag plus admin links if you want).

Caveat: the query would cut across all photo-album instances.  Also, since the image tag will be included potentially from another page/package, you will need to give the fully qualified URL for the image (ie, starting at /photos or wherever photo album(s) is mounted).  I think you could do this by extending the query to join with cr_folders and site_nodes.  Or if you're in a rush and you have only one photo album mounted, hard-code it as a parameter to the "include" (bad but easy).

Hope that helps.  Let me know if you would like me to work on the code and send it your way.

Collapse
Posted by Ben Koot on
Jade,

I memory serves me right, Lars used have a random image function on his first blogger.

Cheers
Ben

Collapse
Posted by Dave Bauer on
RObert,

Pass in the package_id to the include template to limit to one package instance.

<include src="ramdom-photo" package_id="12345">

Or slightly more user friendly, pass in the url relative to the subsite root to the photo album instance to the include, and have the include determine the package id for the query.
<include src="random-photo" package="my_photos">

Collapse
Posted by Jarkko Laine on
Lars did and still does have a random photo on pinds.com. It's a quick-and-dirty solution, discussed here.
Collapse
Posted by Jarkko Laine on
Oh, and about Jeff's photo album: It's been finally ported to Oracle by Michael Steigman and needs a bit testing, but it should be committed as a whole in very near future.
Collapse
Posted by Vinod Kurup on
Doh! I also ported Jeff's photo-album to Oracle and sent it to him a couple weeks ago. Oh well... it'll be nice to have it in CVS 😊
Collapse
Posted by Jade Rubick on
Robert, thanks for the great reply!

I think this might be a nice addition the photo-album.

If you have the time to do it, great! If not, I'll get around to it sometime. If I do it, should I submit it as a patch?

Collapse
Posted by Robert Locke on
I'll happily work on it if you or someone needs it right away.  Otherwise, first one to get around to it should email the other before getting started.  Deal?

I think if the patch is nice and generic, then it should be committed to CVS, with Jeff's approval ofcourse.

Thanks!

Collapse
Posted by Jade Rubick on
Sounds like a deal to me :)

I don't need it right away, but I'm able to use it whenever it's completed. I'll write you if I get to it first.