Added clean methods to edit profile form
authorNishanth Amuluru <nishanth@fossee.in>
Sat, 08 Jan 2011 13:54:38 +0530
changeset 311 de27bb39375f
parent 310 c7fb9663c3a1
child 312 a8fbe291385c
Added clean methods to edit profile form
pytask/profile/forms.py
--- a/pytask/profile/forms.py	Sat Jan 08 12:31:53 2011 +0530
+++ b/pytask/profile/forms.py	Sat Jan 08 13:54:38 2011 +0530
@@ -91,3 +91,34 @@
     class Meta:
         model = Profile
         fields = ['full_name', 'aboutme', 'gender', 'dob', 'address', 'phonenum']
+
+    def clean_aboutme(self):
+        """ Empty not allowed """
+
+        data = self.cleaned_data['aboutme']
+        if not data.strip():
+            raise forms.ValidationError("Please write something about\
+                                        yourself")
+
+        return data
+
+    def clean_address(self):
+        """ Empty not allowed """
+
+        data = self.cleaned_data['address']
+        if not data.strip():
+            raise forms.ValidationError("Please enter an address")
+        
+        return data
+
+    def clean_phonenum(self):
+        """ should be of 10 digits """
+
+        data = self.cleaned_data['phonenum']
+
+        if (not data.strip()) or \
+           (data.strip("1234567890")) or \
+           (len(data)!= 10):
+               raise forms.ValidationError("This is not a valid phone number")
+
+        return data