Fix updating logo and font configs when deleting a mediafile

This commit is contained in:
Finn Stutzenstein 2021-06-21 07:46:13 +02:00
parent 382fcf4a67
commit 8423433f66
No known key found for this signature in database
GPG Key ID: 9042F605C6324654

View File

@ -23,32 +23,31 @@ def watch_and_update_configs():
def build_mapping(base_config_key, mediafiles): def build_mapping(base_config_key, mediafiles):
"""Returns a map of config keys to medaifile ids""" """Returns a map of config keys to mediafile ids"""
logos = {} mapping = {}
for key in config[base_config_key]: for key in config[base_config_key]:
url = config[key]["path"] url = config[key]["path"]
for mediafile in mediafiles: for mediafile in mediafiles:
if mediafile.url == url: if mediafile.url == url:
logos[key] = mediafile.id mapping[key] = mediafile.id
break break
return logos return mapping
def update_mapping(mapping, mediafiles): def update_mapping(mapping, mediafiles):
""" """
Tries to get the mediafile from the id for a specific config field. Tries to get the mediafile from the id for a specific config field.
If the file was found and the path changed, the config is updated. If the If the file was found and the path changed, the config is updated. If the
mediafile cound not be found, the config is cleared (mediafile deleted). mediafile could not be found, the config is cleared (mediafile deleted).
""" """
for key, id in mapping.items(): for key, id in mapping.items():
config_value = config[key]
try: try:
mediafile = mediafiles.filter(pk=id)[0] mediafile = mediafiles.filter(pk=id)[0]
print(config[key]["path"], mediafile.url) if config_value["path"] != mediafile.url:
if config[key]["path"] != mediafile.url: config_value["path"] = mediafile.url
config[key] = { config[key] = config_value
"display_name": config[key]["display_name"],
"path": mediafile.url,
}
except IndexError: except IndexError:
config[key] = {"display_name": config[key]["display_name"], "path": ""} config_value["path"] = ""
config[key] = config_value