OpenSlides/openslides/core/management/commands/changeconfig.py

34 lines
1.0 KiB
Python
Raw Normal View History

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.
"""
2019-01-06 16:22:33 +01:00
help = "Changes OpenSlides config values."
def add_arguments(self, parser):
parser.add_argument(
2019-01-06 16:22:33 +01:00
"key", help="Config key. See config_variables.py in every app."
)
parser.add_argument(
2019-01-06 16:22:33 +01:00
"value", help='New config value. For a falsy boolean use "False".'
)
def handle(self, *args, **options):
2019-01-06 16:22:33 +01:00
if options["value"].lower() == "false":
options["value"] = False
try:
2019-01-06 16:22:33 +01:00
config[options["key"]] = options["value"]
except (ConfigError, ConfigNotFound) as e:
raise CommandError(str(e))
self.stdout.write(
2019-01-06 16:22:33 +01:00
self.style.SUCCESS(
2019-01-12 23:01:42 +01:00
f"Config {options['key']} successfully changed to {config[options['key']]}."
2019-01-06 16:22:33 +01:00
)
)