pwa: use icon file basename during import (#53720)

Django 2.2.21 introduced the validation of FieldFile.save() name
argument, which cannot contain a path separator anymore. To use the
received FileField value as a base filename, we must apply
os.path.basename() on it first.

ref. https://docs.djangoproject.com/en/3.2/releases/2.2.21/
This commit is contained in:
Benjamin Dauvergne 2021-05-04 14:15:30 +02:00
parent d623ff4d8e
commit 428033da0f
1 changed files with 2 additions and 1 deletions

View File

@ -18,6 +18,7 @@
import base64
import json
import os
from django.conf import settings
from django.core import serializers
@ -188,7 +189,7 @@ class PwaNavigationEntry(models.Model):
decoded_icon = base64.decodebytes(force_bytes(json_entry['icon:base64']))
if not default_storage.exists(entry.object.icon.name) or entry.object.icon.read() != decoded_icon:
# save new file
entry.object.icon.save(entry.object.icon.name, ContentFile(decoded_icon))
entry.object.icon.save(os.path.basename(entry.object.icon.name), ContentFile(decoded_icon))
class PushSubscription(models.Model):