Added Feature for config app, to return the default value for a key
This commit is contained in:
parent
4bd40f9764
commit
6926630d3e
@ -45,19 +45,29 @@ class ConfigHandler(object):
|
||||
pass
|
||||
|
||||
# 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:
|
||||
if config_variable.name == key and config_variable.on_change:
|
||||
config_variable.on_change()
|
||||
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):
|
||||
"""
|
||||
Loads all config variables from the database and by sending a
|
||||
signal to get the default into the 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:
|
||||
if config_variable.name in self._cache:
|
||||
raise ConfigError('Too many values for config variable %s found.' % config_variable.name)
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
@ -155,8 +155,8 @@ class ProjectorEdit(RedirectView):
|
||||
if config['up'] < 0:
|
||||
config['up'] = int(config['up']) + 5
|
||||
elif direction == 'clean':
|
||||
config['up'] = 0 # TODO: Use default value from the signal instead of fix value here
|
||||
config['bigger'] = 100 # TODO: Use default value from the signal instead of fix value here
|
||||
config['up'] = config.get_default('up')
|
||||
config['bigger'] = config.get_default('bigger')
|
||||
|
||||
|
||||
class CountdownEdit(RedirectView):
|
||||
|
@ -89,6 +89,17 @@ class HandleConfigTest(TestCase):
|
||||
value='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):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user