can you give me an example code?
here's what i have but doesn't work.
#model
db.define_table('content',
    Field('username'),
    Field('text', 'text'),
    Field('file', 'upload'),
    Field('userpic'),
    Field('time', 'datetime', update=request.now),
    Field('userid', readable=False),
    Field('votesup', 'integer', default=0),
    Field('votesdown', 'integer', default=0),
    Field('votes', 'text', default='0,'),
)

#controller
def voteup():
    item = db.content[request.args(0)]
    if auth.user.id not in item.votes:
        item.votes.join(str(auth.user.id)+',')
        new_votes = item.votesup + 1
        item.update_record(votesup=new_votes)
        return str(new_votes)
    elif auth.user.id in item.votes:
        return str(0)

#view
<button style='margin-left:30px; margin-top:-17px;'>
    <span onclick="jQuery('#content_votesup').val('{{=content.id}}'); 
ajax('{{=URL('voteup', args=content.id)}}', ['votesup'], 
'content0{{=content.id}}');" >
        <img  src='../static/images/thumbsup.png' style='height:20px; 
width:20px;'/>
    </span>
    <span id='content0{{=content.id}}' >
        {{=content.votesup}}
    </span>
</button>



On Wednesday, 15 May 2013 15:22:28 UTC+1, Anthony wrote:
>
> Actually, as long as you are requiring users to register and log in, you 
> might as well just associate each vote with a user ID -- then when a user 
> votes, you can just check whether that same user has already voted.
>
> Anthony
>
> On Wednesday, May 15, 2013 10:10:44 AM UTC-4, sasogeek wrote:
>>
>> the book states this "although it is easy to change this behavior if 
>> visitors are authenticated, by keeping track of the individual votes in the 
>> database and associating them with therequest.env.remote_addr of the 
>> voter." at this link 
>> http://web2py.com/books/default/chapter/29/11#Voting-and-rating
>>
>> How do I do that? I don't understand... but I need that feature. The app 
>> I'm building with it is already live though. feel free to check it out if 
>> you want :)
>> http://sasogeek.pythonanywhere.com/uRate/default/index.html . However, I 
>> really need the help! thanks
>>
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to