Ticket #6218: t6218b.patch
File t6218b.patch, 7.2 KB (added by , 14 years ago) |
---|
-
django/conf/__init__.py
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index d94f6e9..e81a3fb 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 import warnings 71 warnings.warn('If set, MEDIA_URL must end in a slash', 72 category=PendingDeprecationWarning) 73 object.__setattr__(self, name, value) 74 75 76 class Settings(BaseSettings): 63 77 def __init__(self, settings_module): 64 78 # update this dict from global settings (but only for ALL_CAPS settings) 65 79 for setting in dir(global_settings): … … class Settings(object): 108 122 os.environ['TZ'] = self.TIME_ZONE 109 123 time.tzset() 110 124 111 class UserSettingsHolder(object): 125 126 class UserSettingsHolder(BaseSettings): 112 127 """ 113 128 Holder for user configured settings. 114 129 """ … … class UserSettingsHolder(object): 132 147 # For Python < 2.6: 133 148 __members__ = property(lambda self: self.__dir__()) 134 149 135 settings = LazySettings()136 150 151 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..bbbacfc 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 ``PendingDeprecation`` warning. 99 100 In Django 1.4 this same condition will raise an ``ImproperlyConfigured`` exception. 101 84 102 What's new in Django 1.3 85 103 ======================== 86 104 -
tests/regressiontests/settings_tests/tests.py
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py index fa217b1..7a1fd6f 100644
a b 1 1 import unittest 2 from django.conf import settings 2 from django.conf import settings, UserSettingsHolder, global_settings 3 4 def setattr_settings(settings_module, attr, value): 5 setattr(settings_module, attr, value) 6 3 7 4 8 class SettingsTests(unittest.TestCase): 5 9 … … class SettingsTests(unittest.TestCase): 15 19 16 20 def test_settings_delete_wrapped(self): 17 21 self.assertRaises(TypeError, delattr, settings, '_wrapped') 22 23 24 class MediaURLTests(unittest.TestCase): 25 settings_module = settings 26 27 def setUp(self): 28 self._original_media_url = self.settings_module.MEDIA_URL 29 30 def tearDown(self): 31 self.settings_module.MEDIA_URL = self._original_media_url 32 33 def test_blank(self): 34 """ 35 If blank, no PendingDeprecationWarning error will be raised, even though it 36 doesn't end in a slash. 37 """ 38 self.settings_module.MEDIA_URL = '' 39 self.assertEqual('', self.settings_module.MEDIA_URL) 40 41 def test_end_slash(self): 42 """ 43 MEDIA_URL works if you end in a slash. 44 """ 45 self.settings_module.MEDIA_URL = '/foo/' 46 self.assertEqual('/foo/', self.settings_module.MEDIA_URL) 47 48 self.settings_module.MEDIA_URL = 'http://media.foo.com/' 49 self.assertEqual('http://media.foo.com/', 50 self.settings_module.MEDIA_URL) 51 52 def test_no_end_slash(self): 53 """ 54 MEDIA_URL raises an PendingDeprecationWarning error if it doesn't end in a 55 slash. 56 """ 57 import warnings 58 warnings.filterwarnings('error', 'If set, MEDIA_URL must end in a slash', PendingDeprecationWarning) 59 60 self.assertRaises(PendingDeprecationWarning, setattr_settings, 61 self.settings_module, 'MEDIA_URL', '/foo') 62 63 self.assertRaises(PendingDeprecationWarning, setattr_settings, 64 self.settings_module, 'MEDIA_URL', 65 'http://media.foo.com') 66 67 def test_double_slash(self): 68 """ 69 If a MEDIA_URL ends in more than one slash, presume they know what 70 they're doing. 71 """ 72 self.settings_module.MEDIA_URL = '/stupid//' 73 self.assertEqual('/stupid//', self.settings_module.MEDIA_URL) 74 75 self.settings_module.MEDIA_URL = 'http://media.foo.com/stupid//' 76 self.assertEqual('http://media.foo.com/stupid//', 77 self.settings_module.MEDIA_URL) 78 79 80 class MediaURLUserSettingsHolderTests(unittest.TestCase): 81 settings_module = UserSettingsHolder(global_settings) 82 No newline at end of file