summaryrefslogtreecommitdiff
path: root/taskapp/forms
diff options
context:
space:
mode:
authornishanth2010-03-05 15:13:37 +0530
committernishanth2010-03-05 15:13:37 +0530
commit582567182ce90f31ccf86e6eb432c8cabdffa32c (patch)
treee56cfd7cfc2889f1a84263a8c4eefedefd94b38f /taskapp/forms
parent41ba7417291d681d76621ceecfc9e5191c46c009 (diff)
downloadpytask-582567182ce90f31ccf86e6eb432c8cabdffa32c.tar.gz
pytask-582567182ce90f31ccf86e6eb432c8cabdffa32c.tar.bz2
pytask-582567182ce90f31ccf86e6eb432c8cabdffa32c.zip
now user profile editing is done thro forms in a more elegant way.
Diffstat (limited to 'taskapp/forms')
-rw-r--r--taskapp/forms/user.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/taskapp/forms/user.py b/taskapp/forms/user.py
index fe2121e..fe81536 100644
--- a/taskapp/forms/user.py
+++ b/taskapp/forms/user.py
@@ -1,5 +1,10 @@
#!/usr/bin/python2.5
+import os
+import PIL
+
+from pytask.taskapp.utilities.helper import get_key
+
from django import forms
from pytask.taskapp.models import GENDER_CHOICES, Profile
from registration.forms import RegistrationFormUniqueEmail
@@ -12,6 +17,28 @@ class UserProfileEditForm(forms.ModelForm):
model = Profile
exclude = ('user','rights','dob','credits')
+ def clean_photo(self):
+ uploaded_photo = self.data.get('photo', None)
+ prev_photo = self.instance.photo
+ if uploaded_photo:
+ if uploaded_photo.size > 1048576:
+ raise forms.ValidationError('Images only smaller than 1MB allowed')
+ tmp_im_path = '/tmp/'+get_key()
+ tmp_file = open(tmp_im_path, 'w')
+ tmp_file.write(uploaded_photo.read())
+ tmp_file.close()
+ try:
+ PIL.Image.open(tmp_im_path)
+ except IOError:
+ raise forms.ValidationError('Image format unknown')
+ os.remove(tmp_im_path)
+
+ if prev_photo: os.remove(prev_photo.path)
+ return uploaded_photo
+ else:
+ return prev_photo
+
+
class RegistrationFormCustom(RegistrationFormUniqueEmail):
"""Used instead of RegistrationForm used by default django-registration backend, this adds date of birth and gender to the default django-registration RegistrationForm"""