Exemplo n.º 1
0
def ajaxupdownvote(request, post_id, updown):
    post = get_object_or_404(VotablePost.objects, pk=post_id)
    user = request.user
    previous_vote = post.userHasUpdownvoted(user)

    ## user has already voted: remove it
    if previous_vote != None:
        vote = post.updownvoteFromUser(user)
        vote.disable()
    
    ## requested updownvote on previous_vote ==> cancels vote
    if previous_vote == updown:
        pass
    
    ## cast new vote
    else:
        # check if upvote is allowed
        if not post.userCanUpdownvote(user):
            return HttpResponse(content=post.upvote_score, mimetype='text/plain')
        # create updownvote
        vote = UpDownVote(
            user = user,
            post = post,
            value = (-1 if updown=="down" else 1),
        )
        vote.save()
        # add event
        UpDownVoteEvent.new_event_and_create_listeners_and_email_queue_entries(updownvote=vote)

    return HttpResponse(content=post.upvote_score, mimetype='text/plain')
Exemplo n.º 2
0
def ajaxendorse(request, proposal_slug):
    proposal = get_object_or_404(Proposal.objects, slug=proposal_slug)
    user = request.user

    ## disable if UpDownVote already exists
    if proposal.userHasUpdownvoted(user) != None:
        vote = proposal.updownvoteFromUser(user)
        vote.disable()
        return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
    
    ## check if upvote is allowed
    if not proposal.userCanUpdownvote(user):
        return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
    
    ## create updownvote
    vote = UpDownVote(
        user = user,
        post = proposal,
        value = 1,
    )
    vote.save()
    # add event
    UpDownVoteEvent.new_event_and_create_listeners_and_email_queue_entries(updownvote=vote)

    return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
Exemplo n.º 3
0
def ajaxupdownvote(request, post_id, updown):
    post = get_object_or_404(VotablePost.objects, pk=post_id)
    user = request.user
    previous_vote = post.userHasUpdownvoted(user)

    ## user has already voted: remove it
    if previous_vote != None:
        vote = post.updownvoteFromUser(user)
        vote.disable()

    ## requested updownvote on previous_vote ==> cancels vote
    if previous_vote == updown:
        pass

    ## cast new vote
    else:
        # check if upvote is allowed
        if not post.userCanUpdownvote(user):
            return HttpResponse(content=post.upvote_score,
                                mimetype='text/plain')
        # create updownvote
        vote = UpDownVote(
            user=user,
            post=post,
            value=(-1 if updown == "down" else 1),
        )
        vote.save()
        # add event
        UpDownVoteEvent.new_event_and_create_listeners_and_email_queue_entries(
            updownvote=vote)

    return HttpResponse(content=post.upvote_score, mimetype='text/plain')
Exemplo n.º 4
0
def ajaxendorse(request, proposal_slug):
    proposal = get_object_or_404(Proposal.objects, slug=proposal_slug)
    user = request.user

    ## disable if UpDownVote already exists
    if proposal.userHasUpdownvoted(user) != None:
        vote = proposal.updownvoteFromUser(user)
        vote.disable()
        return HttpResponse(content=proposal.upvote_score,
                            mimetype='text/plain')

    ## check if upvote is allowed
    if not proposal.userCanUpdownvote(user):
        return HttpResponse(content=proposal.upvote_score,
                            mimetype='text/plain')

    ## create updownvote
    vote = UpDownVote(
        user=user,
        post=proposal,
        value=1,
    )
    vote.save()
    # add event
    UpDownVoteEvent.new_event_and_create_listeners_and_email_queue_entries(
        updownvote=vote)

    return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
Exemplo n.º 5
0
def ajaxendorse(request, proposal_slug):
    proposal = get_object_or_404(Proposal.objects, slug=proposal_slug)
    user = request.user
    if proposal.userHasUpdownvoted(user) != None:
        vote = proposal.updownvoteFromUser(user)
        vote.disable()
        return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
    # check if upvote is allowed
    if not proposal.userCanUpdownvote(user):
        return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
    # create updownvote
    vote = UpDownVote(
        user = user,
        post = proposal,
        value = 1,
    )
    vote.save()
    return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')
Exemplo n.º 6
0
def ajaxendorse(request, proposal_slug):
    proposal = get_object_or_404(Proposal, slug=proposal_slug)
    user = request.user
    if proposal.userHasUpdownvoted(user) != None:
        vote = proposal.updownvoteFromUser(user)
        vote.delete()
        return HttpResponse(content=proposal.upvote_score,
                            mimetype='text/plain')
    # check if upvote is allowed
    if not proposal.userCanUpdownvote(user):
        return HttpResponse(content=proposal.upvote_score,
                            mimetype='text/plain')
    # create updownvote
    vote = UpDownVote(
        user=user,
        post=proposal,
        value=1,
    )
    vote.save()
    return HttpResponse(content=proposal.upvote_score, mimetype='text/plain')