mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
convert uploaded images to webp
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
import mimetypes
|
||||
from urllib.parse import quote, urljoin
|
||||
|
||||
# This file contains all the views that concern the page model
|
||||
@ -77,7 +78,7 @@ def send_file(
|
||||
raise Http404
|
||||
with open(filepath, "rb") as filename:
|
||||
response.content = FileWrapper(filename)
|
||||
response["Content-Type"] = f.mime_type
|
||||
response["Content-Type"] = mimetypes.guess_type(filepath)[0]
|
||||
response["Last-Modified"] = http_date(f.date.timestamp())
|
||||
response["Content-Length"] = filepath.stat().st_size
|
||||
return response
|
||||
|
@ -239,10 +239,6 @@ class UserProfileForm(forms.ModelForm):
|
||||
"quote": forms.Textarea,
|
||||
}
|
||||
|
||||
def generate_name(self, field_name, f):
|
||||
field_name = field_name[:-4]
|
||||
return field_name + str(self.instance.id) + "." + f.content_type.split("/")[-1]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@ -278,11 +274,11 @@ class UserProfileForm(forms.ModelForm):
|
||||
im = Image.open(BytesIO(f.read()))
|
||||
new_file = SithFile(
|
||||
parent=parent,
|
||||
name=self.generate_name(field, f),
|
||||
file=resize_image(im, 400, f.content_type.split("/")[-1]),
|
||||
name=f"{field.removesuffix('_pict')}_{self.instance.id}.webp",
|
||||
file=resize_image(im, 400, "webp"),
|
||||
owner=self.instance,
|
||||
is_folder=False,
|
||||
mime_type=f.content_type,
|
||||
mime_type="image/wepb",
|
||||
size=f.size,
|
||||
moderator=self.instance,
|
||||
is_moderated=True,
|
||||
|
Reference in New Issue
Block a user