Ticket #8968: fix_8968_v5.patch

File fix_8968_v5.patch, 6.7 KB (added by kkubasik, 6 years ago)
  • django/contrib/comments/views/moderation.py

    diff --git a/django/contrib/comments/views/moderation.py b/django/contrib/comments/views/moderation.py
    index 3334b09..5a4e8b6 100644
    a b def flag(request, comment_id, next=None): 
    3434            created = created,
    3535            request = request,
    3636        )
     37        if request.POST.has_key('next'):
     38            next = request.POST.get('next')
     39        elif request.GET.has_key('next'):
     40            next = request.GET.get('next')
    3741        return next_redirect(request.POST.copy(), next, flag_done, c=comment.pk)
    3842
    3943    # Render a form on GET
    4044    else:
     45        next = request.GET.get('next', next)
    4146        return render_to_response('comments/flag.html',
    4247            {'comment': comment, "next": next},
    4348            template.RequestContext(request)
    def delete(request, comment_id, next=None): 
    7479            created = created,
    7580            request = request,
    7681        )
     82        if request.POST.has_key('next'):
     83            next = request.POST.get('next')
     84        elif request.GET.has_key('next'):
     85            next = request.GET.get('next')
    7786        return next_redirect(request.POST.copy(), next, delete_done, c=comment.pk)
    7887
    7988    # Render a form on GET
    8089    else:
     90        next = request.GET.get('next', next)
    8191        return render_to_response('comments/delete.html',
    8292            {'comment': comment, "next": next},
    8393            template.RequestContext(request)
    def approve(request, comment_id, next=None): 
    117127            created = created,
    118128            request = request,
    119129        )
     130        if request.POST.has_key('next'):
     131            next = request.POST.get('next')
     132        elif request.GET.has_key('next'):
     133            next = request.GET.get('next')
    120134        return next_redirect(request.POST.copy(), next, approve_done, c=comment.pk)
    121135
    122136    # Render a form on GET
    123137    else:
     138        next = request.GET.get('next', next)
    124139        return render_to_response('comments/approve.html',
    125140            {'comment': comment, "next": next},
    126141            template.RequestContext(request)
  • docs/ref/contrib/comments/index.txt

    diff --git a/docs/ref/contrib/comments/index.txt b/docs/ref/contrib/comments/index.txt
    index f6e1553..4bfedcd 100644
    a b you can include a hidden form input called ``next`` in your comment form. For ex 
    188188
    189189    <input type="hidden" name="next" value="{% url my_comment_was_posted %}" />
    190190
     191The ``next`` parameter can be passed into the comment system in a variety of ways,
     192but POST will always be preferred over GET and the named parameter is always overridden.
     193
     194A ``next`` parameter can be specified in ``urls.py`` with the following line::
     195
     196    (r'^flag/(\d+)/$', flag, {'next': '/I/am/done/'})
     197
    191198.. _notes-on-the-comment-form:
    192199
    193200Notes on the comment form
  • tests/regressiontests/comment_tests/tests/moderation_view_tests.py

    diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py
    index b9eadd7..91055ca 100644
    a b from django.contrib.auth.models import User, Permission 
    33from django.contrib.contenttypes.models import ContentType
    44from regressiontests.comment_tests.tests import CommentTestCase
    55from django.contrib.comments import signals
    6 
     6from django.contrib.comments.views.moderation import delete
     7import re
    78class FlagViewTests(CommentTestCase):
    89
    910    def testFlagGet(self):
    class DeleteViewTests(CommentTestCase): 
    9293        self.client.login(username="normaluser", password="normaluser")
    9394        response = self.client.post("/delete/%d/" % pk)
    9495        self.assertEqual(response["Location"], "http://testserver/deleted/?c=%d" % pk)
     96
     97        response = self.client.post("/delete/%d/" % pk, {"next": "/somewhere/else/"})
     98        location = response["Location"]
     99        match = re.search(r"^http://testserver/somewhere/else/\?c=\d+$", location)
     100        self.failUnless(match != None, "Unexpected redirect location: %s" % location)
    95101        c = Comment.objects.get(pk=pk)
    96102        self.failUnless(c.is_removed)
    97103        self.assertEqual(c.flags.filter(flag=CommentFlag.MODERATOR_DELETION, user__username="normaluser").count(), 1)
    class DeleteViewTests(CommentTestCase): 
    106112
    107113        # Post a comment and check the signals
    108114        self.testDeletePost()
    109         self.assertEqual(received_signals, [signals.comment_was_flagged])
     115        self.assertEqual(received_signals, [signals.comment_was_flagged, signals.comment_was_flagged])
    110116
    111117    def testDeletedView(self):
    112118        comments = self.createSomeComments()
    class DeleteViewTests(CommentTestCase): 
    114120        response = self.client.get("/deleted/", data={"c":pk})
    115121        self.assertTemplateUsed(response, "comments/deleted.html")
    116122
     123    def testDeletedViewNextGet(self):
     124        comments = self.createSomeComments()
     125        pk = comments[0].pk
     126        makeModerator("normaluser")
     127        self.client.login(username="normaluser", password="normaluser")
     128        response = self.client.get("/delete/%d/" % pk, data={"next": "/somewhere/else"})
     129        self.assertEqual(response.context[1]['next'], "/somewhere/else")
     130        self.assertTemplateUsed(response, "comments/delete.html")
     131
     132    def testDeletedViewNextGetPost(self):
     133        comments = self.createSomeComments()
     134        pk = comments[0].pk
     135        makeModerator("normaluser")
     136        self.client.login(username="normaluser", password="normaluser")
     137        response = self.client.post("/delete/%d/?next=/somewhere/else" % pk, data={"next": "/somewhere/new"})
     138        location = response["Location"]
     139        match = re.search(r"^http://testserver/somewhere/new\?c=\d+$", location)
     140        self.failUnless(match != None, "Unexpected redirect location: %s" % location)
     141
     142
    117143class ApproveViewTests(CommentTestCase):
    118144
    119145    def testApprovePermissions(self):
    class ApproveViewTests(CommentTestCase): 
    131157    def testApprovePost(self):
    132158        """POSTing the delete view should mark the comment as removed"""
    133159        c1, c2, c3, c4 = self.createSomeComments()
    134         c1.is_public = False; c1.save()
     160        c1.is_public = False
     161        c1.save()
    135162
    136163        makeModerator("normaluser")
    137164        self.client.login(username="normaluser", password="normaluser")
    class ModerationQueueTests(CommentTestCase): 
    179206        self.client.login(username="normaluser", password="normaluser")
    180207
    181208        c1.is_public = c2.is_public = False
    182         c1.save(); c2.save()
     209        c1.save()
     210        c2.save()
    183211        response = self.client.get("/moderate/")
    184212        self.assertEqual(list(response.context[0]["comments"]), [c1, c2])
    185213
Back to Top