-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathforms.py
More file actions
307 lines (282 loc) · 12.1 KB
/
forms.py
File metadata and controls
307 lines (282 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import datetime
from django import forms
from applications.alumniprofile.models import Profile, Constants, Batch
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.core.exceptions import ValidationError
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit, Row, Column, Div, Field
from crispy_forms.bootstrap import InlineRadios
import re
# --------------------------------REGISTRATION FORMS FOR STUDENTS AND ALUMNI START--------------------------------------------------------
class ProfileNewRegister(forms.ModelForm):
country = forms.ChoiceField(widget=forms.Select(
attrs={'id': 'countryId', 'class': 'countries order-alpha presel-IN custom-select', 'name': 'country'}))
state = forms.ChoiceField(
widget=forms.Select(attrs={'id': 'stateId', 'class': 'states order-alpha custom-select', 'name': 'state'}))
city = forms.ChoiceField(
widget=forms.Select(attrs={'id': 'cityId', 'class': 'cities order-alpha custom-select', 'name': 'city'}))
checkbox_update = forms.BooleanField(required=True)
def clean(self):
super(ProfileNewRegister, self).clean() # if necessary
del self._errors['country']
del self._errors['city']
del self._errors['state']
return self.cleaned_data
class Meta:
model = Profile
fields = [
'city',
'country',
'state',
'year_of_admission',
'mobile1',
'mobile2',
'facebook',
'instagram',
'name',
'fathers_name',
'spouse_name',
'sex',
'alternate_email',
'date_of_birth',
'date_of_joining',
'working_status',
'branch',
'programme',
'batch',
'current_address',
'permanent_address',
'current_position',
'current_organisation',
'past_experience',
'current_course',
'current_university',
'linkedin',
'website',
'profile_picture',
'checkbox_update']
widgets = {
'working_status': forms.RadioSelect(choices=Constants.WORKING_STATUS),
}
# --------------------------------REGISTRATION FORMS FOR STUDENTS AND ALUMNI END--------------------------------------------------------
class RegisterForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Row(
Column('batch', css_class='form-group col-md-4 mb-0'),
Column('programme', css_class='form-group col-md-4 mb-0'),
Column('branch', css_class='form-group col-md-4 mb-0'),
css_class='form-row my-3'
),
Submit('submit', 'Search', css_class=''),
)
class Meta:
model = Profile
fields = ['batch', 'programme', 'branch']
class ProfileEdit(forms.ModelForm):
date_of_birth = forms.DateField(
widget=forms.TextInput(
attrs={'type': 'date'}
),
required=True,
)
date_of_joining = forms.DateField(
widget=forms.TextInput(
attrs={'type': 'date'}
),
required=False,
)
current_address = forms.CharField(
widget=forms.Textarea(
attrs={'rows': 3, 'placeholder': 'Enter Address'}
),
max_length=4000,
)
permanent_address = forms.CharField(
widget=forms.Textarea(
attrs={'rows': 3, 'placeholder': 'Enter Permanent Address', }
),
max_length=4000,
required=False,
)
country = forms.CharField(widget=forms.Select(
attrs={'id': 'countryId', 'class': 'countries order-alpha custom-select', 'name': 'country'}))
state = forms.CharField(
widget=forms.Select(attrs={'id': 'stateId', 'class': 'states order-alpha custom-select', 'name': 'state'}))
city = forms.CharField(
widget=forms.Select(attrs={'id': 'cityId', 'class': 'cities order-alpha custom-selects', 'name': 'city'}))
linkedin = forms.URLField(widget=forms.TextInput(attrs={'placeholder': 'Linkedin URL'}))
website = forms.URLField(widget=forms.TextInput(attrs={'placeholder': 'Website'}), required=False)
facebook = forms.URLField(widget=forms.TextInput(attrs={'placeholder': 'Facebook URL'}), required=False)
instagram = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Instagram Username'}), required=False)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['fathers_name'].label = "Father/Mother's Name"
self.fields['spouse_name'].label = "Husband's Name"
self.fields['mobile1'].label = "Mobile No."
self.fields['mobile2'].label = "Alternate Mobile No."
self.fields['batch'].label = 'Year of Passing'
self.fields['sex'].label = 'Gender'
self.fields['phone_no'].label = 'Phone No.'
self.fields['roll_no'].label = 'Roll No.'
self.fields['date_of_birth'].label = 'Date of Birth'
self.fields['year_of_admission'].label = 'Year of Admission'
self.fields['alternate_email'].label = 'Alternate Email'
self.helper = FormHelper()
self.helper.layout = Layout(
Div(
Field('roll_no', css_class="form-control", wrapper_class='col-md-4'),
Field('name', css_class="form-control", wrapper_class='col-md-4'),
Field('sex', css_class="custom-select", wrapper_class="col-md-4"),
css_class='form-row my-3',
),
Div(
Field('fathers_name', css_class="form-control", wrapper_class='col-md-6'),
Field('spouse_name', css_class="form-control", wrapper_class='col-md-6'),
css_class='form-row my-3',
),
Div(
Field('date_of_birth', css_class="form-control", wrapper_class='col-md-4'),
Field('year_of_admission', css_class="custom-select", wrapper_class='col-md-4'),
Field('batch', css_class="custom-select", wrapper_class="col-md-4"),
css_class='form-row my-3',
),
Div(
Field('branch', css_class="custom-select", wrapper_class="col-md-6"),
Field('programme', css_class="custom-select", wrapper_class="col-md-6"),
css_class='form-row my-3',
),
Div(
Field('mobile1', css_class="form-control", wrapper_class='col-md-4'),
Field('mobile2', css_class="form-control", wrapper_class='col-md-4'),
Field('phone_no', css_class="form-control", wrapper_class="col-md-4"),
css_class='form-row my-3',
),
Div(
Field('email', css_class="form-control", wrapper_class='col-md-6'),
Field('alternate_email', css_class="form-control", wrapper_class='col-md-6'),
css_class='form-row my-3',
),
Div(
Field('current_address', css_class="form-control", wrapper_class='col-md'),
css_class='form-row my-3',
),
Div(
Field('country', wrapper_class="col-md-4"),
Field('state', wrapper_class="col-md-4"),
Field('city', wrapper_class="col-md-4"),
css_class='form-row my-3',
),
Div(
Field('permanent_address', css_class="form-control", wrapper_class='col-md'),
css_class='form-row my-3',
),
InlineRadios('working_status'),
Div(
Field('current_position', css_class="form-control", wrapper_class='col-md-6 col-lg-4'),
Field('current_organisation', css_class="form-control", wrapper_class='col-md-6 col-lg-4'),
Field('date_of_joining', css_class="form-control", wrapper_class='col-md-6 col-lg-4'),
Field('past_experience', css_class="form-control", wrapper_class="col-md-6 col-lg-4"),
css_class='form-row my-3',
),
Div(
Field('current_course', css_class="form-control", wrapper_class='col-md-6 col-lg-4'),
Field('current_university', css_class="form-control", wrapper_class='col-md-6 col-lg-4'),
css_class='form-row my-3',
),
Div(
Field('linkedin', css_class="form-control", wrapper_class='col-md-6'),
Field('website', css_class="form-control", wrapper_class='col-md-6'),
css_class='form-row my-3',
),
Div(
Field('facebook', css_class="form-control", wrapper_class='col-md-6'),
Field('instagram', css_class="form-control", wrapper_class='col-md-6'),
css_class='form-row my-3',
),
Field('profile_picture', css_class="w-100"),
# 'profile_picture',
Submit('submit', 'Save Changes'),
)
# def clean(self):
# super(ProfileEdit, self).clean() #if necessary
# del self._errors['country']
# del self._errors['city']
# del self._errors['state']
# return self.cleaned_data
class Meta:
model = Profile
fields = [
'city',
'country',
'state',
'year_of_admission',
'alternate_email',
'phone_no',
'mobile1',
'mobile2',
'facebook',
'instagram',
'name',
'fathers_name',
'spouse_name',
'sex',
'email',
'roll_no',
'date_of_birth',
'date_of_joining',
'working_status',
'branch',
'programme',
'batch',
'current_address',
'permanent_address',
'phone_no',
'current_position',
'current_organisation',
'past_experience',
'current_course',
'current_university',
'linkedin',
'website',
'profile_picture']
widgets = {
# 'name': forms.TextInput(attrs={ 'readonly':'readonly'}),
# 'sex': forms.TextInput(attrs={ 'readonly':'readonly'}),
'email': forms.TextInput(attrs={'readonly': 'readonly'}),
'roll_no': forms.TextInput(attrs={'readonly': 'readonly'}),
'year_of_admission': forms.TextInput(attrs={'readonly': 'readonly'}),
'branch': forms.TextInput(attrs={'readonly': 'readonly'}),
'programme': forms.TextInput(attrs={'readonly': 'readonly'}),
'working_status': forms.RadioSelect(choices=Constants.WORKING_STATUS),
}
class SignUp(UserCreationForm):
user_role = forms.ChoiceField(choices=(('A', 'Alumni'), ('S', 'Student')))
def clean_email(self):
email = self.cleaned_data['email'].lower()
r = User.objects.filter(email=email)
if r:
raise ValidationError('Account with this email id already exists.')
if re.findall("iiitdmj.ac.in$", email):
raise ValidationError(
"Institute email id is not accepted.Kindly enter your personal email id.")
return email
def clean_username(self):
username = self.cleaned_data.get('username').lower()
r = User.objects.filter(username=username)
# New regex matching for institute id (also added in signup.html)
match = re.search('20(([A-Za-z]{3,5})|(\d{2}))\d{2,5}', username)
if(match == None):
raise ValidationError(
'Please enter your institute roll number.'
)
return username
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2', 'user_role']
class PasswordResetRequestForm(forms.Form):
roll_no = forms.IntegerField(label=("Roll No."))
email = forms.CharField(label=("Email"), max_length=254)