Exemplo n.º 1
0
    def upvote(self, Request, Session):
        id = Request.param('id')
        votes = Vote.where('question_id', id).where('user_id',
                                                    Request.user().id).get()
        if votes.count() > 0:
            vote = votes.last()
            vote.value += 1
            if vote.value > 1:
                Session.flash('warning', 'Question already voted!')
            else:
                vote.save()
            return Request.redirect('/questions/@id', {'id': id})

        Vote.create(value=1, question_id=id, user_id=Request.user().id)
        return Request.redirect('/questions/@id', {'id': id})
Exemplo n.º 2
0
    def votes(self, id):
        # vote = Vote.where('question_id', id).last()
        # print(vote)
        votes = Vote.where('question_id', id).get()
        if votes.count() > 0:
            return votes.last().value

        return 0