reg/forms.py
author nishanth
Fri, 23 Apr 2010 16:36:40 +0530
changeset 99 cc2ed87ee896
parent 62 b7e47cc39342
permissions -rwxr-xr-x
resolved a bug
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
     1
import string
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
     2
from datetime import datetime
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
     3
7
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
     4
from django import forms
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
     5
from django.contrib.auth.models import User
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
     6
from django.contrib.auth import authenticate
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
     7
62
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 43
diff changeset
     8
from ws_app.reg.models import Profile, Event, GENDER_CHOICES, PROFESSION_CHOICES
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
     9
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    10
class LoginForm(forms.Form):
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    11
    """ a form to handle login.
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    12
    """
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    13
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    14
    email = forms.EmailField()
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    15
    password = forms.CharField(widget=forms.PasswordInput)
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    16
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    17
    def clean_email(self):
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    18
        """ see if a user exists for this email.
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    19
        """
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    20
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    21
        email = self.cleaned_data['email']
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    22
        password = self.data['password']
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    23
        try:
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    24
            username = User.objects.get(email__iexact=email).username
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    25
        except User.DoesNotExist:
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    26
            raise forms.ValidationError("Incorrect e-mail or password")
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    27
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    28
        user = authenticate(username=username, password=password)
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    29
        if not user:
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    30
            raise forms.ValidationError("Incorrect e-mail or password")
4
ededea9ad08b login and logout works .
nishanth
parents: 3
diff changeset
    31
        return email
3
182f216da4a8 made the login view. have to write templates and check it.
nishanth
parents:
diff changeset
    32
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    33
class RegisterForm(forms.ModelForm):
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    34
    """ add the fields email and password
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    35
    and then generate form using profile model.
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    36
    """
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    37
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    38
    email = forms.EmailField()
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    39
    password = forms.CharField(widget=forms.PasswordInput, help_text="Choose a good password which 8 to 30 chars long")
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    40
    confirm_password = forms.CharField(widget=forms.PasswordInput) 
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    41
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    42
    first_name = forms.CharField(required=True)
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    43
    last_name = forms.CharField()
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    44
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    45
    class Meta:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    46
        model = Profile
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    47
        fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    48
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    49
    def clean_first_name(self):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    50
        """ firstname should contain only alphabets.
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    51
        """
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    52
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    53
        first_name = self.cleaned_data['first_name']
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    54
        if first_name.strip(string.ascii_letters):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    55
            raise forms.ValidationError("Name must contain only alphabets")
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    56
        return first_name
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    57
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    58
    def clean_last_name(self):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    59
        """ only alphabets allowed.
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    60
        """
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    61
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    62
        last_name = self.cleaned_data['last_name']
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    63
        if last_name.strip(string.ascii_letters):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    64
            raise forms.ValidationError("Name must contain only alphabets")
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    65
        return last_name
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
    66
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    67
    def clean_email(self):
7
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    68
        """ check if a user exists with same email.
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    69
        """
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    70
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    71
        email = self.cleaned_data['email']
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    72
        try:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    73
            User.objects.get(email__iexact=email)
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    74
            raise forms.ValidationError("An account already exists with this email.\
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    75
                                        Click on forgot password if you have forgotten your password")
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    76
        except User.DoesNotExist:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    77
            return email
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    78
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    79
    def clean_password(self):
7
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    80
        """ check if the password contains only alphabets or digits or punctuation.
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    81
        then check if the size of the password is optimal.
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    82
        then check if both the given passwords match.
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    83
        """
af9ab5ad2786 fixed a bug in registration .
nishanth
parents: 6
diff changeset
    84
6
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    85
        password = self.cleaned_data['password']
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    86
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    87
        if password.strip(string.ascii_letters+string.punctuation+string.digits):
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    88
            raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password")
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    89
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    90
        if not 8 <= len(password) <= 30:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    91
            raise forms.ValidationError("Password must be atleast 8 characters and at most 30 characters")
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    92
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    93
        if not password == self.data['confirm_password']:
057498d12450 users can now register but still there is no concept of activation e-mail .
nishanth
parents: 4
diff changeset
    94
            raise forms.ValidationError("Passwords do not match")
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
    95
22
737ec98cf6df added the missing return statements in clean functions of forms .
nishanth
parents: 18
diff changeset
    96
        return password
737ec98cf6df added the missing return statements in clean functions of forms .
nishanth
parents: 18
diff changeset
    97
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
    98
class EventCreateForm(forms.ModelForm):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
    99
    """ A form to create an event.
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   100
    """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   101
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   102
    class Meta:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   103
        model = Event
43
757d1da69255 added venue field in event model and corresponding forms and views.
nishanth
parents: 22
diff changeset
   104
        fields = ['title', 'description', 'start_date', 'stop_date', 'venue']
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   105
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   106
    def clean_start_date(self):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   107
        """ see if the start date is greater than today or not.
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   108
        """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   109
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   110
        start_date = self.cleaned_data['start_date']
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   111
        if start_date < datetime.now().date():
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   112
            raise forms.ValidationError("The event must start at the latest today.")
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   113
        return start_date
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   114
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   115
    def clean_stop_date(self):
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   116
        """ see that stop_date is not less than start_date.
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   117
        """
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   118
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   119
        stop_date = self.cleaned_data['stop_date']
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   120
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   121
        start_date = self.clean_start_date()
8
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   122
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   123
        if start_date > stop_date:
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   124
            raise forms.ValidationError('The event stops even before it starts. I am starting to wonder what kind of event is this.')
e2699e042129 now a user can create an event if he is a staff
nishanth
parents: 7
diff changeset
   125
        return stop_date
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   126
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   127
class PasswordResetForm(forms.Form):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   128
    """ check for the existance of user for the email.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   129
    Reset the password irrespective of active status.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   130
    """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   131
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   132
    email = forms.EmailField()
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   133
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   134
    def clean_email(self):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   135
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   136
        email = self.cleaned_data['email']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   137
        try:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   138
            user = User.objects.get(email__iexact=email)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   139
            return email
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   140
        except User.DoesNotExist:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   141
            raise forms.ValidationError("This not a registered email. Please enter a valid email.")
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   142
22
737ec98cf6df added the missing return statements in clean functions of forms .
nishanth
parents: 18
diff changeset
   143
        return email
737ec98cf6df added the missing return statements in clean functions of forms .
nishanth
parents: 18
diff changeset
   144
9
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   145
class PasswordChangeForm(forms.Form):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   146
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   147
    old_password = forms.CharField(widget=forms.PasswordInput)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   148
    new_password = forms.CharField(widget=forms.PasswordInput)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   149
    confirm_password = forms.CharField(widget=forms.PasswordInput)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   150
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   151
    def clean_old_password(self):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   152
        """ authenticate the given password against username.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   153
        """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   154
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   155
        username = self.data['username']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   156
        old_password = self.cleaned_data['old_password']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   157
        user = authenticate(username=username, password=old_password)
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   158
        if not user:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   159
            raise forms.ValidationError("Incorrect password")
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   160
        return old_password
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   161
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   162
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   163
    def clean_new_password(self):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   164
        """ check if the password contains only alphabets or digits or punctuation.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   165
        then check if the size of the password is optimal.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   166
        then check if both the given passwords match.
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   167
        """
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   168
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   169
        new_password = self.cleaned_data['new_password']
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   170
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   171
        if new_password.strip(string.ascii_letters+string.punctuation+string.digits):
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   172
            raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password")
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   173
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   174
        if not 8 <= len(new_password) <= 30:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   175
            raise forms.ValidationError("Password must be atleast 8 characters and at most 30 characters")
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   176
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   177
        if not new_password == self.data['confirm_password']:
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   178
            raise forms.ValidationError("Passwords do not match")
e29ecb7819e7 password change and password reset have been done.
nishanth
parents: 8
diff changeset
   179
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   180
        return new_password
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   181
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   182
class EditProfileForm(forms.Form):
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   183
    """ form for editing the profile.
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   184
    """
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   185
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   186
    first_name = forms.CharField(required=True)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   187
    last_name = forms.CharField(required=True)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   188
    gender = forms.ChoiceField(choices=GENDER_CHOICES)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   189
    profession = forms.ChoiceField(choices=PROFESSION_CHOICES)
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   190
    affiliated_to = forms.CharField(max_length=100, required=True, label="College/Company")
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   191
    interests = forms.CharField(max_length=100, label="Fields of interest")
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   192
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   193
    def clean_first_name(self):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   194
        """ firstname should contain only alphabets.
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   195
        """
17
125b6fc8f20b users can view and edit profile .
nishanth
parents: 9
diff changeset
   196
18
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   197
        first_name = self.cleaned_data['first_name']
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   198
        if first_name.strip(string.ascii_letters):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   199
            raise forms.ValidationError("Name must contain only alphabets")
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   200
        return first_name
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   201
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   202
    def clean_last_name(self):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   203
        """ only alphabets allowed.
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   204
        """
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   205
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   206
        last_name = self.cleaned_data['last_name']
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   207
        if last_name.strip(string.ascii_letters):
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   208
            raise forms.ValidationError("Name must contain only alphabets")
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   209
        return last_name
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   210
7dae32a2439b prettified the home page and moved workshops to another page called workshops.
nishanth
parents: 17
diff changeset
   211