diff --git a/openslides/core/config.py b/openslides/core/config.py index 22752ee42..512718207 100644 --- a/openslides/core/config.py +++ b/openslides/core/config.py @@ -77,9 +77,10 @@ class ConfigHandler: raise ConfigError(e.messages[0]) # Save the new value to the database. - updated_rows = ConfigStore.objects.filter(key=key).update(value=value) - if not updated_rows: - ConfigStore.objects.create(key=key, value=value) + config_store, created = ConfigStore.objects.get_or_create(key=key, defaults={'value': value}) + if not created: + config_store.value = value + config_store.save() # Update cache. if hasattr(self, '_cache'): diff --git a/openslides/core/models.py b/openslides/core/models.py index e860cfdea..31e9c16f3 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -1,5 +1,6 @@ from django.conf import settings from django.contrib.contenttypes.models import ContentType +from django.core.urlresolvers import reverse from django.db import models from django.utils.translation import ugettext_noop from jsonfield import JSONField @@ -198,6 +199,12 @@ class ConfigStore(models.Model): permissions = ( ('can_manage_config', ugettext_noop('Can manage configuration')),) + def get_root_rest_url(self): + """ + Returns the detail url of config value. + """ + return reverse('config-detail', args=[str(self.key)]) + class ChatMessage(RESTModelMixin, models.Model): """ diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index f5b97d411..0afcce9ef 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -343,6 +343,11 @@ angular.module('OpenSlidesApp.core.site', [ $scope.key = 'field-' + field.key; $scope.value = config.value; $scope.help_text = field.help_text; + $scope.default_value = field.default_value; + $scope.reset = function () { + $scope.value = $scope.default_value; + $scope.save(field.key, $scope.value); + } } }; }) diff --git a/openslides/core/static/templates/config-form-field.html b/openslides/core/static/templates/config-form-field.html index 12614798a..b8302b299 100644 --- a/openslides/core/static/templates/config-form-field.html +++ b/openslides/core/static/templates/config-form-field.html @@ -2,18 +2,27 @@