<s> from django import template <EOL> from django . conf import settings <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . contrib . auth . decorators import login_required , permission_required <EOL> from utils import next_redirect , confirmation_view <EOL> from django . contrib import comments <EOL> from django . contrib . comments import signals <EOL> from django . views . decorators . csrf import csrf_protect <EOL> @ csrf_protect <EOL> @ login_required <EOL> def flag ( request , comment_id , next = None ) : <EOL> """<STR_LIT>""" <EOL> comment = get_object_or_404 ( comments . get_model ( ) , pk = comment_id , site__pk = settings . SITE_ID ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> perform_flag ( request , comment ) <EOL> return next_redirect ( request . POST . copy ( ) , next , flag_done , c = comment . pk ) <EOL> else : <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : comment , "<STR_LIT>" : next } , <EOL> template . RequestContext ( request ) <EOL> ) <EOL> @ csrf_protect <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def delete ( request , comment_id , next = None ) : <EOL> """<STR_LIT>""" <EOL> comment = get_object_or_404 ( comments . get_model ( ) , pk = comment_id , site__pk = settings . SITE_ID ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> perform_delete ( request , comment ) <EOL> return next_redirect ( request . POST . copy ( ) , next , delete_done , c = comment . pk ) <EOL> else : <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : comment , "<STR_LIT>" : next } , <EOL> template . RequestContext ( request ) <EOL> ) <EOL> @ csrf_protect <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def approve ( request , comment_id , next = None ) : <EOL> """<STR_LIT>""" <EOL> comment = get_object_or_404 ( comments . get_model ( ) , pk = comment_id , site__pk = settings . SITE_ID ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> perform_approve ( request , comment ) <EOL> return next_redirect ( request . POST . copy ( ) , next , approve_done , c = comment . pk ) <EOL> else : <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : comment , "<STR_LIT>" : next } , <EOL> template . RequestContext ( request ) <EOL> ) <EOL> def perform_flag ( request , comment ) : <EOL> """<STR_LIT>""" <EOL> flag , created = comments . models . CommentFlag . objects . get_or_create ( <EOL> comment = comment , <EOL> user = request . user , <EOL> flag = comments . models . CommentFlag . SUGGEST_REMOVAL <EOL> ) <EOL> signals . comment_was_flagged . send ( <EOL> sender = comment . __class__ , <EOL> comment = comment , <EOL> flag = flag , <EOL> created = created , <EOL> request = request , <EOL> ) <EOL> def perform_delete ( request , comment ) : <EOL> flag , created = comments . models . CommentFlag . objects . get_or_create ( <EOL> comment = comment , <EOL> user = request . user , <EOL> flag = comments . models . CommentFlag . MODERATOR_DELETION <EOL> ) <EOL> comment . is_removed = True <EOL> comment . save ( ) <EOL> signals . comment_was_flagged . send ( <EOL> sender = comment . __class__ , <EOL> comment = comment , <EOL> flag = flag , <EOL> created = created , <EOL> request = request , <EOL> ) <EOL> def perform_approve ( request , comment ) : <EOL> flag , created = comments . models . CommentFlag . objects . get_or_create ( <EOL> comment = comment , <EOL> user = request . user , <EOL> flag = comments . models . CommentFlag . MODERATOR_APPROVAL , <EOL> ) <EOL> comment . is_removed = False <EOL> comment . is_public = True <EOL> comment . save ( ) <EOL> signals . comment_was_flagged . send ( <EOL> sender = comment . __class__ , <EOL> comment = comment , <EOL> flag = flag , <EOL> created = created , <EOL> request = request , <EOL> ) <EOL> flag_done = confirmation_view ( <EOL> template = "<STR_LIT>" , <EOL> doc = '<STR_LIT>' <EOL> ) <EOL> delete_done = confirmation_view ( <EOL> template = "<STR_LIT>" , <EOL> doc = '<STR_LIT>' <EOL> ) <EOL> approve_done = confirmation_view ( <EOL> template = "<STR_LIT>" , <EOL> doc = '<STR_LIT>' <EOL> ) </s>
