Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20767 -- Fixed ModelAdmin.preserve_filters for namespaced URLs.

Thanks Collin Anderson for the report.
  • Loading branch information...
commit 2fc6c9472cd25910f978fe1d18de5c350370f901 1 parent 9a2715d
@loic loic authored charettes committed
View
6 django/contrib/admin/options.py
@@ -771,12 +771,10 @@ def get_preserved_filters(self, request):
Returns the preserved filters querystring.
"""
- # FIXME: We can remove that getattr as soon as #20619 is fixed.
- match = getattr(request, 'resolver_match', None)
-
+ match = request.resolver_match
if self.preserve_filters and match:
opts = self.model._meta
- current_url = '%s:%s' % (match.namespace, match.url_name)
+ current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if current_url == changelist_url:
preserved_filters = request.GET.urlencode()
View
2  django/contrib/admin/templatetags/admin_urls.py
@@ -38,7 +38,7 @@ def add_preserved_filters(context, url, popup=False):
except Resolver404:
pass
else:
- current_url = '%s:%s' % (match.namespace, match.url_name)
+ current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
View
5 tests/admin_views/admin.py
@@ -777,3 +777,8 @@ class ChoiceList(admin.ModelAdmin):
from django.contrib.auth.admin import UserAdmin, GroupAdmin
site.register(User, UserAdmin)
site.register(Group, GroupAdmin)
+
+# Used to test URL namespaces
+site2 = admin.AdminSite(name="namespaced_admin")
+site2.register(User, UserAdmin)
+site2.register(Group, GroupAdmin)
View
21 tests/admin_views/tests.py
@@ -26,7 +26,6 @@
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Group, User, Permission
from django.contrib.contenttypes.models import ContentType
-from django.core.urlresolvers import reverse
from django.db import connection
from django.forms.util import ErrorList
from django.template.response import TemplateResponse
@@ -53,6 +52,7 @@
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
Simple, UndeletableObject, Choice, ShortMessage, Telegram)
+from .admin import site, site2
ERROR_MESSAGE = "Please enter the correct username and password \
@@ -4186,6 +4186,7 @@ def test_message_extra_tags(self):
class AdminKeepChangeListFiltersTests(TestCase):
urls = "admin_views.urls"
fixtures = ['admin-views-users.xml']
+ admin_site = site
def setUp(self):
self.client.login(username='super', password='secret')
@@ -4209,13 +4210,15 @@ def get_sample_user_id(self):
def get_changelist_url(self):
return '%s?%s' % (
- reverse('admin:auth_user_changelist'),
+ reverse('admin:auth_user_changelist',
+ current_app=self.admin_site.name),
self.get_changelist_filters_querystring(),
)
def get_add_url(self):
return '%s?%s' % (
- reverse('admin:auth_user_add'),
+ reverse('admin:auth_user_add',
+ current_app=self.admin_site.name),
self.get_preserved_filters_querystring(),
)
@@ -4223,7 +4226,8 @@ def get_change_url(self, user_id=None):
if user_id is None:
user_id = self.get_sample_user_id()
return "%s?%s" % (
- reverse('admin:auth_user_change', args=(user_id,)),
+ reverse('admin:auth_user_change', args=(user_id,),
+ current_app=self.admin_site.name),
self.get_preserved_filters_querystring(),
)
@@ -4231,7 +4235,8 @@ def get_history_url(self, user_id=None):
if user_id is None:
user_id = self.get_sample_user_id()
return "%s?%s" % (
- reverse('admin:auth_user_history', args=(user_id,)),
+ reverse('admin:auth_user_history', args=(user_id,),
+ current_app=self.admin_site.name),
self.get_preserved_filters_querystring(),
)
@@ -4239,7 +4244,8 @@ def get_delete_url(self, user_id=None):
if user_id is None:
user_id = self.get_sample_user_id()
return "%s?%s" % (
- reverse('admin:auth_user_delete', args=(user_id,)),
+ reverse('admin:auth_user_delete', args=(user_id,),
+ current_app=self.admin_site.name),
self.get_preserved_filters_querystring(),
)
@@ -4333,3 +4339,6 @@ def test_delete_view(self):
# Test redirect on "Delete".
response = self.client.post(self.get_delete_url(), {'post': 'yes'})
self.assertRedirects(response, self.get_changelist_url())
+
+class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
+ admin_site = site2
View
1  tests/admin_views/urls.py
@@ -12,4 +12,5 @@
(r'^test_admin/admin2/', include(customadmin.site.urls)),
(r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
(r'^test_admin/admin4/', include(customadmin.simple_site.urls)),
+ (r'^test_admin/admin5/', include(admin.site2.urls)),
)
Please sign in to comment.
Something went wrong with that request. Please try again.