From 00913a6333bfd9851c19c325b6a078ed0f33dd94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sun, 18 Sep 2016 13:17:21 +0200 Subject: [PATCH] Added management command to change config values. Fixed #2400. --- .../core/management/commands/changeconfig.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 openslides/core/management/commands/changeconfig.py diff --git a/openslides/core/management/commands/changeconfig.py b/openslides/core/management/commands/changeconfig.py new file mode 100644 index 000000000..aa93afdfa --- /dev/null +++ b/openslides/core/management/commands/changeconfig.py @@ -0,0 +1,32 @@ +from django.core.management.base import BaseCommand, CommandError + +from openslides.core.config import config +from openslides.core.exceptions import ConfigError, ConfigNotFound + + +class Command(BaseCommand): + """ + Command to change OpenSlides config values. + """ + help = 'Changes OpenSlides config values.' + + def add_arguments(self, parser): + parser.add_argument( + 'key', + help='Config key. See config_variables.py in every app.' + ) + parser.add_argument( + 'value', + help='New config value. For a falsy boolean use "False".' + ) + + def handle(self, *args, **options): + if options['value'].lower() == 'false': + options['value'] = False + try: + config[options['key']] = options['value'] + except (ConfigError, ConfigNotFound) as e: + raise CommandError(str(e)) + self.stdout.write( + self.style.SUCCESS('Config {key} successfully changed to {value}.'.format( + key=options['key'], value=config[options['key']])))