Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Thanks Collin Anderson for the report.
  • Loading branch information...
commit 2fc6c9472cd25910f978fe1d18de5c350370f901 1 parent 9a2715d
Loic Bistuer authored July 19, 2013 charettes committed July 18, 2013
6  django/contrib/admin/options.py
@@ -771,12 +771,10 @@ def get_preserved_filters(self, request):
771 771
         Returns the preserved filters querystring.
772 772
         """
773 773
 
774  
-        # FIXME: We can remove that getattr as soon as #20619 is fixed.
775  
-        match = getattr(request, 'resolver_match', None)
776  
-
  774
+        match = request.resolver_match
777 775
         if self.preserve_filters and match:
778 776
             opts = self.model._meta
779  
-            current_url = '%s:%s' % (match.namespace, match.url_name)
  777
+            current_url = '%s:%s' % (match.app_name, match.url_name)
780 778
             changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
781 779
             if current_url == changelist_url:
782 780
                 preserved_filters = request.GET.urlencode()
2  django/contrib/admin/templatetags/admin_urls.py
@@ -38,7 +38,7 @@ def add_preserved_filters(context, url, popup=False):
38 38
         except Resolver404:
39 39
             pass
40 40
         else:
41  
-            current_url = '%s:%s' % (match.namespace, match.url_name)
  41
+            current_url = '%s:%s' % (match.app_name, match.url_name)
42 42
             changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
43 43
             if changelist_url == current_url and '_changelist_filters' in preserved_filters:
44 44
                 preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
5  tests/admin_views/admin.py
@@ -777,3 +777,8 @@ class ChoiceList(admin.ModelAdmin):
777 777
 from django.contrib.auth.admin import UserAdmin, GroupAdmin
778 778
 site.register(User, UserAdmin)
779 779
 site.register(Group, GroupAdmin)
  780
+
  781
+# Used to test URL namespaces
  782
+site2 = admin.AdminSite(name="namespaced_admin")
  783
+site2.register(User, UserAdmin)
  784
+site2.register(Group, GroupAdmin)
21  tests/admin_views/tests.py
@@ -26,7 +26,6 @@
26 26
 from django.contrib.auth import REDIRECT_FIELD_NAME
27 27
 from django.contrib.auth.models import Group, User, Permission
28 28
 from django.contrib.contenttypes.models import ContentType
29  
-from django.core.urlresolvers import reverse
30 29
 from django.db import connection
31 30
 from django.forms.util import ErrorList
32 31
 from django.template.response import TemplateResponse
@@ -53,6 +52,7 @@
53 52
     AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
54 53
     Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
55 54
     Simple, UndeletableObject, Choice, ShortMessage, Telegram)
  55
+from .admin import site, site2
56 56
 
57 57
 
58 58
 ERROR_MESSAGE = "Please enter the correct username and password \
@@ -4186,6 +4186,7 @@ def test_message_extra_tags(self):
4186 4186
 class AdminKeepChangeListFiltersTests(TestCase):
4187 4187
     urls = "admin_views.urls"
4188 4188
     fixtures = ['admin-views-users.xml']
  4189
+    admin_site = site
4189 4190
 
4190 4191
     def setUp(self):
4191 4192
         self.client.login(username='super', password='secret')
@@ -4209,13 +4210,15 @@ def get_sample_user_id(self):
4209 4210
 
4210 4211
     def get_changelist_url(self):
4211 4212
         return '%s?%s' % (
4212  
-            reverse('admin:auth_user_changelist'),
  4213
+            reverse('admin:auth_user_changelist',
  4214
+                    current_app=self.admin_site.name),
4213 4215
             self.get_changelist_filters_querystring(),
4214 4216
         )
4215 4217
 
4216 4218
     def get_add_url(self):
4217 4219
         return '%s?%s' % (
4218  
-            reverse('admin:auth_user_add'),
  4220
+            reverse('admin:auth_user_add',
  4221
+                    current_app=self.admin_site.name),
4219 4222
             self.get_preserved_filters_querystring(),
4220 4223
         )
4221 4224
 
@@ -4223,7 +4226,8 @@ def get_change_url(self, user_id=None):
4223 4226
         if user_id is None:
4224 4227
             user_id = self.get_sample_user_id()
4225 4228
         return "%s?%s" % (
4226  
-            reverse('admin:auth_user_change', args=(user_id,)),
  4229
+            reverse('admin:auth_user_change', args=(user_id,),
  4230
+                    current_app=self.admin_site.name),
4227 4231
             self.get_preserved_filters_querystring(),
4228 4232
         )
4229 4233
 
@@ -4231,7 +4235,8 @@ def get_history_url(self, user_id=None):
4231 4235
         if user_id is None:
4232 4236
             user_id = self.get_sample_user_id()
4233 4237
         return "%s?%s" % (
4234  
-            reverse('admin:auth_user_history', args=(user_id,)),
  4238
+            reverse('admin:auth_user_history', args=(user_id,),
  4239
+                    current_app=self.admin_site.name),
4235 4240
             self.get_preserved_filters_querystring(),
4236 4241
         )
4237 4242
 
@@ -4239,7 +4244,8 @@ def get_delete_url(self, user_id=None):
4239 4244
         if user_id is None:
4240 4245
             user_id = self.get_sample_user_id()
4241 4246
         return "%s?%s" % (
4242  
-            reverse('admin:auth_user_delete', args=(user_id,)),
  4247
+            reverse('admin:auth_user_delete', args=(user_id,),
  4248
+                    current_app=self.admin_site.name),
4243 4249
             self.get_preserved_filters_querystring(),
4244 4250
         )
4245 4251
 
@@ -4333,3 +4339,6 @@ def test_delete_view(self):
4333 4339
         # Test redirect on "Delete".
4334 4340
         response = self.client.post(self.get_delete_url(), {'post': 'yes'})
4335 4341
         self.assertRedirects(response, self.get_changelist_url())
  4342
+
  4343
+class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
  4344
+    admin_site = site2
1  tests/admin_views/urls.py
@@ -12,4 +12,5 @@
12 12
     (r'^test_admin/admin2/', include(customadmin.site.urls)),
13 13
     (r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
14 14
     (r'^test_admin/admin4/', include(customadmin.simple_site.urls)),
  15
+    (r'^test_admin/admin5/', include(admin.site2.urls)),
15 16
 )

0 notes on commit 2fc6c94

Please sign in to comment.
Something went wrong with that request. Please try again.