sdi/forms.py
author nishanth
Fri, 03 Sep 2010 16:07:30 +0530
branchanoop
changeset 237 53b9c79dfbf0
parent 234 cf3de6d222ce
child 238 30e39c985e2f
permissions -rw-r--r--
fixed a typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     1
from django import forms
68
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
     2
from django.contrib.auth import authenticate
8
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     3
131
04158b6bfa7e somehow thought this kinda forms are better
nishanth
parents: 124
diff changeset
     4
from sage_days.sdi.models import Registrant, TOPICS_CHOICES, ParticipantInfo, SPRINT_CHOICES
41
651b341fd555 added captcha for registration
nishanth
parents: 25
diff changeset
     5
from captcha.fields import CaptchaField
8
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     6
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     7
class RegisterForm(forms.ModelForm):
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     8
    """ The form that is displayed to user.
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
     9
    """
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
    10
20
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    11
    topics_interested = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=TOPICS_CHOICES, required=False)
8
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
    12
    class Meta:
e85ae25f920a added forms.py
nishanth
parents:
diff changeset
    13
        model = Registrant
45
29d7d70c9273 added new fields to registrant.
nishanth
parents: 44
diff changeset
    14
        exclude = ['priority_for_attending', 'selected_for_attending']
44
ce2b84e6f24a changed the name of captcha.
nishanth
parents: 41
diff changeset
    15
    verification_code = CaptchaField()
19
3932d9426c44 added the topics field in register form
nishanth
parents: 8
diff changeset
    16
21
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    17
    def clean_email(self):
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    18
        """ See if the user has already registered using the email.
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    19
        """
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    20
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    21
        email = self.cleaned_data['email'].strip()
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    22
        try:
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    23
            Registrant.objects.get(email__iexact=email)
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    24
            raise forms.ValidationError("This email is already registered. Did you register earlier??")
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    25
        except Registrant.DoesNotExist:
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    26
            return email
3d7a52d9ed2e added clean email
nishanth
parents: 20
diff changeset
    27
20
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    28
    def clean_topics_interested(self):
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    29
        """ Join the choices using PIPE character and store them.
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    30
        """
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    31
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    32
        topics = self.cleaned_data['topics_interested']
9db4ee082d4e added topics choices and corresponding clean method
nishanth
parents: 19
diff changeset
    33
        return "|".join(topics)
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    34
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    35
class SearchForm(forms.Form):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    36
    """ Search form for filtering registrants.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    37
    """
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    38
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    39
    topics_interested = forms.CharField(required=False, help_text=" Use numbers seperated by spaces and prefix a minus to exclude")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    40
    knowledge_of_python = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    41
    knowledge_of_sage = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    42
    likeliness_of_attending = forms.CharField(required=False, help_text=" Give single number from 1 to 5 or a range seperated by hyphen")
79
064ff60025d9 removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents: 77
diff changeset
    43
    #need_for_python_workshop = forms.BooleanField(required=False)
064ff60025d9 removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents: 77
diff changeset
    44
    #need_accomodation = forms.BooleanField(required=False)
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    45
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    46
    def clean_topics_interested(self):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    47
        """ split and return include list and exclude list
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    48
        """
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    49
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    50
        include_list = []
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    51
        exclude_list = []
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    52
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    53
        topics = self.cleaned_data['topics_interested']
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    54
        for number in topics.split():
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    55
            if number.startswith('-'):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    56
                exclude_list.append(number[1:])
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    57
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    58
                include_list.append(number)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    59
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    60
        return (include_list, exclude_list)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    61
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    62
    def clean_knowledge_of_python(self):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    63
        """ if two numbers are given take start and stop.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    64
        else take highest as default.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    65
        """
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    66
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    67
        range_str = self.cleaned_data['knowledge_of_python'].strip()
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    68
        if not range_str:
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    69
            return ("","")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    70
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    71
        start_stop = range_str.split("-")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    72
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    73
        if len(start_stop) == 1:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    74
            if start_stop[0].isdigit():
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    75
                return (start_stop[0], "")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    76
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    77
                raise forms.ValidationError("Invalid range for knowledge of Python")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    78
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    79
        elif len(start_stop) == 2:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    80
            start, stop = start_stop
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    81
            if start.isdigit() and stop.isdigit():
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    82
                return (start, stop)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    83
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    84
                 raise forms.ValidationError("Invalid range for knowledge of Python")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    85
        else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    86
            raise forms.ValidationError("Invalid range for knowledge of Python")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    87
 
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    88
    def clean_knowledge_of_sage(self):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    89
        """ if two numbers are given take start and stop.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    90
        else take highest as default.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    91
        """
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    92
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    93
        range_str = self.cleaned_data['knowledge_of_sage'].strip()
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    94
        if not range_str:
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
    95
            return ("","")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    96
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    97
        start_stop = range_str.split("-")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    98
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
    99
        if len(start_stop) == 1:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   100
            if start_stop[0].isdigit():
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
   101
                return (start_stop[0], "")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   102
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   103
                raise forms.ValidationError("Invalid range for knowledge of Sage")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   104
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   105
        elif len(start_stop) == 2:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   106
            start, stop = start_stop
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   107
            if start.isdigit() and stop.isdigit():
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   108
                return (start, stop)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   109
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   110
                 raise forms.ValidationError("Invalid range for knowledge of Sage")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   111
        else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   112
            raise forms.ValidationError("Invalid range for knowledge of Sage")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   113
 
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   114
    def clean_likeliness_of_attending(self):
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   115
        """ if two numbers are given take start and stop.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   116
        else take highest as default.
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   117
        """
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   118
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   119
        range_str = self.cleaned_data['likeliness_of_attending'].strip()
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   120
        if not range_str:
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
   121
            return ("","")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   122
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   123
        start_stop = range_str.split("-")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   124
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   125
        if len(start_stop) == 1:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   126
            if start_stop[0].isdigit():
25
30baf3c635c5 added list statiscs page
nishanth
parents: 24
diff changeset
   127
                return (start_stop[0], "")
24
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   128
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   129
                raise forms.ValidationError("Invalid range for Likeliness of attending the workshop")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   130
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   131
        elif len(start_stop) == 2:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   132
            start, stop = start_stop
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   133
            if start.isdigit() and stop.isdigit():
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   134
                return (start, stop)
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   135
            else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   136
                 raise forms.ValidationError("Invalid range for Likeliness of attending the workshop")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   137
        else:
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   138
            raise forms.ValidationError("Invalid range for Likeliness of attending the workshop")
f79be1dd4a22 added clean methods for each attribute in search form
nishanth
parents: 21
diff changeset
   139
                   
56
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   140
class EmailForm(forms.Form):
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   141
    """ Take a list of csv seperated email addresses.
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   142
    """
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   143
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   144
    emails = forms.CharField(widget=forms.Textarea, required=False)
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   145
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   146
    def clean_emails(self):
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   147
        emails = self.cleaned_data['emails']
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   148
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   149
        to_emails = [csv_list.split(',') for csv_list in emails.split()]
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   150
        return to_emails
7dfacad8adee provided an interface for sending out emails
nishanth
parents: 45
diff changeset
   151
71
c736873f35cb fixed a bug
nishanth
parents: 68
diff changeset
   152
class LoginForm(forms.Form):
68
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   153
    """ login form.
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   154
    """
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   155
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   156
    username = forms.CharField()
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   157
    password = forms.CharField(widget=forms.PasswordInput)
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   158
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   159
    def clean_username(self):
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   160
        username = self.cleaned_data['username']
72
3673ed3ca27c fixed a few bugs
nishanth
parents: 71
diff changeset
   161
        try:
3673ed3ca27c fixed a few bugs
nishanth
parents: 71
diff changeset
   162
            password = self.data['password']
3673ed3ca27c fixed a few bugs
nishanth
parents: 71
diff changeset
   163
        except KeyError:
3673ed3ca27c fixed a few bugs
nishanth
parents: 71
diff changeset
   164
            raise forms.ValidationError("Invalid username or password")
68
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   165
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   166
        if not authenticate(username=username, password=password):
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   167
            raise forms.ValidationError("Invalid username or password")
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   168
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   169
        return username
b0e630caa6e6 added required forms for login and logout
nishanth
parents: 56
diff changeset
   170
93
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   171
def UserSelectForm(users, post_data=None ):
90
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   172
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   173
    choices = [ (_.id, _.first_name) for _ in users ]
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   174
    class myF(forms.Form):
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   175
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   176
        selected_users = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=choices, required=False)
1a6e1af98624 now selecting users through forms. created a form for that
nishanth
parents: 79
diff changeset
   177
93
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   178
        def clean_selected_users(self):
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   179
            selected_ids = self.cleaned_data['selected_users']
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   180
            return [ Registrant.objects.get(id=_) for _ in selected_ids ]
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   181
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   182
    return myF(post_data) if post_data else myF()
505989755cd8 modified the form and implemented the view to display selected users
nishanth
parents: 90
diff changeset
   183
131
04158b6bfa7e somehow thought this kinda forms are better
nishanth
parents: 124
diff changeset
   184
class ParticipantInfoForm(forms.Form):
124
d4a7644e7fe8 created a form for taking participant info and used it in the view
nishanth
parents: 93
diff changeset
   185
133
38b7bad92b5b finally the view is complete
nishanth
parents: 132
diff changeset
   186
    has_laptop_for_sagedays = forms.ChoiceField(choices=(("Yes","Yes"), ("No", "No")))
132
b8e5390e7920 fixed a typo
nishanth
parents: 131
diff changeset
   187
    sprinted_already = forms.ChoiceField(choices=(("Yes","Yes"), ("No", "No")))
131
04158b6bfa7e somehow thought this kinda forms are better
nishanth
parents: 124
diff changeset
   188
    will_sprint = forms.ChoiceField(choices=SPRINT_CHOICES)
04158b6bfa7e somehow thought this kinda forms are better
nishanth
parents: 124
diff changeset
   189
                                         
175
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   190
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   191
def SendAccoForm(users, post_data=None):
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   192
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   193
    choices = [ (_.id, _.first_name) for _ in users ]
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   194
    class myF(forms.Form):
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   195
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   196
	message = forms.CharField(required=True)
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   197
        selected_users = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=choices, required=False)
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   198
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   199
        def clean_selected_users(self):
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   200
            selected_ids = self.cleaned_data['selected_users']
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   201
            return [ Registrant.objects.get(id=_) for _ in selected_ids ]
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   202
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   203
	def clean_message(self):
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   204
	    message = self.cleaned_data['message']
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   205
	    return message.strip()
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   206
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   207
    return myF(post_data) if post_data else myF()
b48d4c18a0aa created form for sending accomodation info
nishanth
parents: 133
diff changeset
   208
237
53b9c79dfbf0 fixed a typo
nishanth
parents: 234
diff changeset
   209
class EditAddressForm(forms.ModelForm):
234
cf3de6d222ce added form for editing address and name
nishanth
parents: 175
diff changeset
   210
cf3de6d222ce added form for editing address and name
nishanth
parents: 175
diff changeset
   211
    class Meta:
cf3de6d222ce added form for editing address and name
nishanth
parents: 175
diff changeset
   212
        model = Regristrant
cf3de6d222ce added form for editing address and name
nishanth
parents: 175
diff changeset
   213
        fields = ["first_name", "last_name", "address"]