Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ro_help/hub/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from io import BytesIO

from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from django_crispy_bulma.widgets import EmailInput
from django.core.files.uploadedfile import InMemoryUploadedFile
from PIL import Image

from hub import models
from captcha.fields import ReCaptchaField
Expand Down Expand Up @@ -79,6 +83,21 @@ class Meta:
# "statute": AdminResubmitFileWidget,
}

def clean_avatar(self):
avatar = self.cleaned_data["avatar"]

im = Image.open(avatar)
thumb_io = BytesIO()

im.thumbnail((200, 200), Image.LANCZOS)
im.save(thumb_io, avatar.content_type.split("/")[-1].upper())

file = InMemoryUploadedFile(
thumb_io, "avatar", str(avatar), avatar.content_type, thumb_io.getbuffer().nbytes, None,
)

return file


class RegisterNGORequestVoteForm(forms.ModelForm):
class Meta:
Expand Down