Ticket #12241: keep_query_string_after_continue.diff

File keep_query_string_after_continue.diff, 2.3 KB (added by Batiste Bieler, 15 years ago)

Keep the request's query string when the button "Save and continue" or "Add and continue" are used.

  • django/contrib/admin/options.py

     
    589589            "admin/change_form.html"
    590590        ], context, context_instance=context_instance)
    591591
     592    def handle_continue_redirect(self, request, url_continue, msg):
     593        self.message_user(request, msg + ' ' + _("You may edit it again below."))
     594        if request.POST.has_key("_popup"):
     595            url_continue += ("?_popup=1" + request.META.get('QUERY_STRING'))
     596        else:
     597            url_continue += ("?" + request.META.get('QUERY_STRING'))
     598        return url_continue
     599
    592600    def response_add(self, request, obj, post_url_continue='../%s/'):
    593601        """
    594602        Determines the HttpResponse for the add_view stage.
     
    600608        # Here, we distinguish between different save types by checking for
    601609        # the presence of keys in request.POST.
    602610        if request.POST.has_key("_continue"):
    603             self.message_user(request, msg + ' ' + _("You may edit it again below."))
    604             if request.POST.has_key("_popup"):
    605                 post_url_continue += "?_popup=1"
     611            url = self.handle_continue_redirect(request, post_url_continue, msg)
    606612            return HttpResponseRedirect(post_url_continue % pk_value)
    607613
    608614        if request.POST.has_key("_popup"):
     
    633639
    634640        msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
    635641        if request.POST.has_key("_continue"):
    636             self.message_user(request, msg + ' ' + _("You may edit it again below."))
    637             if request.REQUEST.has_key('_popup'):
    638                 return HttpResponseRedirect(request.path + "?_popup=1")
    639             else:
    640                 return HttpResponseRedirect(request.path)
     642            url = self.handle_continue_redirect(request, request.path, msg)
     643            return HttpResponseRedirect(url)
    641644        elif request.POST.has_key("_saveasnew"):
    642645            msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj}
    643646            self.message_user(request, msg)
Back to Top