@@ -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
0 commit comments