Ticket #1659: userflags.3.diff

File userflags.3.diff, 3.6 KB (added by ubernostrum, 9 years ago)

Pesky manager methods

  • userflags.py

     
    11from django.shortcuts import render_to_response
    22from django.template import RequestContext
    33from django.http import Http404
    4 from django.models.comments import comments, moderatordeletions, userflags
     4from django.contrib.comments.models import Comment, ModeratorDeletion, UserFlag
    55from django.contrib.auth.decorators import login_required
    66from django.http import HttpResponseRedirect
    77from django.conf import settings
     
    1616            the flagged `comments.comments` object
    1717    """
    1818    try:
    19         comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
    20     except comments.CommentDoesNotExist:
     19        comment = Comment.objects.get(pk=comment_id, site__id__exact=settings.SITE_ID)
     20    except Comment.DoesNotExist:
    2121        raise Http404
    2222    if request.POST:
    23         userflags.flag(comment, request.user)
     23        UserFlag.objects.flag(comment, request.user)
    2424        return HttpResponseRedirect('%sdone/' % request.path)
    25     return render_to_response('comments/flag_verify', {'comment': comment}, context_instance=RequestContext(request))
     25    return render_to_response('comments/flag_verify.html', {'comment': comment}, context_instance=RequestContext(request))
    2626flag = login_required(flag)
    2727
    2828def flag_done(request, comment_id):
    2929    try:
    30         comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
    31     except comments.CommentDoesNotExist:
     30        comment = Comment.objects.get(pk=comment_id, site__id__exact=settings.SITE_ID)
     31    except Comment.DoesNotExist:
    3232        raise Http404
    33     return render_to_response('comments/flag_done', {'comment': comment}, context_instance=RequestContext(request))
     33    return render_to_response('comments/flag_done.html', {'comment': comment}, context_instance=RequestContext(request))
    3434
    3535def delete(request, comment_id):
    3636    """
     
    4242            the flagged `comments.comments` object
    4343    """
    4444    try:
    45         comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
    46     except comments.CommentDoesNotExist:
     45        comment = Comment.objects.get(pk=comment_id, site__id__exact=settings.SITE_ID)
     46    except Comment.DoesNotExist:
    4747        raise Http404
    48     if not comments.user_is_moderator(request.user):
     48    if not Comment.objects.user_is_moderator(request.user):
    4949        raise Http404
    5050    if request.POST:
    5151        # If the comment has already been removed, silently fail.
    5252        if not comment.is_removed:
    5353            comment.is_removed = True
    5454            comment.save()
    55             m = moderatordeletions.ModeratorDeletion(None, request.user.id, comment.id, None)
     55            m = ModeratorDeletion(user=request.user, comment=comment)
    5656            m.save()
    5757        return HttpResponseRedirect('%sdone/' % request.path)
    58     return render_to_response('comments/delete_verify', {'comment': comment}, context_instance=RequestContext(request))
     58    return render_to_response('comments/delete_verify.html', {'comment': comment}, context_instance=RequestContext(request))
    5959delete = login_required(delete)
    6060
    6161def delete_done(request, comment_id):
    6262    try:
    63         comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID)
    64     except comments.CommentDoesNotExist:
     63        comment = Comment.objects.get(pk=comment_id, site__id__exact=settings.SITE_ID)
     64    except Comment.DoesNotExist:
    6565        raise Http404
    6666    return render_to_response('comments/delete_done', {'comment': comment}, context_instance=RequestContext(request))
Back to Top