Ticket #1659: userflags.2.diff
File userflags.2.diff, 3.6 KB (added by , 19 years ago) |
---|
-
userflags.py
1 1 from django.shortcuts import render_to_response 2 2 from django.template import RequestContext 3 3 from django.http import Http404 4 from django. models.comments import comments, moderatordeletions, userflags4 from django.contrib.comments.models import Comment, ModeratorDeletion, UserFlag 5 5 from django.contrib.auth.decorators import login_required 6 6 from django.http import HttpResponseRedirect 7 7 from django.conf import settings … … 16 16 the flagged `comments.comments` object 17 17 """ 18 18 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: 21 21 raise Http404 22 22 if request.POST: 23 userflags.flag(comment, request.user)23 UserFlag.flag(comment, request.user) 24 24 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)) 26 26 flag = login_required(flag) 27 27 28 28 def flag_done(request, comment_id): 29 29 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: 32 32 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)) 34 34 35 35 def delete(request, comment_id): 36 36 """ … … 42 42 the flagged `comments.comments` object 43 43 """ 44 44 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: 47 47 raise Http404 48 if not comments.user_is_moderator(request.user):48 if not Comment.objects.user_is_moderator(request.user): 49 49 raise Http404 50 50 if request.POST: 51 51 # If the comment has already been removed, silently fail. 52 52 if not comment.is_removed: 53 53 comment.is_removed = True 54 54 comment.save() 55 m = moderatordeletions.ModeratorDeletion(None, request.user.id, comment.id, None)55 m = ModeratorDeletion(user=request.user, comment=comment) 56 56 m.save() 57 57 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)) 59 59 delete = login_required(delete) 60 60 61 61 def delete_done(request, comment_id): 62 62 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: 65 65 raise Http404 66 66 return render_to_response('comments/delete_done', {'comment': comment}, context_instance=RequestContext(request))