Some templating and add webcam support for profile editing

This commit is contained in:
Skia
2016-08-22 02:56:27 +02:00
parent 4cbfd58660
commit 8e3eb1e2bf
12 changed files with 551 additions and 52 deletions

View File

@ -83,26 +83,10 @@ class RegisteringForm(UserCreationForm):
user.save()
return user
# Image utils
from core.utils import resize_image
from io import BytesIO
from PIL import Image
def scale_dimension(width, height, long_edge):
if width > height:
ratio = long_edge * 1. / width
else:
ratio = long_edge * 1. / height
return int(width * ratio), int(height * ratio)
def resize_image(im, edge, format):
from django.core.files.base import ContentFile
(w, h) = im.size
(width, height) = scale_dimension(w, h, long_edge=edge)
content = BytesIO()
im.resize((width, height), Image.ANTIALIAS).save(fp=content, format=format, dpi=[72, 72])
return ContentFile(content.getvalue())
class UserProfileForm(forms.ModelForm):
"""
Form handling the user profile, managing the files