Unset font if the mediafile is deleted

This commit is contained in:
FinnStutzenstein 2019-04-09 19:38:01 +02:00
parent f54360290f
commit 648aabc310

View File

@ -77,12 +77,21 @@ class MediafileViewSet(ModelViewSet):
# on server via Django methods (file, open(), save(), ...). # on server via Django methods (file, open(), save(), ...).
mediafile = self.get_object() mediafile = self.get_object()
mediafile.mediafile.storage.delete(mediafile.mediafile.name) mediafile.mediafile.storage.delete(mediafile.mediafile.name)
# check if the file was used as a logo or font
for logo in config["logos_available"]: for logo in config["logos_available"]:
if config[logo]["path"] == mediafile.mediafile.url: if config[logo]["path"] == mediafile.mediafile.url:
config[logo] = { config[logo] = {
"display_name": config[logo]["display_name"], "display_name": config[logo]["display_name"],
"path": "", "path": "",
} }
for font in config["fonts_available"]:
if config[font]["path"] == mediafile.mediafile.url:
config[font] = {
"display_name": config[font]["display_name"],
"default": config[font]["default"],
"path": "",
}
return super().destroy(request, *args, **kwargs) return super().destroy(request, *args, **kwargs)