Merge pull request #893 from ostcar/back_to_default_config
Added Feature for config app, to return the default value for a key
This commit is contained in:
commit
81319e746e
@ -45,19 +45,29 @@ class ConfigHandler(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Call on_change callback
|
# Call on_change callback
|
||||||
for receiver, config_page in config_signal.send(sender=self):
|
for receiver, config_page in config_signal.send(sender='set_value'):
|
||||||
for config_variable in config_page.variables:
|
for config_variable in config_page.variables:
|
||||||
if config_variable.name == key and config_variable.on_change:
|
if config_variable.name == key and config_variable.on_change:
|
||||||
config_variable.on_change()
|
config_variable.on_change()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def get_default(self, key):
|
||||||
|
"""
|
||||||
|
Returns the default value for 'key'.
|
||||||
|
"""
|
||||||
|
for receiver, config_page in config_signal.send(sender='get_default'):
|
||||||
|
for config_variable in config_page.variables:
|
||||||
|
if config_variable.name == key:
|
||||||
|
return config_variable.default_value
|
||||||
|
raise ConfigNotFound('The config variable %s was not found.' % key)
|
||||||
|
|
||||||
def setup_cache(self):
|
def setup_cache(self):
|
||||||
"""
|
"""
|
||||||
Loads all config variables from the database and by sending a
|
Loads all config variables from the database and by sending a
|
||||||
signal to get the default into the cache.
|
signal to get the default into the cache.
|
||||||
"""
|
"""
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
for receiver, config_page in config_signal.send(sender=self):
|
for receiver, config_page in config_signal.send(sender='setup_cache'):
|
||||||
for config_variable in config_page.variables:
|
for config_variable in config_page.variables:
|
||||||
if config_variable.name in self._cache:
|
if config_variable.name in self._cache:
|
||||||
raise ConfigError('Too many values for config variable %s found.' % config_variable.name)
|
raise ConfigError('Too many values for config variable %s found.' % config_variable.name)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Views for the projector app.
|
Views for the projector app.
|
||||||
|
|
||||||
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
:copyright: 2011–2013 by OpenSlides team, see AUTHORS.
|
||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -155,8 +155,8 @@ class ProjectorEdit(RedirectView):
|
|||||||
if config['up'] < 0:
|
if config['up'] < 0:
|
||||||
config['up'] = int(config['up']) + 5
|
config['up'] = int(config['up']) + 5
|
||||||
elif direction == 'clean':
|
elif direction == 'clean':
|
||||||
config['up'] = 0 # TODO: Use default value from the signal instead of fix value here
|
config['up'] = config.get_default('up')
|
||||||
config['bigger'] = 100 # TODO: Use default value from the signal instead of fix value here
|
config['bigger'] = config.get_default('bigger')
|
||||||
|
|
||||||
|
|
||||||
class CountdownEdit(RedirectView):
|
class CountdownEdit(RedirectView):
|
||||||
|
@ -89,6 +89,17 @@ class HandleConfigTest(TestCase):
|
|||||||
value='new_string_kbmbnfhdgibkdjshg452bc')
|
value='new_string_kbmbnfhdgibkdjshg452bc')
|
||||||
self.assertEqual(config['var_with_callback_ghvnfjd5768gdfkwg0hm2'], 'new_string_kbmbnfhdgibkdjshg452bc')
|
self.assertEqual(config['var_with_callback_ghvnfjd5768gdfkwg0hm2'], 'new_string_kbmbnfhdgibkdjshg452bc')
|
||||||
|
|
||||||
|
def test_get_default(self):
|
||||||
|
"""
|
||||||
|
Tests the methode 'default'.
|
||||||
|
"""
|
||||||
|
self.assertEqual(config.get_default('string_var'), 'default_string_rien4ooCZieng6ah')
|
||||||
|
self.assertRaisesMessage(
|
||||||
|
ConfigNotFound,
|
||||||
|
'The config variable unknown_var was not found.',
|
||||||
|
config.get_default,
|
||||||
|
'unknown_var')
|
||||||
|
|
||||||
|
|
||||||
class ConfigFormTest(TestCase):
|
class ConfigFormTest(TestCase):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user