Ticket #12241: preserve_query_string_with_tests.diff
File preserve_query_string_with_tests.diff, 4.1 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/options.py
634 634 "admin/change_form.html" 635 635 ], context, context_instance=context_instance) 636 636 637 def handle_continue_redirect(self, request, url_continue, msg): 638 self.message_user(request, msg + ' ' + _("You may edit it again below.")) 639 if request.POST.has_key("_popup"): 640 url_continue += ("?_popup=1" + request.META.get('QUERY_STRING')) 641 else: 642 url_continue += ("?" + request.META.get('QUERY_STRING')) 643 return url_continue 644 637 645 def response_add(self, request, obj, post_url_continue='../%s/'): 638 646 """ 639 647 Determines the HttpResponse for the add_view stage. … … 645 653 # Here, we distinguish between different save types by checking for 646 654 # the presence of keys in request.POST. 647 655 if request.POST.has_key("_continue"): 648 self.message_user(request, msg + ' ' + _("You may edit it again below.")) 649 if request.POST.has_key("_popup"): 650 post_url_continue += "?_popup=1" 651 return HttpResponseRedirect(post_url_continue % pk_value) 656 url = self.handle_continue_redirect(request, post_url_continue, msg) 657 return HttpResponseRedirect(url % pk_value) 652 658 653 659 if request.POST.has_key("_popup"): 654 660 return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \ … … 678 684 679 685 msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)} 680 686 if request.POST.has_key("_continue"): 681 self.message_user(request, msg + ' ' + _("You may edit it again below.")) 682 if request.REQUEST.has_key('_popup'): 683 return HttpResponseRedirect(request.path + "?_popup=1") 684 else: 685 return HttpResponseRedirect(request.path) 687 url = self.handle_continue_redirect(request, request.path, msg) 688 return HttpResponseRedirect(url) 686 689 elif request.POST.has_key("_saveasnew"): 687 690 msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj} 688 691 self.message_user(request, msg) -
tests/regressiontests/admin_views/tests.py
1513 1513 else: 1514 1514 self.assertEqual(response.status_code, 404) 1515 1515 1516 class AdminResponseChangeTest(TestCase): 1517 fixtures = ['admin-views-users.xml'] 1518 1519 def setUp(self): 1520 self.client.login(username='super', password='secret') 1521 self.data = {'title':"I Could Go Anywhere", 'content':"Versatile", 'date':datetime.datetime.now()} 1522 article = Article.objects.create(**self.data) 1523 self.pk = article.id 1524 1525 def test_response_change(self): 1526 """Regression test for #12241: ModelAdmin.response_change and 1527 ModelAdmin.response_add should preserve the request 1528 query string after the redirection if the "save and continue" button 1529 is used within the admin.""" 1530 self.data['_continue'] = True 1531 self.data['date_0'] = u"2008-03-18" 1532 self.data['date_1'] = u"11:54:58" 1533 response = self.client.post('/test_admin/admin/admin_views/article/%d/?test=1' % self.pk, self.data) 1534 self.assertEqual(response.status_code, 302) 1535 self.assertTrue("?test=1" in response['Location']) 1536 response = self.client.post('/test_admin/admin/admin_views/article/add/?test=1', self.data) 1537 self.assertEqual(response.status_code, 302) 1538 self.assertTrue("?test=1" in response['Location']) 1539 1540 1516 1541 class AdminInlineFileUploadTest(TestCase): 1517 1542 fixtures = ['admin-views-users.xml', 'admin-views-actions.xml'] 1518 1543 urlbit = 'admin'