Fixed #18824 -- Allow deleting a setting from overriden settings
This commit is contained in:
parent
cc9b767fc6
commit
22f85b9057
|
@ -152,11 +152,22 @@ class UserSettingsHolder(BaseSettings):
|
||||||
Requests for configuration variables not in this class are satisfied
|
Requests for configuration variables not in this class are satisfied
|
||||||
from the module specified in default_settings (if possible).
|
from the module specified in default_settings (if possible).
|
||||||
"""
|
"""
|
||||||
|
self.__dict__['_deleted'] = set()
|
||||||
self.default_settings = default_settings
|
self.default_settings = default_settings
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
if name in self._deleted:
|
||||||
|
raise AttributeError
|
||||||
return getattr(self.default_settings, name)
|
return getattr(self.default_settings, name)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
self._deleted.discard(name)
|
||||||
|
return super(UserSettingsHolder, self).__setattr__(name, value)
|
||||||
|
|
||||||
|
def __delattr__(self, name):
|
||||||
|
self._deleted.add(name)
|
||||||
|
return super(UserSettingsHolder, self).__delattr__(name)
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return list(self.__dict__) + dir(self.default_settings)
|
return list(self.__dict__) + dir(self.default_settings)
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,16 @@ class SettingsTests(TestCase):
|
||||||
def test_settings_delete_wrapped(self):
|
def test_settings_delete_wrapped(self):
|
||||||
self.assertRaises(TypeError, delattr, settings, '_wrapped')
|
self.assertRaises(TypeError, delattr, settings, '_wrapped')
|
||||||
|
|
||||||
|
def test_override_settings_delete(self):
|
||||||
|
"""
|
||||||
|
Allow deletion of a setting in an overriden settings set (#18824)
|
||||||
|
"""
|
||||||
|
previous_i18n = settings.USE_I18N
|
||||||
|
with self.settings(USE_I18N=False):
|
||||||
|
del settings.USE_I18N
|
||||||
|
self.assertRaises(AttributeError, getattr, settings, 'USE_I18N')
|
||||||
|
self.assertEqual(settings.USE_I18N, previous_i18n)
|
||||||
|
|
||||||
def test_allowed_include_roots_string(self):
|
def test_allowed_include_roots_string(self):
|
||||||
"""
|
"""
|
||||||
ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string
|
ALLOWED_INCLUDE_ROOTS is not allowed to be incorrectly set to a string
|
||||||
|
|
Loading…
Reference in New Issue