diff --git a/poetry.lock b/poetry.lock index 7a59706..ea1a7b4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2676,13 +2676,13 @@ doc = ["sphinx"] [[package]] name = "strawberry-graphql" -version = "0.237.3" +version = "0.243.1" description = "A library for creating GraphQL APIs" optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "strawberry_graphql-0.237.3-py3-none-any.whl", hash = "sha256:2dc43a5036995edf614d21c9faca8b6848a09353d167ae05f42a9d0e976e1611"}, - {file = "strawberry_graphql-0.237.3.tar.gz", hash = "sha256:8e04bb8821b303cb2cbd2c981f211b2d61bd21e3d171a638d93ceb99081194ac"}, + {file = "strawberry_graphql-0.243.1-py3-none-any.whl", hash = "sha256:7c4ddb97cd424fa23a540816cb169ef760822c9acfb63901e6717042bcda6cfe"}, + {file = "strawberry_graphql-0.243.1.tar.gz", hash = "sha256:0ef8b0b100cb0ebd25eea1723105166625820b18d075e4f7cae744468b81d23e"}, ] [package.dependencies] @@ -2707,7 +2707,6 @@ pydantic = ["pydantic (>1.6.1)"] pyinstrument = ["pyinstrument (>=4.0.0)"] quart = ["quart (>=0.19.3)"] sanic = ["sanic (>=20.12.2)"] -starlite = ["starlite (>=1.48.0)"] [[package]] name = "strawberry-graphql-django" diff --git a/pyproject.toml b/pyproject.toml index 963493f..37969f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ asgiref = {git = "https://github.com/django/asgiref.git"} django-choices-field = "^2.2.2" django-cors-headers = "^4.3.1" stripe = "^10.12.0" -strawberry-graphql = "^0.237.3" +strawberry-graphql = "^0.243.1" strawberry-persisted-queries = "^1.0.3" qrcode = "^7.4.2" uuid = "^1.30" diff --git a/users/models.py b/users/models.py index 2512485..d3ab4ba 100644 --- a/users/models.py +++ b/users/models.py @@ -5,6 +5,9 @@ from enum import Enum from io import BytesIO import re +from PIL import Image, ImageOps +import io +from uuid import uuid4 import requests from django.contrib.auth.models import AbstractUser @@ -100,6 +103,30 @@ class User(AbstractUser): coral_friend_url = models.URLField(_("Nintendo Switch Online app friend URL"), blank=True, null=True, validators=[URLValidator( regex=r"^https:\/\/lounge\.nintendo\.com\/friendcode\/\d{4}-\d{4}-\d{4}\/[A-Za-z0-9]{10}$")]) + + def save(self, *args, **kwargs): + for field_name in ['profile_picture', 'profile_cover', 'page_background']: + image = getattr(self, field_name) + if image and hasattr(image, 'name'): + try: + with Image.open(image) as img: + img = ImageOps.exif_transpose(img) + + img_no_exif = Image.new(img.mode, img.size) + img_no_exif.putdata(list(img.getdata())) + + buffer = io.BytesIO() + + output_format = 'JPEG' + img_no_exif.save(buffer, format=output_format) + buffer.seek(0) + + new_filename = f"{uuid4()}.{output_format.lower()}" + image.save(new_filename, ContentFile(buffer.read()), save=False) + except Exception as e: + print(f"Error processing image for {field_name}: {e}") + + super().save(*args, **kwargs) @property def entitlements(self):