2006-05-02 09:31:56 +08:00
|
|
|
from django.shortcuts import render_to_response, get_object_or_404
|
|
|
|
from django.template import RequestContext
|
|
|
|
from django.http import Http404
|
|
|
|
from django.contrib.comments.models import Comment, ModeratorDeletion, UserFlag
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.conf import settings
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2006-05-02 09:31:56 +08:00
|
|
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
2005-07-13 09:25:57 +08:00
|
|
|
if request.POST:
|
2006-05-02 09:31:56 +08:00
|
|
|
UserFlag.objects.flag(comment, request.user)
|
2005-07-13 09:25:57 +08:00
|
|
|
return HttpResponseRedirect('%sdone/' % request.path)
|
2006-05-02 09:31:56 +08:00
|
|
|
return render_to_response('comments/flag_verify.html', {'comment': comment}, context_instance=RequestContext(request))
|
2005-07-13 09:25:57 +08:00
|
|
|
flag = login_required(flag)
|
|
|
|
|
|
|
|
def flag_done(request, comment_id):
|
2006-05-02 09:31:56 +08:00
|
|
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
|
|
|
return render_to_response('comments/flag_done.html', {'comment': comment}, context_instance=RequestContext(request))
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2006-05-02 09:31:56 +08:00
|
|
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
|
|
|
if not Comment.objects.user_is_moderator(request.user):
|
2005-07-13 09:25:57 +08:00
|
|
|
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()
|
2006-05-02 09:31:56 +08:00
|
|
|
m = ModeratorDeletion(None, request.user.id, comment.id, None)
|
2005-07-13 09:25:57 +08:00
|
|
|
m.save()
|
|
|
|
return HttpResponseRedirect('%sdone/' % request.path)
|
2006-05-02 09:31:56 +08:00
|
|
|
return render_to_response('comments/delete_verify.html', {'comment': comment}, context_instance=RequestContext(request))
|
2005-07-13 09:25:57 +08:00
|
|
|
delete = login_required(delete)
|
|
|
|
|
|
|
|
def delete_done(request, comment_id):
|
2006-05-02 09:31:56 +08:00
|
|
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
|
|
|
return render_to_response('comments/delete_done.html', {'comment': comment}, context_instance=RequestContext(request))
|