Skip to content

Commit fddc4a5

Browse files
Nidhi Sharmanidhi-pythonmateayush-labpranatsharma1
authored
registration form updated (#56)
* registation form updated * responsive input areas * form validation applied in template * minor changes in the responsiveness of inputs * style bug in registration form * validation styles for mobile and syntax * form style * student no. regex updated * changes in settigs deployment * validation bug removed * case insensitive url validation * added roll_no, gender&removed some fields * toggle visibility of username acc. to domain * added whatsapp field Co-authored-by: Nidhi Sharma <[email protected]> Co-authored-by: ayush <[email protected]> Co-authored-by: Pranat Sharma <[email protected]>
1 parent 304eb1b commit fddc4a5

File tree

10 files changed

+563
-283
lines changed

10 files changed

+563
-283
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
work/
55
static
66
.vscode
7-
7+
.env
88
# Created by https://www.toptal.com/developers/gitignore/api/django
99
# Edit at https://www.toptal.com/developers/gitignore?templates=django
1010

Core/forms.py

Lines changed: 97 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ class RegistrationForm(forms.ModelForm):
7474

7575
class Meta:
7676
model = Registration
77-
fields = ['name', 'contact','your_work','college_email', 'student_number','branch','year',
78-
'account_handles','experience','about_yourself','why_attend',
79-
'design_tools','insta_improvement','captcha']
80-
exclude = ['event']
77+
fields = [
78+
'name', 'phone','your_work','college_email','whatsapp',
79+
'student_number','branch','year','roll_no',
80+
'gender','domain','skills','hacker_rank_username',
81+
'captcha'
82+
]
8183

8284
def __init__(self, *args, **kwargs):
8385
super(RegistrationForm, self).__init__(*args, **kwargs)
@@ -103,36 +105,38 @@ def __init__(self, *args, **kwargs):
103105
'onblur': ''}
104106
)
105107
)
106-
self.fields['account_handles'] = forms.CharField(
107-
max_length=500,required=False,
108+
109+
self.fields['your_work'] = forms.CharField(
110+
max_length=1000,required=False,
108111
widget=forms.TextInput(
109112
attrs={'type': 'text',
110-
'name': 'account_handles',
113+
'name': 'your_work',
111114
'class': 'form-control',
112-
'id': 'account_handles',
115+
'id': 'your_work',
113116
'onblur': ''
114117
}
115118
)
116119
)
117-
self.fields['your_work'] = forms.CharField(
118-
max_length=1000,required=False,
120+
self.fields['phone'] = forms.CharField(
121+
required=True,
119122
widget=forms.TextInput(
120123
attrs={'type': 'text',
121-
'name': 'your_work',
124+
'name': 'phone',
122125
'class': 'form-control',
123-
'id': 'your_work',
126+
'id': 'Phone',
127+
'placeholder': 'Enter Phone No.',
124128
'onblur': ''
125129
}
126130
)
127131
)
128-
self.fields['contact'] = forms.CharField(
132+
self.fields['whatsapp'] = forms.CharField(
129133
required=True,
130134
widget=forms.TextInput(
131135
attrs={'type': 'text',
132-
'name': 'contact',
136+
'name': 'whatsapp',
133137
'class': 'form-control',
134-
'id': 'Contact',
135-
'placeholder': 'Enter Contact No.',
138+
'id': 'whatsapp',
139+
'placeholder': 'Enter whatsapp No.',
136140
'onblur': ''
137141
}
138142
)
@@ -147,13 +151,21 @@ def __init__(self, *args, **kwargs):
147151
'onblur': ''}
148152
)
149153
)
150-
154+
self.fields['roll_no'] = forms.CharField(
155+
required=True,
156+
widget=forms.TextInput(
157+
attrs={'type': 'text',
158+
'class': 'form-control',
159+
'id': 'Roll_no',
160+
'placeholder': 'Enter Roll Number',
161+
'onblur': ''}
162+
)
163+
)
151164
self.fields['branch'] = forms.ModelChoiceField(
152165
queryset=Branch.objects.filter(active=True).order_by('name'),
153166
initial=Branch.objects.filter(active=True).order_by('name').first(),
154167
required=True,
155168
widget=forms.Select(
156-
# choices=BRANCH_CHOICES,
157169
attrs={'class': 'form-control',
158170
'data-val': 'true',
159171
'data-val-required': '*',
@@ -162,37 +174,41 @@ def __init__(self, *args, **kwargs):
162174
}
163175
)
164176
)
165-
self.fields['experience'] = forms.ChoiceField(
166-
choices=Registration.experience_choices,
167-
label = 'Experience',
177+
178+
self.fields['gender'] = forms.ModelChoiceField(
179+
queryset=Gender.objects.all(),
180+
initial=Gender.objects.all().first(),
168181
required=True,
169182
widget=forms.Select(
170183
attrs={'class': 'form-control',
171184
'data-val': 'true',
172185
'data-val-required': '*',
173-
'id': 'Experience',
174-
'name': 'Experience',
186+
'id': 'gender',
187+
'name': 'gender',
175188
}
176189
)
177190
)
178-
self.fields['insta_improvement'] = forms.CharField(
191+
self.fields['domain'] = forms.ModelChoiceField(
192+
queryset=Domain.objects.all(),
193+
initial=Domain.objects.all().first(),
179194
required=True,
180-
widget=forms.TextInput(
181-
attrs={'type': 'text',
182-
'name': 'insta_improvement',
183-
'class': 'form-control',
184-
'id': 'insta_improvement',
185-
'onblur': ''
195+
widget=forms.Select(
196+
attrs={'class': 'form-control',
197+
'data-val': 'true',
198+
'data-val-required': '*',
199+
'id': 'domain',
200+
'name': 'domain',
186201
}
187202
)
188203
)
189-
self.fields['about_yourself'] = forms.CharField(
204+
205+
self.fields['skills'] = forms.CharField(
190206
required=True,
191207
widget=forms.TextInput(
192208
attrs={'type': 'text',
193-
'name': 'about_yourself',
209+
'name': 'skills',
194210
'class': 'form-control',
195-
'id': 'about_yourself',
211+
'id': 'skills',
196212
'onblur': ''
197213
}
198214
)
@@ -239,62 +255,83 @@ def clean(self):
239255
raise ValidationError("")
240256

241257
try:
242-
contact = cleaned_data['contact']
258+
phone = cleaned_data['phone']
259+
except KeyError:
260+
raise ValidationError("")
261+
262+
try:
263+
whatsapp = cleaned_data['whatsapp']
243264
except KeyError:
244265
raise ValidationError("")
245266

246-
account_handles = cleaned_data.get('account_handles',None)
247-
your_work = cleaned_data.get('your_work',None)
248-
if account_handles:
249-
account_handles = account_handles.split(',')
250-
for ah in account_handles:
251-
ah = ah.lstrip()
252-
ah = ah.rstrip()
253-
try:
254-
validate_url(ah)
255-
except:
256-
raise ValidationError(f'Handles : {ah} is not a valid URL')
267+
try:
268+
roll_no = cleaned_data['roll_no']
269+
except KeyError:
270+
raise ValidationError("")
271+
272+
hacker_rank_username = cleaned_data.get('hacker_rank_username')
273+
your_work = cleaned_data.get('your_work')
274+
if hacker_rank_username:
275+
pattern = re.compile("^_*[a-zA-Z\\d]+[a-zA-z0-9]*$")
276+
if not pattern.match(str(hacker_rank_username)):
277+
return ValidationError("Invalid HackerRank Username")
278+
257279
if your_work:
258280
your_work = your_work.split(',')
259281
for link in your_work:
260282
link = link.lstrip()
261283
link = link.rstrip()
284+
285+
if (link[:7]).lower()!='http://' and link[:8].lower()!='https://':
286+
link = 'http://'+ link
262287
try:
263288
validate_url(link)
264-
except:
289+
except ValidationError:
265290
raise ValidationError(f'Your work : {link} is not a valid URL')
266291

267-
regex_student = "^(17|18|19|20)(15|11|12|14|10|13|00|31|21|32|40)[0-9][0-9][0-9]";
292+
regex_student = "^(20|21)(15|11|12|14|10|13|00|31|21|32|40)[0-9][0-9][0-9](d|D|)[-]?[mdlMDL]?";
268293
pattern_student = re.compile(regex_student)
269294

270295
if student_number:
271296
if not pattern_student.match(str(student_number)):
272297
raise ValidationError("Invalid Student Number")
273-
regex_college_email= "^[a-zA-Z]+(17|18|19|20)(15|11|12|14|10|13|00|31|21|32|40)[0-9][0-9][0-9](\@akgec\.ac\.in)$"
298+
299+
regex_college_email= "^[a-zA-Z]+(20|21)(15|11|12|14|10|13|00|31|21|32|40)[0-9][0-9][0-9](\@akgec\.ac\.in)$"
300+
274301
pattern_college_email= re.compile(regex_college_email)
275302

276303
if college_email:
277304
if not pattern_college_email.match(str(college_email)):
278305
raise ValidationError("Invalid College Email")
279306

280-
regex_contact= "^[56789]\d{9}$"
281-
pattern_contact=re.compile(regex_contact)
307+
regex_phone= "^[56789]\d{9}$"
308+
pattern_phone=re.compile(regex_phone)
282309

283-
if contact:
284-
if not pattern_contact.match(str(contact)):
285-
raise ValidationError("Invalid contact")
310+
if phone:
311+
if not pattern_phone.match(str(phone)):
312+
raise ValidationError("Invalid phone")
313+
if whatsapp:
314+
if not pattern_phone.match(str(whatsapp)):
315+
raise ValidationError("Invalid Whatsapp number")
286316

317+
regex_roll_no = "^(21|20)00270(15|11|12|14|10|13|00|31|21|32|40)[0-9]{4}$"
318+
pattern_roll_no = re.compile(regex_roll_no)
287319

288-
event = Event.objects.filter(active=True).first()
320+
if not pattern_roll_no.match(str(roll_no)):
321+
raise ValidationError("Invalid Roll No. ")
289322

290-
if Registration.objects.filter(college_email=college_email, event=event, student_number=student_number).exists():
291-
raise ValidationError('Registration with this student number and email already exist.')
323+
event = Event.objects.filter(active=True).first()
324+
if Registration.objects.filter(college_email=college_email, event=event).exists():
325+
raise ValidationError('Registration with this email already exist.')
292326
elif Registration.objects.filter(student_number=student_number, event=event).exists():
293327
raise ValidationError('Registration with this student number already exist.')
294-
elif Registration.objects.filter(college_email=college_email, event=event).exists():
295-
raise ValidationError('Registration with this email already exist.')
296-
elif Registration.objects.filter(contact=contact, event=event).exists():
297-
raise ValidationError('Registration with this contact already exist.')
328+
elif Registration.objects.filter(roll_no=roll_no, event=event).exists():
329+
raise ValidationError('Registration with this roll number already exists.')
330+
elif Registration.objects.filter(phone=phone, event=event).exists():
331+
raise ValidationError('Registration with this phone already exist.')
332+
elif Registration.objects.filter(whatsapp=whatsapp, event=event).exists():
333+
raise ValidationError('Registration with this whatsapp number already exist.')
334+
298335

299336
return cleaned_data
300337

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Generated by Django 3.2.4 on 2021-09-03 16:50
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('Core', '0004_auto_20210616_1853'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='registration',
16+
name='domain',
17+
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='registrations', to='Core.domain'),
18+
),
19+
migrations.AddField(
20+
model_name='registration',
21+
name='gender',
22+
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='registrations', to='Core.gender'),
23+
),
24+
migrations.AddField(
25+
model_name='registration',
26+
name='hacker_rank_username',
27+
field=models.CharField(blank=True, help_text='Your HackerRank username. Please create an account on HackerRank.', max_length=250, null=True),
28+
),
29+
migrations.AddField(
30+
model_name='registration',
31+
name='phone',
32+
field=models.CharField(default=1111111111, max_length=10, unique=True),
33+
preserve_default=False,
34+
),
35+
migrations.AddField(
36+
model_name='registration',
37+
name='roll_no',
38+
field=models.CharField(default=1111111111111, max_length=13, unique=True),
39+
preserve_default=False,
40+
),
41+
migrations.AddField(
42+
model_name='registration',
43+
name='skills',
44+
field=models.CharField(default='html/css', help_text='Skills like HTML, CSS, Java...', max_length=250),
45+
preserve_default=False,
46+
),
47+
migrations.AlterField(
48+
model_name='registration',
49+
name='college_email',
50+
field=models.EmailField(max_length=254, unique=True),
51+
),
52+
migrations.AlterField(
53+
model_name='registration',
54+
name='student_number',
55+
field=models.CharField(max_length=7, unique=True),
56+
),
57+
migrations.AlterField(
58+
model_name='registration',
59+
name='year',
60+
field=models.ForeignKey(default=2, on_delete=django.db.models.deletion.CASCADE, to='Core.year'),
61+
),
62+
migrations.AlterField(
63+
model_name='registration',
64+
name='your_work',
65+
field=models.TextField(blank=True, help_text='Links to your work or coding profiles.', null=True),
66+
),
67+
migrations.AlterUniqueTogether(
68+
name='registration',
69+
unique_together=set(),
70+
),
71+
migrations.RemoveField(
72+
model_name='registration',
73+
name='about_yourself',
74+
),
75+
migrations.RemoveField(
76+
model_name='registration',
77+
name='account_handles',
78+
),
79+
migrations.RemoveField(
80+
model_name='registration',
81+
name='contact',
82+
),
83+
migrations.RemoveField(
84+
model_name='registration',
85+
name='design_tools',
86+
),
87+
migrations.RemoveField(
88+
model_name='registration',
89+
name='experience',
90+
),
91+
migrations.RemoveField(
92+
model_name='registration',
93+
name='insta_improvement',
94+
),
95+
migrations.RemoveField(
96+
model_name='registration',
97+
name='why_attend',
98+
),
99+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.2.4 on 2021-09-07 16:59
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('Core', '0005_auto_20210903_2220'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='branch',
15+
name='name',
16+
field=models.CharField(max_length=10),
17+
),
18+
migrations.AlterField(
19+
model_name='registration',
20+
name='student_number',
21+
field=models.CharField(max_length=10, unique=True),
22+
),
23+
]

0 commit comments

Comments
 (0)