diff --git a/backend/management/commands/update.py b/backend/management/commands/update.py new file mode 100644 index 0000000..f7eeee3 --- /dev/null +++ b/backend/management/commands/update.py @@ -0,0 +1,38 @@ +from django.core.management.base import BaseCommand, CommandError +from backend.models import Backend + +class Command(BaseCommand): + help = ("Usage: python manage.py update \n" + "\n" + "Update key/value in database.") + + # Copied from warmup.py, is this really needed? + def __init__(self, *args, **kwargs): + super().__init__( *args, **kwargs) + + # Custom log function. + def log(self, msg=""): + print(msg) + + # Command line arguments. + def add_arguments(self, parser): + parser.add_argument("backend_slug", nargs=1, + help="Slug of the selected backend") + parser.add_argument("key", nargs=1, + help="Key to update") + parser.add_argument("value", nargs=1, + help="New value to set") + + def handle(self, *args, returnLog=False, **options): + backend_slug = options["backend_slug"][0] + key = options["key"][0] + value = options["value"][0] + + self.log(f"Update database: set {key} to {value} ...") + try: + backend = Backend.objects.filter(slug=backend_slug).get() + setattr(backend, key, value) + backend.save() + except Exception as e: + self.log(f"ERROR: {e}") + return diff --git a/backend/templates/index.html b/backend/templates/index.html index b97aa97..1779f00 100644 --- a/backend/templates/index.html +++ b/backend/templates/index.html @@ -86,6 +86,7 @@

Basic settings

Backend name{{ backend.name }} Backend slug{{ backend.slugify }} Backend URL{{ backend.baseUrl }} + {% if backend.mapViewBaseURL != "" %}Petrimaps URL{{ backend.mapViewBaseURL }}{% endif %} Is default:{% if backend.isDefault %}Yes{% else %}No{% endif %} Fill known prefixes:{% if backend.fillPrefixes %}Yes{% else %}No{% endif %} Languages:{{ backend.filteredLanguage }}