Exemplo n.º 1
0
Arquivo: views.py Projeto: daonb/okqa
def upvote_question(request, q_id):
    if request.user.is_anonymous():
        messages.error(
            request, _('Sorry but only connected users can upvote questions'))
        return HttpResponseRedirect(settings.LOGIN_URL)

    if request.method == "POST":
        q = get_object_or_404(Question, id=q_id)
        user = request.user
        if q.entity != user.profile.locality:
            return HttpResponseForbidden(
                _('You may only support questions in your locality'))
        if q.author == user:
            return HttpResponseForbidden(
                _("You may not support your own question"))
        if user.upvotes.filter(question=q):
            return HttpResponseForbidden(
                _("You already upvoted this question"))
        else:
            upvote = QuestionUpvote.objects.create(question=q, user=user)
            #TODO: use signals so the next line won't be necesary
            new_count = change_rating(q, 1)
            follow(request.user, q)

            publish_upvote_to_facebook.delay(upvote)
            return HttpResponse(new_count)
    else:
        return HttpResponseForbidden(_("Use POST to upvote a question"))
Exemplo n.º 2
0
def upvote_question(request, q_id):
    if request.method == "POST":
        q = get_object_or_404(Question, id=q_id)
        user = request.user
        if q.author == user or user.upvotes.filter(question=q):
            return HttpResponseForbidden(_("You already upvoted this question"))
        else:
            upvote = QuestionUpvote.objects.create(question=q, user=user)
            #TODO: use signals so the next line won't be necesary
            new_count = increase_rating(q)
            publish_upvote_to_facebook.delay(upvote)
            return HttpResponse(new_count)
    else:
        return HttpResponseForbidden(_("Use POST to upvote a question"))
Exemplo n.º 3
0
def upvote_question(request, q_id):
    if request.method == "POST":
        q = get_object_or_404(Question, id=q_id)
        user = request.user
        if q.author == user or user.upvotes.filter(question=q):
            return HttpResponseForbidden(
                _("You already upvoted this question"))
        else:
            upvote = QuestionUpvote.objects.create(question=q, user=user)
            #TODO: use signals so the next line won't be necesary
            new_count = increase_rating(q)
            publish_upvote_to_facebook.delay(upvote)
            return HttpResponse(new_count)
    else:
        return HttpResponseForbidden(_("Use POST to upvote a question"))
Exemplo n.º 4
0
Arquivo: views.py Projeto: daonb/okqa
def upvote_question(request, q_id):
    if request.user.is_anonymous():
        messages.error(request, _('Sorry but only connected users can upvote questions'))
        return HttpResponseRedirect(settings.LOGIN_URL)

    if request.method == "POST":
        q = get_object_or_404(Question, id=q_id)
        user = request.user
        if q.entity != user.profile.locality:
            return HttpResponseForbidden(_('You may only support questions in your locality'))
        if q.author == user:
            return HttpResponseForbidden(_("You may not support your own question"))
        if user.upvotes.filter(question=q):
            return HttpResponseForbidden(_("You already upvoted this question"))
        else:
            upvote = QuestionUpvote.objects.create(question=q, user=user)
            #TODO: use signals so the next line won't be necesary
            new_count = change_rating(q, 1)
            follow(request.user, q)

            publish_upvote_to_facebook.delay(upvote)
            return HttpResponse(new_count)
    else:
        return HttpResponseForbidden(_("Use POST to upvote a question"))