pytask/profile/forms.py
changeset 311 de27bb39375f
parent 307 c6bca38c1cbf
child 312 a8fbe291385c
equal deleted inserted replaced
310:c7fb9663c3a1 311:de27bb39375f
    89 class EditProfileForm(forms.ModelForm):
    89 class EditProfileForm(forms.ModelForm):
    90 
    90 
    91     class Meta:
    91     class Meta:
    92         model = Profile
    92         model = Profile
    93         fields = ['full_name', 'aboutme', 'gender', 'dob', 'address', 'phonenum']
    93         fields = ['full_name', 'aboutme', 'gender', 'dob', 'address', 'phonenum']
       
    94 
       
    95     def clean_aboutme(self):
       
    96         """ Empty not allowed """
       
    97 
       
    98         data = self.cleaned_data['aboutme']
       
    99         if not data.strip():
       
   100             raise forms.ValidationError("Please write something about\
       
   101                                         yourself")
       
   102 
       
   103         return data
       
   104 
       
   105     def clean_address(self):
       
   106         """ Empty not allowed """
       
   107 
       
   108         data = self.cleaned_data['address']
       
   109         if not data.strip():
       
   110             raise forms.ValidationError("Please enter an address")
       
   111         
       
   112         return data
       
   113 
       
   114     def clean_phonenum(self):
       
   115         """ should be of 10 digits """
       
   116 
       
   117         data = self.cleaned_data['phonenum']
       
   118 
       
   119         if (not data.strip()) or \
       
   120            (data.strip("1234567890")) or \
       
   121            (len(data)!= 10):
       
   122                raise forms.ValidationError("This is not a valid phone number")
       
   123 
       
   124         return data