Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	poetry.lock
  • Loading branch information
catgirlinspace committed Nov 11, 2024
2 parents 1dd7a05 + d3dc756 commit b8fdcc5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
7 changes: 3 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit b8fdcc5

Please sign in to comment.