I am trying to use session.counter to count clicks on images on a page.
My problem is that my session.counter is not counting...
I am doing something wrong, not sure exactly what.
I am pretty sure the issue is the* if image.id == 1*
I'd appreciate some help with this.

*Controller:*

def index():
    images = db().select(db.image.ALL, orderby=db.image.id)
    return dict(images=images)

def show():
    image = db.image(request.args(0,cast=int)) or redirect(URL('index'))
    one_counter = []
    two_counter = []
    three_counter = []
    if image.id == 1:
        session.counter = (session.counter or 0)+1
        one_counter=session.one_counter
    elif image.id == 2:
        session.counter = (session.counter or 0)+1
        two_counter=session.two_counter
    elif image.id == 3:
        session.counter = (session.counter or 0)+1
        three_counter=session.three_counter
    return dict(image=image)

def download():
    return response.download(request, db)

*View:*

show:
<h3>{{=0 if session.one_counter is None else session.one_counter}}</h3>
<h3>{{=0 if session.two_counter is None else session.two_counter}}</h3>
<h3>{{=0 if session.three_counter is None else session.three_counter}}</h3>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to