Fixed #17744 -- Reset default file storage with setting_changed signal

This commit is contained in:
Claude Paroz 2012-10-27 22:38:15 +02:00
parent 43d7cee86e
commit 9a02851340
3 changed files with 19 additions and 16 deletions

View File

@ -5,6 +5,7 @@ from django.conf import settings
from django.db import connections from django.db import connections
from django.dispatch import receiver, Signal from django.dispatch import receiver, Signal
from django.utils import timezone from django.utils import timezone
from django.utils.functional import empty
template_rendered = Signal(providing_args=["template", "context"]) template_rendered = Signal(providing_args=["template", "context"])
@ -72,3 +73,9 @@ def language_changed(**kwargs):
trans_real._default = None trans_real._default = None
if kwargs['setting'] == 'LOCALE_PATHS': if kwargs['setting'] == 'LOCALE_PATHS':
trans_real._translations = {} trans_real._translations = {}
@receiver(setting_changed)
def file_storage_changed(**kwargs):
if kwargs['setting'] in ('MEDIA_ROOT', 'DEFAULT_FILE_STORAGE'):
from django.core.files.storage import default_storage
default_storage._wrapped = empty

View File

@ -1594,15 +1594,16 @@ callbacks to clean up and otherwise reset state when settings are changed.
Django itself uses this signal to reset various data: Django itself uses this signal to reset various data:
=========================== ======================== ================================ ========================
Overriden settings Data reset Overriden settings Data reset
=========================== ======================== ================================ ========================
USE_TZ, TIME_ZONE Databases timezone USE_TZ, TIME_ZONE Databases timezone
TEMPLATE_CONTEXT_PROCESSORS Context processors cache TEMPLATE_CONTEXT_PROCESSORS Context processors cache
TEMPLATE_LOADERS Template loaders cache TEMPLATE_LOADERS Template loaders cache
SERIALIZATION_MODULES Serializers cache SERIALIZATION_MODULES Serializers cache
LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
=========================== ======================== MEDIA_ROOT, DEFAULT_FILE_STORAGE Default file storage
================================ ========================
Emptying the test outbox Emptying the test outbox
~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -12,7 +12,6 @@ from django.template import loader, Context
from django.conf import settings from django.conf import settings
from django.core.cache.backends.base import BaseCache from django.core.cache.backends.base import BaseCache
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
from django.core.management import call_command from django.core.management import call_command
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
@ -48,10 +47,9 @@ class BaseStaticFilesTestCase(object):
Test case with a couple utility assertions. Test case with a couple utility assertions.
""" """
def setUp(self): def setUp(self):
# Clear the cached default_storage out, this is because when it first # Clear the cached staticfiles_storage out, this is because when it first
# gets accessed (by some other test), it evaluates settings.MEDIA_ROOT, # gets accessed (by some other test), it evaluates settings.STATIC_ROOT,
# since we're planning on changing that we need to clear out the cache. # since we're planning on changing that we need to clear out the cache.
default_storage._wrapped = empty
storage.staticfiles_storage._wrapped = empty storage.staticfiles_storage._wrapped = empty
# Clear the cached staticfile finders, so they are reinitialized every # Clear the cached staticfile finders, so they are reinitialized every
# run and pick up changes in settings.STATICFILES_DIRS. # run and pick up changes in settings.STATICFILES_DIRS.
@ -709,9 +707,6 @@ class TestMiscFinder(TestCase):
""" """
A few misc finder tests. A few misc finder tests.
""" """
def setUp(self):
default_storage._wrapped = empty
def test_get_finder(self): def test_get_finder(self):
self.assertIsInstance(finders.get_finder( self.assertIsInstance(finders.get_finder(
'django.contrib.staticfiles.finders.FileSystemFinder'), 'django.contrib.staticfiles.finders.FileSystemFinder'),