Merge pull request #4586 from FinnStutzenstein/unsetFontOnDelete

Unset font if the mediafile is deleted
This commit is contained in:
Emanuel Schütze 2019-04-11 23:14:51 +02:00 committed by GitHub
commit 8072c26983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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)