diff --git a/openslides/core/config.py b/openslides/core/config.py index be055244b..5b836cce1 100644 --- a/openslides/core/config.py +++ b/openslides/core/config.py @@ -60,7 +60,11 @@ class ConfigHandler: # Validate datatype and run validators. expected_type = INPUT_TYPE_MAPPING[config_variable.input_type] - if not isinstance(value, expected_type): + + # Try to convert value into the expected datatype + try: + value = expected_type(value) + except ValueError: raise ConfigError(_('Wrong datatype. Expected %s, got %s.') % (expected_type, type(value))) if config_variable.input_type == 'choice' and value not in map(lambda choice: choice['value'], config_variable.choices): raise ConfigError(_('Invalid input. Choice does not match.')) diff --git a/openslides/core/static/js/core.js b/openslides/core/static/js/core.js index 547656cfb..39e8c0362 100644 --- a/openslides/core/static/js/core.js +++ b/openslides/core/static/js/core.js @@ -250,7 +250,7 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core']) controller: 'ConfigCtrl', resolve: { configOption: function($http) { - return $http({ 'method': 'OPTIONS', 'url': '/rest/config/config/' }); + return $http({ 'method': 'OPTIONS', 'url': '/rest/core/config/' }); } } }) @@ -351,7 +351,7 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core']) string: 'text', integer: 'number', boolean: 'checkbox', - choice: 'radio', + choice: 'choice', }[type]; } @@ -363,8 +363,11 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core']) var field = $parse(iAttrs.field)($scope); var config = Config.get(field.key); $scope.type = getHtmlType(field.input_type); + if ($scope.type == 'choice') { + $scope.choices = field.choices; + } $scope.label = field.label; - $scope.id = 'field-' + field.id; + $scope.key = 'field-' + field.key; $scope.value = config.value; $scope.help_text = field.help_text; } @@ -433,12 +436,7 @@ angular.module('OpenSlidesApp.core.site', ['OpenSlidesApp.core']) $scope.configGroups = configOption.data.config_groups; // save changed config value - $scope.save = function(key, value, type) { - // TODO: find a better way to check the type without using of - // the extra parameter 'type' from template - if (type == 'number') { - value = parseInt(value); - } + $scope.save = function(key, value) { Config.get(key).value = value; Config.save(key); } diff --git a/openslides/core/static/templates/config-form-field.html b/openslides/core/static/templates/config-form-field.html index c5348732b..c49fdc249 100644 --- a/openslides/core/static/templates/config-form-field.html +++ b/openslides/core/static/templates/config-form-field.html @@ -2,10 +2,15 @@