From 55b5b879a21e1f26504631ee3f64c7903f33351d Mon Sep 17 00:00:00 2001 From: Gustavo Date: Wed, 12 Apr 2017 14:14:03 -0300 Subject: [PATCH] Fix'd edit profile bug --- users/forms.py | 61 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/users/forms.py b/users/forms.py index 16e337a..2ac8132 100644 --- a/users/forms.py +++ b/users/forms.py @@ -81,18 +81,19 @@ class RegisterUserForm(Validation): if self.instance.image : 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) + if not x is None: + cropped_image = image.crop((x, y, w+x, h+y)) + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) - folder_path = join(settings.MEDIA_ROOT, 'users') - #check if the folder already exists - if not os.path.isdir(folder_path): - os.makedirs(folder_path) + folder_path = join(settings.MEDIA_ROOT, 'users') + #check if the folder already exists + if not os.path.isdir(folder_path): + os.makedirs(folder_path) - if ("users" not in self.instance.image.path): - self.deletepath = self.instance.image.path + if ("users" not in self.instance.image.path): + self.deletepath = self.instance.image.path - resized_image.save(self.instance.image.path) + resized_image.save(self.instance.image.path) self.instance.set_password(self.cleaned_data['new_password']) @@ -128,21 +129,22 @@ class ProfileForm(Validation): y = self.cleaned_data.get('y') w = self.cleaned_data.get('width') h = self.cleaned_data.get('height') - + if self.instance.image: 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) + if not x is None: + cropped_image = image.crop((x, y, w+x, h+y)) + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) - folder_path = join(settings.MEDIA_ROOT, 'users') - #check if the folder already exists - if not os.path.isdir(folder_path): - os.makedirs(folder_path) + folder_path = join(settings.MEDIA_ROOT, 'users') + #check if the folder already exists + if not os.path.isdir(folder_path): + os.makedirs(folder_path) - if ("users" not in self.instance.image.path): - self.deletepath = self.instance.image.path + if ("users" not in self.instance.image.path): + self.deletepath = self.instance.image.path - resized_image.save(self.instance.image.path) + resized_image.save(self.instance.image.path) self.instance.save() if (self.deletepath): @@ -181,7 +183,7 @@ class UserForm(Validation): def save(self, commit=True): super(UserForm, self).save(commit=False) - self.deletepath = "" + self.deletepath = "" x = self.cleaned_data.get('x') y = self.cleaned_data.get('y') @@ -190,18 +192,19 @@ class UserForm(Validation): if self.instance.image : 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) + if not x is None: + cropped_image = image.crop((x, y, w+x, h+y)) + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) - folder_path = join(settings.MEDIA_ROOT, 'users') - #check if the folder already exists - if not os.path.isdir(folder_path): - os.makedirs(folder_path) + folder_path = join(settings.MEDIA_ROOT, 'users') + #check if the folder already exists + if not os.path.isdir(folder_path): + os.makedirs(folder_path) - if ("users" not in self.instance.image.path): - self.deletepath = self.instance.image.path + if ("users" not in self.instance.image.path): + self.deletepath = self.instance.image.path - resized_image.save(self.instance.image.path) + resized_image.save(self.instance.image.path) if not self.is_edit or self.cleaned_data['new_password'] != '': -- libgit2 0.21.2