Ejemplo n.º 1
0
def vote(request, comment_id, vote):
    """
    Rate a comment (+1 or -1)

    Templates: `karma_vote_accepted`
    Context:
        comment
            `comments.comments` object being rated
    """
    rating = {'up': 1, 'down': -1}.get(vote, False)
    if not rating:
        raise Http404, "Invalid vote"
    if request.user.is_anonymous():
        raise Http404, "Anonymous users cannot vote"
    try:
        comment = comments.get_object(pk=comment_id)
    except comments.CommentDoesNotExist:
        raise Http404, "Invalid comment ID"
    if comment.user_id == request.user.id:
        raise Http404, "No voting for yourself"
    karma.vote(request.user.id, comment_id, rating)
    # Reload comment to ensure we have up to date karma count
    comment = comments.get_object(pk=comment_id)
    return render_to_response('comments/karma_vote_accepted', {'comment': comment}, context_instance=DjangoContext(request))
Ejemplo n.º 2
0
def flag(request, comment_id):
    """
    Flags a comment. Confirmation on GET, action on POST.

    Templates: `comments/flag_verify`, `comments/flag_done`
    Context:
        comment
            the flagged `comments.comments` object
    """
    try:
        comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
    except comments.CommentDoesNotExist:
        raise Http404
    if request.POST:
        userflags.flag(comment, request.user)
        return HttpResponseRedirect('%sdone/' % request.path)
    return render_to_response('comments/flag_verify', {'comment': comment}, context_instance=DjangoContext(request))
Ejemplo n.º 3
0
def delete(request, comment_id):
    """
    Deletes a comment. Confirmation on GET, action on POST.

    Templates: `comments/delete_verify`, `comments/delete_done`
    Context:
        comment
            the flagged `comments.comments` object
    """
    try:
        comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
    except comments.CommentDoesNotExist:
        raise Http404
    if not comments.user_is_moderator(request.user):
        raise Http404
    if request.POST:
        # If the comment has already been removed, silently fail.
        if not comment.is_removed:
            comment.is_removed = True
            comment.save()
            m = moderatordeletions.ModeratorDeletion(None, request.user.id, comment.id, None)
            m.save()
        return HttpResponseRedirect('%sdone/' % request.path)
    return render_to_response('comments/delete_verify', {'comment': comment}, context_instance=DjangoContext(request))
Ejemplo n.º 4
0
def delete_done(request, comment_id):
    try:
        comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
    except comments.CommentDoesNotExist:
        raise Http404
    return render_to_response('comments/delete_done', {'comment': comment}, context_instance=DjangoContext(request))