Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6.x] Fixed #21795 -- Made add_preserved_filters account for url pr…

…efixes.

Thanks to trac username honyczek for the report. Refs #6903.

Backport of 4339e9a from master
  • Loading branch information...
commit a5297c1ef4c4c010d1eb979177d4633beb5f9cad 1 parent 916f0de
Loïc Bistuer loic authored timgraham committed
5 django/contrib/admin/templatetags/admin_urls.py
View
@@ -5,7 +5,7 @@
from django import template
from django.contrib.admin.util import quote
-from django.core.urlresolvers import resolve, Resolver404
+from django.core.urlresolvers import Resolver404, get_script_prefix, resolve
from django.utils.http import urlencode
register = template.Library()
@@ -33,8 +33,9 @@ def add_preserved_filters(context, url, popup=False):
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
+ match_url = '/%s' % url.partition(get_script_prefix())[2]
try:
- match = resolve(url)
+ match = resolve(match_url)
except Resolver404:
pass
else:
4 docs/releases/1.6.3.txt
View
@@ -30,5 +30,9 @@ several bugs in 1.6.2:
* Fixed a regression in the :mod:`django.contrib.gis` SQL compiler for
non-concrete fields (`#22250 <http://code.djangoproject.com/ticket/22250>`_).
+* Fixed :attr:`ModelAdmin.preserve_filters
+ <django.contrib.admin.ModelAdmin.preserve_filters>` when running a site with
+ a URL prefix (`#21795 <http://code.djangoproject.com/ticket/21795>`_).
+
Additionally, Django's vendored version of six, :mod:`django.utils.six` has been
upgraded to the latest release (1.6.1).
38 tests/admin_views/tests.py
View
@@ -9,17 +9,18 @@
from django.core import mail
from django.core.exceptions import ImproperlyConfigured
from django.core.files import temp as tempfile
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import get_script_prefix, reverse, set_script_prefix
# Register auth models with the admin.
from django.contrib import admin
from django.contrib.auth import get_permission_codename
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY
+from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
+from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
from django.contrib.admin.util import quote
from django.contrib.admin.validation import ModelAdminValidator
from django.contrib.admin.views.main import IS_POPUP_VAR
-from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.models import Group, User, Permission
from django.contrib.contenttypes.models import ContentType
@@ -4224,11 +4225,14 @@ def setUp(self):
def tearDown(self):
self.client.logout()
- def get_changelist_filters_querystring(self):
- return urlencode({
+ def get_changelist_filters(self):
+ return {
'is_superuser__exact': 0,
'is_staff__exact': 0,
- })
+ }
+
+ def get_changelist_filters_querystring(self):
+ return urlencode(self.get_changelist_filters())
def get_preserved_filters_querystring(self):
return urlencode({
@@ -4370,6 +4374,30 @@ def test_delete_view(self):
response = self.client.post(self.get_delete_url(), {'post': 'yes'})
self.assertRedirects(response, self.get_changelist_url())
+ def test_url_prefix(self):
+ context = {
+ 'preserved_filters': self.get_preserved_filters_querystring(),
+ 'opts': User._meta,
+ }
+
+ url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name)
+ self.assertEqual(
+ self.get_changelist_url(),
+ add_preserved_filters(context, url),
+ )
+
+ original_prefix = get_script_prefix()
+ try:
+ set_script_prefix('/prefix/')
+ url = reverse('admin:auth_user_changelist', current_app=self.admin_site.name)
+ self.assertEqual(
+ self.get_changelist_url(),
+ add_preserved_filters(context, url),
+ )
+ finally:
+ set_script_prefix(original_prefix)
+
+
class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests):
admin_site = site2
Please sign in to comment.
Something went wrong with that request. Please try again.