Ticket #6218: ticket-6218.2.patch
File ticket-6218.2.patch, 4.9 KB (added by , 14 years ago) |
---|
-
django/conf/__init__.py
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index d94f6e9..82e0c66 100644
a b class LazySettings(LazyObject): 59 59 return bool(self._wrapped) 60 60 configured = property(configured) 61 61 62 class Settings(object): 62 class BaseSettings(object): 63 """ 64 Common logic for settings wether set by a module or by the user. 65 """ 66 def __setattr__(self, name, value): 67 #Protecting people from themselves if they set MEDIA_URL to a value that 68 #doesn't end in a trailing slash 69 if name == "MEDIA_URL" and value and value[-1] != '/': 70 value = "%s/" % value 71 object.__setattr__(self, name, value) 72 73 class Settings(BaseSettings): 63 74 def __init__(self, settings_module): 64 75 # update this dict from global settings (but only for ALL_CAPS settings) 65 76 for setting in dir(global_settings): … … class Settings(object): 108 119 os.environ['TZ'] = self.TIME_ZONE 109 120 time.tzset() 110 121 111 class UserSettingsHolder( object):122 class UserSettingsHolder(BaseSettings): 112 123 """ 113 124 Holder for user configured settings. 114 125 """ -
django/conf/project_template/settings.py
diff --git a/django/conf/project_template/settings.py b/django/conf/project_template/settings.py index c49df24..b77a99e 100644
a b MEDIA_ROOT = '' 49 49 50 50 # URL that handles the media served from MEDIA_ROOT. Make sure to use a 51 51 # trailing slash if there is a path component (optional in other cases). 52 # Examples: "http://media.lawrence.com ", "http://example.com/media/"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..fb38aa9 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 Note that a trailing slash will be added if this is set to a non-empty value. 1081 1078 1082 1079 .. setting:: MIDDLEWARE_CLASSES 1083 1080 -
tests/regressiontests/settings_tests/tests.py
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py index fa217b1..ab6e105 100644
a b 1 1 import unittest 2 from django.conf import settings 2 from django.conf import settings, UserSettingsHolder, global_settings 3 3 4 4 class SettingsTests(unittest.TestCase): 5 5 … … class SettingsTests(unittest.TestCase): 15 15 16 16 def test_settings_delete_wrapped(self): 17 17 self.assertRaises(TypeError, delattr, settings, '_wrapped') 18 19 def test_settings_media_url_trailing_slash(self): 20 """ 21 settings.MEDIA_URL should always end with a slash if it's not blank 22 """ 23 settings.MEDIA_URL = '' 24 self.assertEqual('', settings.MEDIA_URL) 25 del settings.MEDIA_URL 26 27 settings.MEDIA_URL = '/foo/' 28 self.assertEqual('/foo/', settings.MEDIA_URL) 29 del settings.MEDIA_URL 30 31 settings.MEDIA_URL = '/foo' 32 self.assertEqual('/foo/', settings.MEDIA_URL) 33 del settings.MEDIA_URL 34 35 settings.MEDIA_URL = 'http://media.foo.com' 36 self.assertEqual('http://media.foo.com/', settings.MEDIA_URL) 37 del settings.MEDIA_URL 38 39 settings.MEDIA_URL = 'http://media.foo.com/' 40 self.assertEqual('http://media.foo.com/', settings.MEDIA_URL) 41 del settings.MEDIA_URL 42 43 #If someone does something stupid, presume they know what they're doing 44 settings.MEDIA_URL = 'http://media.foo.com/stupid//' 45 self.assertEqual('http://media.foo.com/stupid//', settings.MEDIA_URL) 46 47 s = UserSettingsHolder(global_settings) 48 s.MEDIA_URL = '' 49 self.assertEqual('', s.MEDIA_URL) 50 51 s = UserSettingsHolder(global_settings) 52 s.MEDIA_URL = '/foo/' 53 self.assertEqual('/foo/', s.MEDIA_URL) 54 55 s = UserSettingsHolder(global_settings) 56 s.MEDIA_URL = '/foo' 57 self.assertEqual('/foo/', s.MEDIA_URL) 58 59 s = UserSettingsHolder(global_settings) 60 s.MEDIA_URL = 'http://media.foo.com/' 61 self.assertEqual('http://media.foo.com/', s.MEDIA_URL) 62 63 s = UserSettingsHolder(global_settings) 64 s.MEDIA_URL = 'http://media.foo.com' 65 self.assertEqual('http://media.foo.com/', s.MEDIA_URL) 66 67 s = UserSettingsHolder(global_settings) 68 s.MEDIA_URL = 'http://media.foo.com/stupid//' 69 self.assertEqual('http://media.foo.com/stupid//', s.MEDIA_URL) 70 No newline at end of file