how to create an album and view photos belonging to that album

84 views
Skip to first unread message

Rahul

unread,
Jun 18, 2014, 4:50:09 AM6/18/14
to web...@googlegroups.com

Hi All,
      I am writing an image gallery in my app. I am stuck up here -
I want to display images that belong to a particular album when I select that album in the view. Although I am able to display albums in the view, but cannot proceed further to display images belonging to that particular albums after clicking the album (from the view). 

here are the table in db.py -
db.define_table('photoalbum',
   
Field('reguser_id'),
   
Field('album_name'),
   
Field('short_description'),
   
)

db
.define_table(photos',
    Field('
reguser_id'),
    Field('
caption'),
    Field('
category', requires=IS_IN_SET(pix_cat)),
    Field('
description', 'text'),
    Field('
upload_photo', 'upload' , uploadfolder=request.folder + 'static/uploads', default=0,  autodelete=True,),
    Field('
album_name', requires=IS_IN_SET(albums)),
    )



Controller - default.py

def myalbums():
   
   
## selects all albums
    allalbums
= db(db.photoalbum.reguser_id == session.logged_in_user_id). select(db.photoalbum.album_name)
   
   
# selects descriptions for all albums
    alldescriptions
= db(db.photoalbum.reguser_id == session.logged_in_user_id). select(db.photoalbum.short_description)
   
   
## selects photos
    allimages
= db(db.photos.reguser_id == session.logged_in_user_id). select(db.photos.upload_photo, db.photos.caption, db.photos.description, cache=(cache.ram,20))
   
   
return dict(allalbums=allalbums, alldescriptions=alldescriptions, allimages=allimages)


Code in the view myalbum.html
<!-- New Try -->

{{for i in range(len(allalbums)):}}        
       
       
<ul class="thumbnails">
       
<!-- Iterate over all images - -->
       
<li class="span2">
       
<div class="thumbnail">
       
<!-- <img data-src="holder.js/300x200" alt="300x200" style="">   -->
               
       
{{=(A(IMG(_src=URL(r=request,c='static\images',f='vimage.jpg')),_href=URL (r=request,c='default', f='myalbums', args=[allalbums[i].album_name]) ))}}
           
       
       
<div class="caption">        
       
<h5>{{=allalbums[i].album_name}}</h5>
       
<p>{{=alldescriptions[i].short_description}}</p>
       
       
       
</div>
       
        </
div>
       
</li>
           
           
{{pass}}    
           
{{pass}}  


Here I can get the album names in the view but when I click on it, it should query all the photos belonging to that particular (as specified in args) albumname and show all images in another page or a carousel that I would create.

Again - The image vimage.jpg specified in the view is a static image, can the thumbnail image representing a particular album be created from an image from within the album ? Please suggest ..


Thanks , Rahul

Dave S

unread,
Jun 19, 2014, 3:01:14 PM6/19/14
to web...@googlegroups.com


On Wednesday, June 18, 2014 1:50:09 AM UTC-7, Rahul wrote:

Hi All,
      I am writing an image gallery in my app. I am stuck up here -
I want to display images that belong to a particular album when I select that album in the view. Although I am able to display albums in the view, but cannot proceed further to display images belonging to that particular albums after clicking the album (from the view). 

here are the table in db.py -
db.define_table('photoalbum',
   
Field('reguser_id'),
   
Field('album_name'),
   
Field('short_description'),
   
)

db
.define_table(photos',
    Field('
reguser_id'),
    Field('
caption'),
    Field('
category', requires=IS_IN_SET(pix_cat)),
    Field('
description', 'text'),
    Field('
upload_photo', 'upload' , uploadfolder=request.folder + 'static/uploads', default=0,  autodelete=True,),
    Field('
album_name', requires=IS_IN_SET(albums)),
    )

I would think you want the last line to be a reference, like Field('album_name', 'reference photoalbum');

Do you want a redirect, or to have multiple pages open at a time?

In either case, don't you need a link (to another controller) or an action (from a form) that would query for somethng like db(photos.album_name == var.album_name).select() ?

I'm not a dab hand at this; I'm still bouncing back and forth in the manual as I type this,
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#One-to-many-relation>
but there's a bunch of examples in the recent posts to this list.

Grabbing one thread rather quickly, this one might have some pertinence:
<https://groups.google.com/d/msg/web2py/nDBOL7w6qB4/3181A5kRWSAJ>

 
Again - The image vimage.jpg specified in the view is a static image, can the thumbnail image representing a particular album be created from an image from within the album ? Please suggest ..

I've read about the thumbnail processing in the book, and a couple of examples in the groups since last summer, but haven't actually tried it.  So I'll defer to others, other than to say that "seems possible".

/dps

Rahul

unread,
Jun 20, 2014, 12:54:42 AM6/20/14
to web...@googlegroups.com
Thanks! for replying Dave. While I am open to suggestions, I plan to redirect the request such that as soon as the user clicks on any album thumbnail - he gets redirected to a page (perhaps viewalbum.html) where all images belonging to a particular album are listed.

Thanks, Rahul.

Rahul

unread,
Jun 20, 2014, 4:14:59 AM6/20/14
to
Hi Dave, All,
          I found a solution - It was easy -
wrote a new function that takes a parameter, called it in the view and it redirects to the required page.

query
= (db.fotoz.album_name == "%s" % request.args(0))



and have this
<p> <a href="{{=URL(r=request, c='default', f='view_album', args=[allalbums[i].album_name])}}"    class="btn">View Album</a></p>


in view.

That sends the argument to this function and displays the album. The only issue is with spaces in album names that dont work. But I would find a workaround over it.

We can consider this thread closed. Thanks Everyone.

Cheers, Rahul

A few threads that helped... -
https://groups.google.com/forum/#!topic/web2py/WJtJ-QDemTM
http://stackoverflow.com/questions/9328126/web2py-connecting-to-the-correct-controller
https://groups.google.com/forum/#!topic/web2py/ICo5-yFgxmc

Dave S

unread,
Jun 21, 2014, 2:39:10 PM6/21/14
to web...@googlegroups.com


On Friday, June 20, 2014 1:14:59 AM UTC-7, Rahul wrote:
Hi Dave, All,
          I found a solution - It was easy -
wrote a new function that takes a parameter, called it in the view and it redirects to the required page.

Glad you got it going.  You're moving ahead faster than I am   :-)

/dps
 

query
= (db.fotoz.album_name == "%s" % request.args(0))



and have this
<p> <a href="{{=URL(r=request, c='default', f='view_album', args=[allalbums[i].album_name])}}"    class="btn">View Album</a></p>


in view.

That sends the argument to this function and displays the album. The only issue is with spaces in album names that dont work. But I would find a workaround over it.

We can consider this thread closed. Thanks Everyone.

Cheers, Rahul

A few threads that helped... -
https://groups.google.com/forum/#!topic/web2py/WJtJ-QDemTM
http://stackoverflow.com/questions/9328126/web2py-connecting-to-the-correct-controller
https://groups.google.com/forum/#!topic/web2py/ICo5-yFgxmc




On Friday, June 20, 2014 10:24:42 AM UTC+5:30, Rahul wrote:

Rahul

unread,
Jun 23, 2014, 1:19:16 AM6/23/14
to web...@googlegroups.com
Thanks! Dave, been using web2py since 2010 :) however not been active in coding from last few months.. (kinda lost touch) I'll get over it quickly though.

Rahul
Reply all
Reply to author
Forward
0 new messages