Commit 55b5b879a21e1f26504631ee3f64c7903f33351d
1 parent
b532a620
Exists in
master
and in
2 other branches
Fix'd edit profile bug
Showing
1 changed file
with
32 additions
and
29 deletions
Show diff stats
users/forms.py
... | ... | @@ -81,18 +81,19 @@ class RegisterUserForm(Validation): |
81 | 81 | |
82 | 82 | if self.instance.image : |
83 | 83 | image = Image.open(self.instance.image) |
84 | - cropped_image = image.crop((x, y, w+x, h+y)) | |
85 | - resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
84 | + if not x is None: | |
85 | + cropped_image = image.crop((x, y, w+x, h+y)) | |
86 | + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
86 | 87 | |
87 | - folder_path = join(settings.MEDIA_ROOT, 'users') | |
88 | - #check if the folder already exists | |
89 | - if not os.path.isdir(folder_path): | |
90 | - os.makedirs(folder_path) | |
88 | + folder_path = join(settings.MEDIA_ROOT, 'users') | |
89 | + #check if the folder already exists | |
90 | + if not os.path.isdir(folder_path): | |
91 | + os.makedirs(folder_path) | |
91 | 92 | |
92 | - if ("users" not in self.instance.image.path): | |
93 | - self.deletepath = self.instance.image.path | |
93 | + if ("users" not in self.instance.image.path): | |
94 | + self.deletepath = self.instance.image.path | |
94 | 95 | |
95 | - resized_image.save(self.instance.image.path) | |
96 | + resized_image.save(self.instance.image.path) | |
96 | 97 | |
97 | 98 | self.instance.set_password(self.cleaned_data['new_password']) |
98 | 99 | |
... | ... | @@ -128,21 +129,22 @@ class ProfileForm(Validation): |
128 | 129 | y = self.cleaned_data.get('y') |
129 | 130 | w = self.cleaned_data.get('width') |
130 | 131 | h = self.cleaned_data.get('height') |
131 | - | |
132 | + | |
132 | 133 | if self.instance.image: |
133 | 134 | image = Image.open(self.instance.image) |
134 | - cropped_image = image.crop((x, y, w+x, h+y)) | |
135 | - resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
135 | + if not x is None: | |
136 | + cropped_image = image.crop((x, y, w+x, h+y)) | |
137 | + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
136 | 138 | |
137 | - folder_path = join(settings.MEDIA_ROOT, 'users') | |
138 | - #check if the folder already exists | |
139 | - if not os.path.isdir(folder_path): | |
140 | - os.makedirs(folder_path) | |
139 | + folder_path = join(settings.MEDIA_ROOT, 'users') | |
140 | + #check if the folder already exists | |
141 | + if not os.path.isdir(folder_path): | |
142 | + os.makedirs(folder_path) | |
141 | 143 | |
142 | - if ("users" not in self.instance.image.path): | |
143 | - self.deletepath = self.instance.image.path | |
144 | + if ("users" not in self.instance.image.path): | |
145 | + self.deletepath = self.instance.image.path | |
144 | 146 | |
145 | - resized_image.save(self.instance.image.path) | |
147 | + resized_image.save(self.instance.image.path) | |
146 | 148 | |
147 | 149 | self.instance.save() |
148 | 150 | if (self.deletepath): |
... | ... | @@ -181,7 +183,7 @@ class UserForm(Validation): |
181 | 183 | |
182 | 184 | def save(self, commit=True): |
183 | 185 | super(UserForm, self).save(commit=False) |
184 | - self.deletepath = "" | |
186 | + self.deletepath = "" | |
185 | 187 | |
186 | 188 | x = self.cleaned_data.get('x') |
187 | 189 | y = self.cleaned_data.get('y') |
... | ... | @@ -190,18 +192,19 @@ class UserForm(Validation): |
190 | 192 | |
191 | 193 | if self.instance.image : |
192 | 194 | image = Image.open(self.instance.image) |
193 | - cropped_image = image.crop((x, y, w+x, h+y)) | |
194 | - resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
195 | + if not x is None: | |
196 | + cropped_image = image.crop((x, y, w+x, h+y)) | |
197 | + resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS) | |
195 | 198 | |
196 | - folder_path = join(settings.MEDIA_ROOT, 'users') | |
197 | - #check if the folder already exists | |
198 | - if not os.path.isdir(folder_path): | |
199 | - os.makedirs(folder_path) | |
199 | + folder_path = join(settings.MEDIA_ROOT, 'users') | |
200 | + #check if the folder already exists | |
201 | + if not os.path.isdir(folder_path): | |
202 | + os.makedirs(folder_path) | |
200 | 203 | |
201 | - if ("users" not in self.instance.image.path): | |
202 | - self.deletepath = self.instance.image.path | |
204 | + if ("users" not in self.instance.image.path): | |
205 | + self.deletepath = self.instance.image.path | |
203 | 206 | |
204 | - resized_image.save(self.instance.image.path) | |
207 | + resized_image.save(self.instance.image.path) | |
205 | 208 | |
206 | 209 | |
207 | 210 | if not self.is_edit or self.cleaned_data['new_password'] != '': | ... | ... |