Merge pull request #6123 from FinnStutzenstein/fixDeletionOfMediafiles

Fix updating logo and font configs when deleting a mediafile
This commit is contained in:
Emanuel Schütze 2021-06-23 16:29:45 +02:00 committed by GitHub
commit c286e0ff76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,32 +23,31 @@ def watch_and_update_configs():
def build_mapping(base_config_key, mediafiles):
"""Returns a map of config keys to medaifile ids"""
logos = {}
"""Returns a map of config keys to mediafile ids"""
mapping = {}
for key in config[base_config_key]:
url = config[key]["path"]
for mediafile in mediafiles:
if mediafile.url == url:
logos[key] = mediafile.id
mapping[key] = mediafile.id
break
return logos
return mapping
def update_mapping(mapping, mediafiles):
"""
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
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():
config_value = config[key]
try:
mediafile = mediafiles.filter(pk=id)[0]
print(config[key]["path"], mediafile.url)
if config[key]["path"] != mediafile.url:
config[key] = {
"display_name": config[key]["display_name"],
"path": mediafile.url,
}
if config_value["path"] != mediafile.url:
config_value["path"] = mediafile.url
config[key] = config_value
except IndexError:
config[key] = {"display_name": config[key]["display_name"], "path": ""}
config_value["path"] = ""
config[key] = config_value