[1.4.X] Fixed #18530 -- Fixed a small regression in the admin filters where wrongly formatted dates passed as url parameters caused an unhandled ValidationError. Thanks to david for the report.
This commit is contained in:
parent
421ce44e8b
commit
336dfc3413
@ -8,13 +8,13 @@ certain test -- e.g. being a DateField or ForeignKey.
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from django.contrib.admin.util import (get_model_from_relation,
|
from django.contrib.admin.util import (get_model_from_relation,
|
||||||
reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
|
reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value)
|
||||||
|
from django.contrib.admin.options import IncorrectLookupParameters
|
||||||
|
|
||||||
class ListFilter(object):
|
class ListFilter(object):
|
||||||
title = None # Human-readable title to appear in the right sidebar.
|
title = None # Human-readable title to appear in the right sidebar.
|
||||||
@ -129,7 +129,10 @@ class FieldListFilter(ListFilter):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def queryset(self, request, queryset):
|
def queryset(self, request, queryset):
|
||||||
return queryset.filter(**self.used_parameters)
|
try:
|
||||||
|
return queryset.filter(**self.used_parameters)
|
||||||
|
except ValidationError as e:
|
||||||
|
raise IncorrectLookupParameters(e)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register(cls, test, list_filter_class, take_priority=False):
|
def register(cls, test, list_filter_class, take_priority=False):
|
||||||
@ -302,7 +305,7 @@ class DateFieldListFilter(FieldListFilter):
|
|||||||
else: # field is a models.DateField
|
else: # field is a models.DateField
|
||||||
today = now.date()
|
today = now.date()
|
||||||
tomorrow = today + datetime.timedelta(days=1)
|
tomorrow = today + datetime.timedelta(days=1)
|
||||||
|
|
||||||
self.lookup_kwarg_since = '%s__gte' % field_path
|
self.lookup_kwarg_since = '%s__gte' % field_path
|
||||||
self.lookup_kwarg_until = '%s__lt' % field_path
|
self.lookup_kwarg_until = '%s__lt' % field_path
|
||||||
self.links = (
|
self.links = (
|
||||||
|
@ -127,7 +127,7 @@ class CustomArticleAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
|
|
||||||
class ThingAdmin(admin.ModelAdmin):
|
class ThingAdmin(admin.ModelAdmin):
|
||||||
list_filter = ('color__warm', 'color__value')
|
list_filter = ('color__warm', 'color__value', 'pub_date',)
|
||||||
|
|
||||||
|
|
||||||
class InquisitionAdmin(admin.ModelAdmin):
|
class InquisitionAdmin(admin.ModelAdmin):
|
||||||
|
@ -113,6 +113,7 @@ class Color2(Color):
|
|||||||
class Thing(models.Model):
|
class Thing(models.Model):
|
||||||
title = models.CharField(max_length=20)
|
title = models.CharField(max_length=20)
|
||||||
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
|
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
|
||||||
|
pub_date = models.DateField(blank=True, null=True)
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
@ -456,6 +456,10 @@ class AdminViewBasicTest(TestCase):
|
|||||||
response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
|
response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
|
||||||
self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
|
self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
|
||||||
|
|
||||||
|
# Regression test for #18530
|
||||||
|
response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'pub_date__gte': 'foo'})
|
||||||
|
self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
|
||||||
|
|
||||||
def testIsNullLookups(self):
|
def testIsNullLookups(self):
|
||||||
"""Ensure is_null is handled correctly."""
|
"""Ensure is_null is handled correctly."""
|
||||||
Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
|
Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user