Ticket #19505: 19505.admin-post-save-redirects.diff

File 19505.admin-post-save-redirects.diff, 4.9 KB (added by Julien Phalip, 12 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index e25a4d4..0a675ec 100644
    a b class ModelAdmin(BaseModelAdmin):  
    785785            "admin/change_form.html"
    786786        ], context, current_app=self.admin_site.name)
    787787
    788     def response_add(self, request, obj, post_url_continue='../%s/'):
     788    def response_add(self, request, obj, post_url_continue=None):
    789789        """
    790790        Determines the HttpResponse for the add_view stage.
    791791        """
    class ModelAdmin(BaseModelAdmin):  
    797797        # the presence of keys in request.POST.
    798798        if "_continue" in request.POST:
    799799            self.message_user(request, msg + ' ' + _("You may edit it again below."))
    800             if "_popup" in request.POST:
    801                 post_url_continue += "?_popup=1"
    802             return HttpResponseRedirect(post_url_continue % pk_value)
     800            if post_url_continue is None:
     801                post_url_continue = reverse('admin:%s_%s_change' %
     802                                            (opts.app_label, opts.module_name),
     803                                            args=(pk_value,),
     804                                            current_app=self.admin_site.name)
     805                if "_popup" in request.POST:
     806                    post_url_continue += "?_popup=1"
     807            return HttpResponseRedirect(post_url_continue)
    803808
    804809        if "_popup" in request.POST:
    805810            return HttpResponse(
    class ModelAdmin(BaseModelAdmin):  
    812817            return HttpResponseRedirect(request.path)
    813818        else:
    814819            self.message_user(request, msg)
    815 
    816             # Figure out where to redirect. If the user has change permission,
    817             # redirect to the change-list page for this object. Otherwise,
    818             # redirect to the admin index.
    819             if self.has_change_permission(request, None):
    820                 post_url = reverse('admin:%s_%s_changelist' %
    821                                    (opts.app_label, opts.module_name),
    822                                    current_app=self.admin_site.name)
    823             else:
    824                 post_url = reverse('admin:index',
    825                                    current_app=self.admin_site.name)
    826             return HttpResponseRedirect(post_url)
     820            return self.response_post_save(request, obj)
    827821
    828822    def response_change(self, request, obj):
    829823        """
    class ModelAdmin(BaseModelAdmin):  
    863857                                        current_app=self.admin_site.name))
    864858        else:
    865859            self.message_user(request, msg)
    866             # Figure out where to redirect. If the user has change permission,
    867             # redirect to the change-list page for this object. Otherwise,
    868             # redirect to the admin index.
    869             if self.has_change_permission(request, None):
    870                 post_url = reverse('admin:%s_%s_changelist' %
    871                                    (opts.app_label, module_name),
    872                                    current_app=self.admin_site.name)
    873             else:
    874                 post_url = reverse('admin:index',
    875                                    current_app=self.admin_site.name)
    876             return HttpResponseRedirect(post_url)
     860            return self.response_post_save(request, obj)
     861
     862    def response_post_save(self, request, obj):
     863        """
     864        Figure out where to redirect after the 'Save' button has been pressed.
     865        If the user has change permission, redirect to the change-list page for
     866        this object. Otherwise, redirect to the admin index.
     867        """
     868        opts = obj._meta
     869        if obj._deferred:
     870            opts_ = opts.proxy_for_model._meta
     871            module_name = opts_.module_name
     872        else:
     873            module_name = opts.module_name
     874        if self.has_change_permission(request, None):
     875            post_url = reverse('admin:%s_%s_changelist' %
     876                               (opts.app_label, module_name),
     877                               current_app=self.admin_site.name)
     878        else:
     879            post_url = reverse('admin:index',
     880                               current_app=self.admin_site.name)
     881        return HttpResponseRedirect(post_url)
    877882
    878883    def response_action(self, request, queryset):
    879884        """
  • django/contrib/auth/admin.py

    diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
    index de5abce..7b81667 100644
    a b class UserAdmin(admin.ModelAdmin):  
    153153            'admin/auth/user/change_password.html',
    154154            context, current_app=self.admin_site.name)
    155155
    156     def response_add(self, request, obj, post_url_continue='../%s/'):
     156    def response_add(self, request, obj, post_url_continue=None):
    157157        """
    158158        Determines the HttpResponse for the add_view stage. It mostly defers to
    159159        its superclass implementation but is customized because the User model
Back to Top