2016-09-18 13:17:21 +02:00
|
|
|
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."
|
2016-09-18 13:17:21 +02:00
|
|
|
|
|
|
|
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."
|
2016-09-18 13:17:21 +02:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
2019-01-06 16:22:33 +01:00
|
|
|
"value", help='New config value. For a falsy boolean use "False".'
|
2016-09-18 13:17:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2019-01-06 16:22:33 +01:00
|
|
|
if options["value"].lower() == "false":
|
|
|
|
options["value"] = False
|
2016-09-18 13:17:21 +02:00
|
|
|
try:
|
2019-01-06 16:22:33 +01:00
|
|
|
config[options["key"]] = options["value"]
|
2016-09-18 13:17:21 +02:00
|
|
|
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
|
|
|
)
|
|
|
|
)
|