mirror of https://github.com/django/django.git
Fixed #3091 -- django.contrib.comments views now accept extra_context and context_processors arguments. Thanks, Eric Floehr and __hawkeye__
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6236 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ca9388cdaf
commit
03652c7f2b
|
@ -155,7 +155,7 @@ class PublicFreeCommentManipulator(oldforms.Manipulator):
|
||||||
c.save()
|
c.save()
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def post_comment(request):
|
def post_comment(request, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Post a comment
|
Post a comment
|
||||||
|
|
||||||
|
@ -185,6 +185,7 @@ def post_comment(request):
|
||||||
rating_choices
|
rating_choices
|
||||||
choice of ratings
|
choice of ratings
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
if not request.POST:
|
if not request.POST:
|
||||||
raise Http404, _("Only POSTs are allowed")
|
raise Http404, _("Only POSTs are allowed")
|
||||||
try:
|
try:
|
||||||
|
@ -244,7 +245,7 @@ def post_comment(request):
|
||||||
'ratings_required': RATINGS_REQUIRED in option_list,
|
'ratings_required': RATINGS_REQUIRED in option_list,
|
||||||
'rating_range': rating_range,
|
'rating_range': rating_range,
|
||||||
'rating_choices': rating_choices,
|
'rating_choices': rating_choices,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
elif 'post' in request.POST:
|
elif 'post' in request.POST:
|
||||||
# If the IP is banned, mail the admins, do NOT save the comment, and
|
# If the IP is banned, mail the admins, do NOT save the comment, and
|
||||||
# serve up the "Thanks for posting" page as if the comment WAS posted.
|
# serve up the "Thanks for posting" page as if the comment WAS posted.
|
||||||
|
@ -257,7 +258,7 @@ def post_comment(request):
|
||||||
else:
|
else:
|
||||||
raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
|
raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
|
||||||
|
|
||||||
def post_free_comment(request):
|
def post_free_comment(request, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Post a free comment (not requiring a log in)
|
Post a free comment (not requiring a log in)
|
||||||
|
|
||||||
|
@ -277,6 +278,7 @@ def post_free_comment(request):
|
||||||
security hash (must be included in a posted form to succesfully
|
security hash (must be included in a posted form to succesfully
|
||||||
post a comment).
|
post a comment).
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
if not request.POST:
|
if not request.POST:
|
||||||
raise Http404, _("Only POSTs are allowed")
|
raise Http404, _("Only POSTs are allowed")
|
||||||
try:
|
try:
|
||||||
|
@ -307,7 +309,7 @@ def post_free_comment(request):
|
||||||
'options': options,
|
'options': options,
|
||||||
'target': target,
|
'target': target,
|
||||||
'hash': security_hash,
|
'hash': security_hash,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
elif 'post' in request.POST:
|
elif 'post' in request.POST:
|
||||||
# If the IP is banned, mail the admins, do NOT save the comment, and
|
# If the IP is banned, mail the admins, do NOT save the comment, and
|
||||||
# serve up the "Thanks for posting" page as if the comment WAS posted.
|
# serve up the "Thanks for posting" page as if the comment WAS posted.
|
||||||
|
@ -321,7 +323,7 @@ def post_free_comment(request):
|
||||||
else:
|
else:
|
||||||
raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
|
raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
|
||||||
|
|
||||||
def comment_was_posted(request):
|
def comment_was_posted(request, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Display "comment was posted" success page
|
Display "comment was posted" success page
|
||||||
|
|
||||||
|
@ -330,6 +332,7 @@ def comment_was_posted(request):
|
||||||
object
|
object
|
||||||
The object the comment was posted on
|
The object the comment was posted on
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
obj = None
|
obj = None
|
||||||
if 'c' in request.GET:
|
if 'c' in request.GET:
|
||||||
content_type_id, object_id = request.GET['c'].split(':')
|
content_type_id, object_id = request.GET['c'].split(':')
|
||||||
|
@ -338,4 +341,5 @@ def comment_was_posted(request):
|
||||||
obj = content_type.get_object_for_this_type(pk=object_id)
|
obj = content_type.get_object_for_this_type(pk=object_id)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
return render_to_response('comments/posted.html', {'object': obj}, context_instance=RequestContext(request))
|
return render_to_response('comments/posted.html', {'object': obj},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.template import RequestContext
|
||||||
from django.contrib.comments.models import Comment, KarmaScore
|
from django.contrib.comments.models import Comment, KarmaScore
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
def vote(request, comment_id, vote):
|
def vote(request, comment_id, vote, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Rate a comment (+1 or -1)
|
Rate a comment (+1 or -1)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ def vote(request, comment_id, vote):
|
||||||
comment
|
comment
|
||||||
`comments.comments` object being rated
|
`comments.comments` object being rated
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
rating = {'up': 1, 'down': -1}.get(vote, False)
|
rating = {'up': 1, 'down': -1}.get(vote, False)
|
||||||
if not rating:
|
if not rating:
|
||||||
raise Http404, "Invalid vote"
|
raise Http404, "Invalid vote"
|
||||||
|
@ -27,4 +28,5 @@ def vote(request, comment_id, vote):
|
||||||
KarmaScore.objects.vote(request.user.id, comment_id, rating)
|
KarmaScore.objects.vote(request.user.id, comment_id, rating)
|
||||||
# Reload comment to ensure we have up to date karma count
|
# Reload comment to ensure we have up to date karma count
|
||||||
comment = Comment.objects.get(pk=comment_id)
|
comment = Comment.objects.get(pk=comment_id)
|
||||||
return render_to_response('comments/karma_vote_accepted.html', {'comment': comment}, context_instance=RequestContext(request))
|
return render_to_response('comments/karma_vote_accepted.html', {'comment': comment},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
def flag(request, comment_id):
|
def flag(request, comment_id, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Flags a comment. Confirmation on GET, action on POST.
|
Flags a comment. Confirmation on GET, action on POST.
|
||||||
|
|
||||||
|
@ -15,18 +15,22 @@ def flag(request, comment_id):
|
||||||
comment
|
comment
|
||||||
the flagged `comments.comments` object
|
the flagged `comments.comments` object
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
||||||
if request.POST:
|
if request.POST:
|
||||||
UserFlag.objects.flag(comment, request.user)
|
UserFlag.objects.flag(comment, request.user)
|
||||||
return HttpResponseRedirect('%sdone/' % request.path)
|
return HttpResponseRedirect('%sdone/' % request.path)
|
||||||
return render_to_response('comments/flag_verify.html', {'comment': comment}, context_instance=RequestContext(request))
|
return render_to_response('comments/flag_verify.html', {'comment': comment},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
flag = login_required(flag)
|
flag = login_required(flag)
|
||||||
|
|
||||||
def flag_done(request, comment_id):
|
def flag_done(request, comment_id, extra_context=None, context_processors=None):
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
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))
|
return render_to_response('comments/flag_done.html', {'comment': comment},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
|
|
||||||
def delete(request, comment_id):
|
def delete(request, comment_id, extra_context=None, context_processors=None):
|
||||||
"""
|
"""
|
||||||
Deletes a comment. Confirmation on GET, action on POST.
|
Deletes a comment. Confirmation on GET, action on POST.
|
||||||
|
|
||||||
|
@ -35,6 +39,7 @@ def delete(request, comment_id):
|
||||||
comment
|
comment
|
||||||
the flagged `comments.comments` object
|
the flagged `comments.comments` object
|
||||||
"""
|
"""
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
||||||
if not Comment.objects.user_is_moderator(request.user):
|
if not Comment.objects.user_is_moderator(request.user):
|
||||||
raise Http404
|
raise Http404
|
||||||
|
@ -46,9 +51,12 @@ def delete(request, comment_id):
|
||||||
m = ModeratorDeletion(None, request.user.id, comment.id, None)
|
m = ModeratorDeletion(None, request.user.id, comment.id, None)
|
||||||
m.save()
|
m.save()
|
||||||
return HttpResponseRedirect('%sdone/' % request.path)
|
return HttpResponseRedirect('%sdone/' % request.path)
|
||||||
return render_to_response('comments/delete_verify.html', {'comment': comment}, context_instance=RequestContext(request))
|
return render_to_response('comments/delete_verify.html', {'comment': comment},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
delete = login_required(delete)
|
delete = login_required(delete)
|
||||||
|
|
||||||
def delete_done(request, comment_id):
|
def delete_done(request, comment_id, extra_context=None, context_processors=None):
|
||||||
|
if extra_context is None: extra_context = {}
|
||||||
comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
|
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))
|
return render_to_response('comments/delete_done.html', {'comment': comment},
|
||||||
|
context_instance=RequestContext(request, extra_context, context_processors))
|
||||||
|
|
Loading…
Reference in New Issue