Merge remote-tracking branch 'django/master' into t3011

This commit is contained in:
Russell Keith-Magee 2012-09-16 18:16:49 +08:00
commit 280bf19e94
9 changed files with 37 additions and 30 deletions

View File

@ -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_text from django.utils.encoding import smart_text
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):
try:
return queryset.filter(**self.used_parameters) 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):

View File

@ -1,7 +1,7 @@
import os import os
import re import re
from django.conf import settings from django.conf import global_settings, settings
from django.contrib.sites.models import Site, RequestSite from django.contrib.sites.models import Site, RequestSite
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import mail from django.core import mail
@ -24,7 +24,8 @@ from django.contrib.auth.tests.utils import skipIfCustomUser
('en', 'English'), ('en', 'English'),
), ),
LANGUAGE_CODE='en', LANGUAGE_CODE='en',
TEMPLATE_DIRS = ( TEMPLATE_LOADERS=global_settings.TEMPLATE_LOADERS,
TEMPLATE_DIRS=(
os.path.join(os.path.dirname(__file__), 'templates'), os.path.join(os.path.dirname(__file__), 'templates'),
), ),
USE_TZ=False, USE_TZ=False,

View File

@ -51,6 +51,13 @@ def clear_context_processors_cache(**kwargs):
context._standard_context_processors = None context._standard_context_processors = None
@receiver(setting_changed)
def clear_template_loaders_cache(**kwargs):
if kwargs['setting'] == 'TEMPLATE_LOADERS':
from django.template import loader
loader.template_source_loaders = None
@receiver(setting_changed) @receiver(setting_changed)
def clear_serializers_cache(**kwargs): def clear_serializers_cache(**kwargs):
if kwargs['setting'] == 'SERIALIZATION_MODULES': if kwargs['setting'] == 'SERIALIZATION_MODULES':

View File

@ -1050,7 +1050,7 @@ defer
In some complex data-modeling situations, your models might contain a lot of In some complex data-modeling situations, your models might contain a lot of
fields, some of which could contain a lot of data (for example, text fields), fields, some of which could contain a lot of data (for example, text fields),
or require expensive processing to convert them to Python objects. If you are or require expensive processing to convert them to Python objects. If you are
using the results of a queryset in some situation where you know you don't know using the results of a queryset in some situation where you don't know
if you need those particular fields when you initially fetch the data, you can if you need those particular fields when you initially fetch the data, you can
tell Django not to retrieve them from the database. tell Django not to retrieve them from the database.

View File

@ -255,12 +255,12 @@ complex logging setup, configured using :meth:`logging.dictConfig`::
}, },
'handlers': { 'handlers': {
'null': { 'null': {
'level':'DEBUG', 'level': 'DEBUG',
'class':'django.utils.log.NullHandler', 'class': 'django.utils.log.NullHandler',
}, },
'console':{ 'console':{
'level':'DEBUG', 'level': 'DEBUG',
'class':'logging.StreamHandler', 'class': 'logging.StreamHandler',
'formatter': 'simple' 'formatter': 'simple'
}, },
'mail_admins': { 'mail_admins': {
@ -271,9 +271,9 @@ complex logging setup, configured using :meth:`logging.dictConfig`::
}, },
'loggers': { 'loggers': {
'django': { 'django': {
'handlers':['null'], 'handlers': ['null'],
'propagate': True, 'propagate': True,
'level':'INFO', 'level': 'INFO',
}, },
'django.request': { 'django.request': {
'handlers': ['mail_admins'], 'handlers': ['mail_admins'],

View File

@ -130,7 +130,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):

View File

@ -128,6 +128,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 __str__(self): def __str__(self):
return self.title return self.title

View File

@ -437,6 +437,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())

View File

@ -1,36 +1,27 @@
from __future__ import absolute_import from __future__ import absolute_import, unicode_literals
import inspect import inspect
import os import os
import sys import sys
from django.conf import settings from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase, RequestFactory
from django.test.utils import (setup_test_template_loader,
restore_template_loaders)
from django.core.urlresolvers import reverse
from django.views.debug import ExceptionReporter
from django.core import mail from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.test.utils import (override_settings, setup_test_template_loader,
restore_template_loaders)
from django.views.debug import ExceptionReporter
from .. import BrokenException, except_args from .. import BrokenException, except_args
from ..views import (sensitive_view, non_sensitive_view, paranoid_view, from ..views import (sensitive_view, non_sensitive_view, paranoid_view,
custom_exception_reporter_filter_view, sensitive_method_view) custom_exception_reporter_filter_view, sensitive_method_view)
@override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
class DebugViewTests(TestCase): class DebugViewTests(TestCase):
urls = "regressiontests.views.urls" urls = "regressiontests.views.urls"
def setUp(self):
self.old_debug = settings.DEBUG
settings.DEBUG = True
self.old_template_debug = settings.TEMPLATE_DEBUG
settings.TEMPLATE_DEBUG = True
def tearDown(self):
settings.DEBUG = self.old_debug
settings.TEMPLATE_DEBUG = self.old_template_debug
def test_files(self): def test_files(self):
response = self.client.get('/raises/') response = self.client.get('/raises/')
self.assertEqual(response.status_code, 500) self.assertEqual(response.status_code, 500)