Ticket #6218: 6218.diff
File 6218.diff, 7.0 KB (added by , 14 years ago) |
---|
-
django/conf/__init__.py
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index bda0ef3..7daf227 100644
a b import re 11 11 import time # Needed for Windows 12 12 13 13 from django.conf import global_settings 14 from django.core.exceptions import ImproperlyConfigured 14 15 from django.utils.functional import LazyObject 15 16 from django.utils import importlib 16 17 … … class LazySettings(LazyObject): 59 60 return bool(self._wrapped) 60 61 configured = property(configured) 61 62 62 class Settings(object): 63 64 class BaseSettings(object): 65 """ 66 Common logic for settings whether set by a module or by the user. 67 """ 68 def __setattr__(self, name, value): 69 if name == "MEDIA_URL" and value and value[-1] != '/': 70 raise ImproperlyConfigured('If set, MEDIA_URL must end in a ' 71 'slash.') 72 object.__setattr__(self, name, value) 73 74 75 class Settings(BaseSettings): 63 76 def __init__(self, settings_module): 64 77 # update this dict from global settings (but only for ALL_CAPS settings) 65 78 for setting in dir(global_settings): … … class Settings(object): 114 127 os.environ['TZ'] = self.TIME_ZONE 115 128 time.tzset() 116 129 117 class UserSettingsHolder(object): 130 131 class UserSettingsHolder(BaseSettings): 118 132 """ 119 133 Holder for user configured settings. 120 134 """ … … class UserSettingsHolder(object): 138 152 # For Python < 2.6: 139 153 __members__ = property(lambda self: self.__dir__()) 140 154 141 settings = LazySettings()142 155 156 settings = LazySettings() -
django/conf/global_settings.py
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 6033297..4a9b9e2 100644
a b DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' 263 263 MEDIA_ROOT = '' 264 264 265 265 # URL that handles the media served from MEDIA_ROOT. 266 # Example: "http://media.lawrence.com "266 # Example: "http://media.lawrence.com/" 267 267 MEDIA_URL = '' 268 268 269 269 # List of upload handler classes to be applied in order. -
django/conf/project_template/settings.py
diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py index c49df24..4edd67f 100644
a b USE_L10N = True 48 48 MEDIA_ROOT = '' 49 49 50 50 # URL that handles the media served from MEDIA_ROOT. Make sure to use a 51 # trailing slash if there is a path component (optional in other cases).52 # Examples: "http://media.lawrence.com ", "http://example.com/media/"51 # trailing slash. 52 # Examples: "http://media.lawrence.com/", "http://example.com/media/" 53 53 MEDIA_URL = '' 54 54 55 55 # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a -
docs/ref/settings.txt
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index b5556de..58738a5 100644
a b MEDIA_URL 1072 1072 Default: ``''`` (Empty string) 1073 1073 1074 1074 URL that handles the media served from ``MEDIA_ROOT``. 1075 Example: ``"http://media.lawrence.com "``1075 Example: ``"http://media.lawrence.com/"`` 1076 1076 1077 Note that this should have a trailing slash if it has a path component. 1078 1079 Good: ``"http://www.example.com/static/"`` 1080 Bad: ``"http://www.example.com/static"`` 1077 It must end in a slash if set to a non-empty value. 1081 1078 1082 1079 .. setting:: MIDDLEWARE_CLASSES 1083 1080 -
docs/releases/1.3.txt
diff --git a/docs/releases/1.3.txt b/docs/releases/1.3.txt index 51de6fd..52f1758 100644
a b If you are currently using the ``mod_python`` request handler, it is strongly 81 81 encouraged you redeploy your Django instances using :doc:`mod_wsgi 82 82 </howto/deployment/modwsgi>`. 83 83 84 Other changes in Django 1.3 85 =========================== 86 87 ``MEDIA_URL`` must end in a slash 88 --------------------------------- 89 90 Previously, the ``MEDIA_URL`` setting only required a trailing slash if it 91 contained a suffix beyond the domain name. 92 93 A trailing slash is now *required* for ``MEDIA_URL`` as long as it is not 94 blank. This ensures there is a consistent way to combine ``MEDIA_URL`` in 95 templates. 96 97 Project settings modules which provide a ``MEDIA_URL`` without a trailing slash 98 will now raise an ``ImproperlyConfigured`` error. 99 84 100 What's new in Django 1.3 85 101 ======================== 86 102 -
tests/regressiontests/settings_tests/tests.py
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py index fa217b1..08d5b0a 100644
a b 1 1 import unittest 2 from django.conf import settings 2 from django.conf import settings, UserSettingsHolder, global_settings 3 from django.core.exceptions import ImproperlyConfigured 4 5 6 def setattr_settings(settings_module, attr, value): 7 setattr(settings_module, attr, value) 8 3 9 4 10 class SettingsTests(unittest.TestCase): 5 11 … … class SettingsTests(unittest.TestCase): 15 21 16 22 def test_settings_delete_wrapped(self): 17 23 self.assertRaises(TypeError, delattr, settings, '_wrapped') 24 25 26 class MediaURLTests(unittest.TestCase): 27 settings_module = settings 28 29 def setUp(self): 30 self._original_media_url = self.settings_module.MEDIA_URL 31 32 def tearDown(self): 33 self.settings_module.MEDIA_URL = self._original_media_url 34 35 def test_blank(self): 36 """ 37 If blank, no ImproperlyConfigured error will be raised, even though it 38 doesn't end in a slash. 39 """ 40 self.settings_module.MEDIA_URL = '' 41 self.assertEqual('', self.settings_module.MEDIA_URL) 42 43 def test_end_slash(self): 44 """ 45 MEDIA_URL works if you end in a slash. 46 """ 47 self.settings_module.MEDIA_URL = '/foo/' 48 self.assertEqual('/foo/', self.settings_module.MEDIA_URL) 49 50 self.settings_module.MEDIA_URL = 'http://media.foo.com/' 51 self.assertEqual('http://media.foo.com/', 52 self.settings_module.MEDIA_URL) 53 54 def test_no_end_slash(self): 55 """ 56 MEDIA_URL raises an ImproperlyConfigured error if it doesn't end in a 57 slash. 58 """ 59 self.assertRaises(ImproperlyConfigured, setattr_settings, 60 self.settings_module, 'MEDIA_URL', '/foo') 61 62 self.assertRaises(ImproperlyConfigured, setattr_settings, 63 self.settings_module, 'MEDIA_URL', 64 'http://media.foo.com') 65 66 def test_double_slash(self): 67 """ 68 If a MEDIA_URL ends in more than one slash, presume they know what 69 they're doing. 70 """ 71 self.settings_module.MEDIA_URL = '/stupid//' 72 self.assertEqual('/stupid//', self.settings_module.MEDIA_URL) 73 74 self.settings_module.MEDIA_URL = 'http://media.foo.com/stupid//' 75 self.assertEqual('http://media.foo.com/stupid//', 76 self.settings_module.MEDIA_URL) 77 78 79 class MediaURLUserSettingsHolderTests(unittest.TestCase): 80 settings_module = UserSettingsHolder(global_settings)