mirror of https://github.com/django/django.git
Fixed #21795 -- Made add_preserved_filters account for url prefixes.
Thanks to trac username honyczek for the report. Refs #6903.
This commit is contained in:
parent
d57ba04d89
commit
4339e9a92d
|
@ -5,7 +5,7 @@ except ImportError:
|
|||
|
||||
from django import template
|
||||
from django.contrib.admin.utils 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, to_field=None):
|
|||
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:
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -11,16 +11,18 @@ from django.core import mail
|
|||
from django.core.checks import Error
|
||||
from django.core.files import temp as tempfile
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
from django.core.urlresolvers import (NoReverseMatch,
|
||||
get_script_prefix, reverse, set_script_prefix)
|
||||
# Register auth models with the admin.
|
||||
from django.contrib.auth import get_permission_codename
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
||||
from django.contrib.admin.models import LogEntry, DELETION
|
||||
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
|
||||
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
||||
from django.contrib.admin.utils 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
|
||||
|
@ -4440,11 +4442,14 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
|||
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({
|
||||
|
@ -4586,6 +4591,29 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue