reg/forms.py
changeset 18 7dae32a2439b
parent 17 125b6fc8f20b
child 22 737ec98cf6df
--- a/reg/forms.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/forms.py	Mon Apr 12 18:15:21 2010 +0530
@@ -46,6 +46,24 @@
         model = Profile
         fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
 
+    def clean_first_name(self):
+        """ firstname should contain only alphabets.
+        """
+
+        first_name = self.cleaned_data['first_name']
+        if first_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return first_name
+
+    def clean_last_name(self):
+        """ only alphabets allowed.
+        """
+
+        last_name = self.cleaned_data['last_name']
+        if last_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return last_name
+
     def clean_email(self):
         """ check if a user exists with same email.
         """
@@ -97,10 +115,8 @@
         """
 
         stop_date = self.cleaned_data['stop_date']
-        try:
-            start_date = datetime.strptime(self.data['start_date'], "%Y-%m-%d").date()
-        except ValueError:
-            raise forms.ValidationError("Enter a valid date")
+
+        start_date = self.clean_start_date()
 
         if start_date > stop_date:
             raise forms.ValidationError('The event stops even before it starts. I am starting to wonder what kind of event is this.')
@@ -157,6 +173,8 @@
         if not new_password == self.data['confirm_password']:
             raise forms.ValidationError("Passwords do not match")
 
+        return new_password
+
 class EditProfileForm(forms.Form):
     """ form for editing the profile.
     """
@@ -168,4 +186,22 @@
     affiliated_to = forms.CharField(max_length=100, required=True, label="College/Company")
     interests = forms.CharField(max_length=100, label="Fields of interest")
 
+    def clean_first_name(self):
+        """ firstname should contain only alphabets.
+        """
 
+        first_name = self.cleaned_data['first_name']
+        if first_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return first_name
+
+    def clean_last_name(self):
+        """ only alphabets allowed.
+        """
+
+        last_name = self.cleaned_data['last_name']
+        if last_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return last_name
+
+