diff --git a/amadeus/templates/base.html b/amadeus/templates/base.html index e8f7476..6c1670e 100644 --- a/amadeus/templates/base.html +++ b/amadeus/templates/base.html @@ -30,6 +30,10 @@ + + + + diff --git a/users/forms.py b/users/forms.py index 8c5f5c6..6262778 100644 --- a/users/forms.py +++ b/users/forms.py @@ -8,6 +8,8 @@ from django.core.validators import validate_email from django.core.exceptions import ValidationError from resubmit.widgets import ResubmitFileWidget +from PIL import Image + from .models import User @@ -60,9 +62,26 @@ class RegisterUserForm(Validation): is_edit = False + #Cropping image + x = forms.FloatField(widget=forms.HiddenInput()) + y = forms.FloatField(widget=forms.HiddenInput()) + width = forms.FloatField(widget=forms.HiddenInput()) + height = forms.FloatField(widget=forms.HiddenInput()) + + def save(self, commit=True): super(RegisterUserForm, self).save(commit=False) + x = self.cleaned_data.get('x') + y = self.cleaned_data.get('y') + w = self.cleaned_data.get('width') + h = self.cleaned_data.get('height') + + image = Image.open(self.instance.image) + cropped_image = image.crop((x, y, w+x, h+y)) + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) + resized_image.save(self.instance.image.path) + self.instance.set_password(self.cleaned_data['new_password']) self.instance.save() @@ -71,7 +90,7 @@ class RegisterUserForm(Validation): class Meta: model = User - fields = ['email', 'username', 'last_name', 'social_name', 'image', 'show_email', ] + fields = ['email', 'username', 'last_name', 'social_name', 'image', 'show_email', 'x', 'y', 'width', 'height',] widgets = { 'email': forms.EmailInput(attrs = {'placeholder': _('Email') + ' *'}), 'username': forms.TextInput(attrs = {'placeholder': _('Name') + ' *'}), diff --git a/users/templates/users/register.html b/users/templates/users/register.html index fdcc2c9..79a1afa 100644 --- a/users/templates/users/register.html +++ b/users/templates/users/register.html @@ -12,6 +12,69 @@ {% block sidebar %} {% endblock sidebar %} +{% block javascript %} + + +{% endblock javascript %} + + + + {% block content %}