Ticket #3091: ticket_3091__rev_6186.diff

File ticket_3091__rev_6186.diff, 7.6 KB (added by __hawkeye__, 8 years ago)

All comment views now support 'extra_context' and 'context_processors' arguments.

  • django/contrib/comments/views/karma.py

     
    44from django.contrib.comments.models import Comment, KarmaScore
    55from django.utils.translation import ugettext as _
    66
    7 def vote(request, comment_id, vote):
     7def vote(request, comment_id, vote, extra_context=None, context_processors=None):
    88    """
    99    Rate a comment (+1 or -1)
    1010
     
    1313        comment
    1414            `comments.comments` object being rated
    1515    """
     16    if extra_context is None: extra_context = {}
    1617    rating = {'up': 1, 'down': -1}.get(vote, False)
    1718    if not rating:
    1819        raise Http404, "Invalid vote"
     
    2728    KarmaScore.objects.vote(request.user.id, comment_id, rating)
    2829    # Reload comment to ensure we have up to date karma count
    2930    comment = Comment.objects.get(pk=comment_id)
    30     return render_to_response('comments/karma_vote_accepted.html', {'comment': comment}, context_instance=RequestContext(request))
     31    return render_to_response('comments/karma_vote_accepted.html', {'comment': comment},
     32        context_instance=RequestContext(request, extra_context, context_processors))
  • django/contrib/comments/views/userflags.py

     
    66from django.http import HttpResponseRedirect
    77from django.conf import settings
    88
    9 def flag(request, comment_id):
     9def flag(request, comment_id, extra_context=None, context_processors=None):
    1010    """
    1111    Flags a comment. Confirmation on GET, action on POST.
    1212
     
    1515        comment
    1616            the flagged `comments.comments` object
    1717    """
     18    if extra_context is None: extra_context = {}
    1819    comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
    1920    if request.POST:
    2021        UserFlag.objects.flag(comment, request.user)
    2122        return HttpResponseRedirect('%sdone/' % request.path)
    22     return render_to_response('comments/flag_verify.html', {'comment': comment}, context_instance=RequestContext(request))
     23    return render_to_response('comments/flag_verify.html', {'comment': comment},
     24        context_instance=RequestContext(request, extra_context, context_processors))
    2325flag = login_required(flag)
    2426
    25 def flag_done(request, comment_id):
     27def flag_done(request, comment_id, extra_context=None, context_processors=None):
     28    if extra_context is None: extra_context = {}
    2629    comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
    27     return render_to_response('comments/flag_done.html', {'comment': comment}, context_instance=RequestContext(request))
     30    return render_to_response('comments/flag_done.html', {'comment': comment},
     31        context_instance=RequestContext(request, extra_context, context_processors))
    2832
    29 def delete(request, comment_id):
     33def delete(request, comment_id, extra_context=None, context_processors=None):
    3034    """
    3135    Deletes a comment. Confirmation on GET, action on POST.
    3236
     
    3539        comment
    3640            the flagged `comments.comments` object
    3741    """
     42    if extra_context is None: extra_context = {}
    3843    comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
    3944    if not Comment.objects.user_is_moderator(request.user):
    4045        raise Http404
     
    4651            m = ModeratorDeletion(None, request.user.id, comment.id, None)
    4752            m.save()
    4853        return HttpResponseRedirect('%sdone/' % request.path)
    49     return render_to_response('comments/delete_verify.html', {'comment': comment}, context_instance=RequestContext(request))
     54    return render_to_response('comments/delete_verify.html', {'comment': comment},
     55        context_instance=RequestContext(request, extra_context, context_processors))
    5056delete = login_required(delete)
    5157
    52 def delete_done(request, comment_id):
     58def delete_done(request, comment_id, extra_context=None, context_processors=None):
     59    if extra_context is None: extra_context = {}
    5360    comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
    54     return render_to_response('comments/delete_done.html', {'comment': comment}, context_instance=RequestContext(request))
     61    return render_to_response('comments/delete_done.html', {'comment': comment},
     62        context_instance=RequestContext(request, extra_context, context_processors))
  • django/contrib/comments/views/comments.py

     
    155155        c.save()
    156156        return c
    157157
    158 def post_comment(request):
     158def post_comment(request, extra_context=None, context_processors=None):
    159159    """
    160160    Post a comment
    161161
     
    185185        rating_choices
    186186            choice of ratings
    187187    """
     188    if extra_context is None: extra_context = {}
    188189    if not request.POST:
    189190        raise Http404, _("Only POSTs are allowed")
    190191    try:
     
    244245            'ratings_required': RATINGS_REQUIRED in option_list,
    245246            'rating_range': rating_range,
    246247            'rating_choices': rating_choices,
    247         }, context_instance=RequestContext(request))
     248        }, context_instance=RequestContext(request, extra_context, context_processors))
    248249    elif 'post' in request.POST:
    249250        # If the IP is banned, mail the admins, do NOT save the comment, and
    250251        # serve up the "Thanks for posting" page as if the comment WAS posted.
     
    257258    else:
    258259        raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
    259260
    260 def post_free_comment(request):
     261def post_free_comment(request, extra_context=None, context_processors=None):
    261262    """
    262263    Post a free comment (not requiring a log in)
    263264
     
    277278            security hash (must be included in a posted form to succesfully
    278279            post a comment).
    279280    """
     281    if extra_context is None: extra_context = {}
    280282    if not request.POST:
    281283        raise Http404, _("Only POSTs are allowed")
    282284    try:
     
    307309            'options': options,
    308310            'target': target,
    309311            'hash': security_hash,
    310         }, context_instance=RequestContext(request))
     312        }, context_instance=RequestContext(request, extra_context, context_processors))
    311313    elif 'post' in request.POST:
    312314        # If the IP is banned, mail the admins, do NOT save the comment, and
    313315        # serve up the "Thanks for posting" page as if the comment WAS posted.
     
    321323    else:
    322324        raise Http404, _("The comment form didn't provide either 'preview' or 'post'")
    323325
    324 def comment_was_posted(request):
     326def comment_was_posted(request, extra_context=None, context_processors=None):
    325327    """
    326328    Display "comment was posted" success page
    327329
     
    330332        object
    331333            The object the comment was posted on
    332334    """
     335    if extra_context is None: extra_context = {}
    333336    obj = None
    334337    if 'c' in request.GET:
    335338        content_type_id, object_id = request.GET['c'].split(':')
     
    338341            obj = content_type.get_object_for_this_type(pk=object_id)
    339342        except ObjectDoesNotExist:
    340343            pass
    341     return render_to_response('comments/posted.html', {'object': obj}, context_instance=RequestContext(request))
     344    return render_to_response('comments/posted.html', {'object': obj},
     345        context_instance=RequestContext(request, extra_context, context_processors))
Back to Top