Commit abb701f8335b554b9a9dd53f5ec55d97b7ef1ef3
1 parent
99cfa4de
Exists in
master
and in
2 other branches
Adjusting some issues with the crop feature
Showing
1 changed file
with
33 additions
and
0 deletions
Show diff stats
users/forms.py
... | ... | @@ -102,9 +102,25 @@ class RegisterUserForm(Validation): |
102 | 102 | |
103 | 103 | class ProfileForm(Validation): |
104 | 104 | is_edit = True |
105 | + #Cropping image | |
106 | + x = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
107 | + y = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
108 | + width = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
109 | + height = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
110 | + | |
105 | 111 | |
106 | 112 | def save(self, commit=True): |
107 | 113 | super(ProfileForm, self).save(commit=False) |
114 | + x = self.cleaned_data.get('x') | |
115 | + y = self.cleaned_data.get('y') | |
116 | + w = self.cleaned_data.get('width') | |
117 | + h = self.cleaned_data.get('height') | |
118 | + | |
119 | + if self.instance.image : | |
120 | + image = Image.open(self.instance.image) | |
121 | + cropped_image = image.crop((x, y, w+x, h+y)) | |
122 | + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
123 | + resized_image.save(self.instance.image.path) | |
108 | 124 | |
109 | 125 | self.instance.save() |
110 | 126 | |
... | ... | @@ -134,10 +150,27 @@ class UserForm(Validation): |
134 | 150 | new_password = forms.CharField(label = _('Password'), widget = forms.PasswordInput(render_value = True), required = False) |
135 | 151 | password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput(render_value = True), required = False) |
136 | 152 | |
153 | + #Cropping image | |
154 | + x = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
155 | + y = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
156 | + width = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
157 | + height = forms.FloatField(widget=forms.HiddenInput(),required=False) | |
137 | 158 | |
138 | 159 | def save(self, commit=True): |
139 | 160 | super(UserForm, self).save(commit=False) |
140 | 161 | |
162 | + x = self.cleaned_data.get('x') | |
163 | + y = self.cleaned_data.get('y') | |
164 | + w = self.cleaned_data.get('width') | |
165 | + h = self.cleaned_data.get('height') | |
166 | + | |
167 | + if self.instance.image : | |
168 | + image = Image.open(self.instance.image) | |
169 | + cropped_image = image.crop((x, y, w+x, h+y)) | |
170 | + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
171 | + resized_image.save(self.instance.image.path) | |
172 | + | |
173 | + | |
141 | 174 | if not self.is_edit or self.cleaned_data['new_password'] != '': |
142 | 175 | self.instance.set_password(self.cleaned_data['new_password']) |
143 | 176 | ... | ... |