diff --git a/backend/settings.py b/backend/settings.py index ef97dc9..e616bb5 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -5,7 +5,7 @@ Getting and setting settings """ import logging -from json import dumps, loads +from json import dump, load from typing import Any from backend.custom_exceptions import InvalidKeyValue, KeyNotFound @@ -67,7 +67,10 @@ def _format_setting(key: str, value): if not isinstance(value, str): raise InvalidKeyValue(key, value) - if value: + if value == '/': + value = '' + + elif value: value = '/' + value.strip('/') elif key == 'log_level' and not value in (logging.INFO, logging.DEBUG): @@ -171,12 +174,16 @@ def update_manifest(url_base: str) -> None: Args: url_base (str): The url base to use in the file. """ - with open(folder_path('frontend', 'static', 'json', 'pwa_manifest.json'), 'r+') as f: - manifest = loads(f.read()) + filename = folder_path('frontend', 'static', 'json', 'pwa_manifest.json') + + with open(filename, 'r') as f: + manifest = load(f) manifest['start_url'] = url_base + '/' manifest['icons'][0]['src'] = f'{url_base}/static/img/favicon.svg' - f.seek(0) - f.write(dumps(manifest, indent=4)) + + with open(filename, 'w') as f: + dump(manifest, f, indent=4) + return def backup_hosting_settings() -> None: @@ -228,5 +235,7 @@ def restore_hosting_settings() -> None: "UPDATE config SET value = ? WHERE key = ?", ((v, k) for k, v in hosting_settings.items()) ) - + + update_manifest(hosting_settings['url_prefix']) + return