# HG changeset patch # User Nishanth Amuluru # Date 1294475078 -19800 # Node ID de27bb39375fc2948ad1d66ebf92a1ac9252e373 # Parent c7fb9663c3a10863d15bce49c61cf845653d45b0 Added clean methods to edit profile form diff -r c7fb9663c3a1 -r de27bb39375f 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