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:
Oskar Hahn 2013-09-30 13:30:58 -07:00
commit 81319e746e
3 changed files with 26 additions and 5 deletions

View File

@ -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)

View File

@ -6,7 +6,7 @@
Views for the projector app.
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
:copyright: 20112013 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):

View File

@ -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):