Ticket #6903: 6903.diff

File 6903.diff, 3.1 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 8e0aacc..26bda21 100644
    a b class ModelAdmin(BaseModelAdmin):  
    884884            post_url = reverse('admin:%s_%s_changelist' %
    885885                               (opts.app_label, opts.module_name),
    886886                               current_app=self.admin_site.name)
     887            post_url += self.changelist_redirect_querystring(request)
    887888        else:
    888889            post_url = reverse('admin:index',
    889890                               current_app=self.admin_site.name)
    class ModelAdmin(BaseModelAdmin):  
    956957            self.message_user(request, msg)
    957958            return None
    958959
     960    def changelist_redirect_querystring(self, request):
     961        opts = self.model._meta
     962        return request.session.get(
     963            'admin_%s_%s_changelist_querystring' % (opts.app_label, opts.module_name), '')
     964
    959965    @csrf_protect_m
    960966    @transaction.commit_on_success
    961967    def add_view(self, request, form_url='', extra_context=None):
    class ModelAdmin(BaseModelAdmin):  
    12821288        }
    12831289        context.update(extra_context or {})
    12841290
     1291        if request.method == 'GET':
     1292            # Store the querystring in the session so we can return to the
     1293            # same filtered changelist later, for example after an object has
     1294            # been saved or deleted.
     1295            request.session['admin_%s_%s_changelist_querystring' % (
     1296                opts.app_label, opts.module_name)] = cl.get_query_string()
     1297
    12851298        return TemplateResponse(request, self.change_list_template or [
    12861299            'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
    12871300            'admin/%s/change_list.html' % app_label,
    class ModelAdmin(BaseModelAdmin):  
    13221335            if not self.has_change_permission(request, None):
    13231336                return HttpResponseRedirect(reverse('admin:index',
    13241337                                                    current_app=self.admin_site.name))
    1325             return HttpResponseRedirect(reverse('admin:%s_%s_changelist' %
     1338            url = reverse('admin:%s_%s_changelist' %
    13261339                                        (opts.app_label, opts.module_name),
    1327                                         current_app=self.admin_site.name))
     1340                                        current_app=self.admin_site.name)
     1341            url += self.changelist_redirect_querystring(request)
     1342            return HttpResponseRedirect(url)
    13281343
    13291344        object_name = force_text(opts.verbose_name)
    13301345
  • tests/regressiontests/admin_changelist/tests.py

    diff --git a/tests/regressiontests/admin_changelist/tests.py b/tests/regressiontests/admin_changelist/tests.py
    index 7a3a5c0..6c98194 100644
    a b class ChangeListTests(TestCase):  
    3535    def _mocked_authenticated_request(self, url, user):
    3636        request = self.factory.get(url)
    3737        request.user = user
     38        request.session = {}
    3839        return request
    3940
    4041    def test_select_related_preserved(self):
Back to Top