Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions backend/management/commands/update.py
Original file line number Diff line number Diff line change
@@ -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 <backend_slug> <key> <value>\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
1 change: 1 addition & 0 deletions backend/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ <h4>Basic settings</h4>
<tr><th>Backend name</th><td>{{ backend.name }}</td></tr>
<tr><th>Backend slug</th><td id="backend-slug">{{ backend.slugify }}</td></tr>
<tr><th>Backend URL</th><td>{{ backend.baseUrl }}</td></tr>
{% if backend.mapViewBaseURL != "" %}<tr><th>Petrimaps URL</th><td>{{ backend.mapViewBaseURL }}</td></tr>{% endif %}
<tr><th>Is default:</th><td>{% if backend.isDefault %}Yes{% else %}No{% endif %}</td></tr>
<tr><th>Fill known prefixes:</th><td>{% if backend.fillPrefixes %}Yes{% else %}No{% endif %}</td></tr>
<tr><th>Languages:</th><td>{{ backend.filteredLanguage }}</td></tr>
Expand Down