Skip to content

Commit 458d4d6

Browse files
authored
Merge pull request #290 from hackupc/FIX--add-default-optn-discover
FIX: Added default option and fixed clean discover
2 parents 78de7da + 9b0e2b8 commit 458d4d6

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

applications/forms/common_fields.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def social_media_field(field_name, placeholder):
4343
label=field_name.capitalize(),
4444
)
4545

46+
4647
def social_required(field_name, placeholder):
4748
return forms.CharField(
4849
required=True,
@@ -52,6 +53,7 @@ def social_required(field_name, placeholder):
5253
label=field_name.capitalize(),
5354
)
5455

56+
5557
def common_online():
5658
return forms.TypedChoiceField(
5759
required=True,

applications/forms/hacker.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class HackerApplicationForm(_BaseApplicationForm):
4444

4545
online = common_online()
4646

47-
4847
def clean_resume(self):
4948
resume = self.cleaned_data["resume"]
5049
size = getattr(resume, "_size", 0)
@@ -92,7 +91,6 @@ def clean_projects(self):
9291
),
9392
)
9493

95-
9694
cvs_edition = forms.BooleanField(
9795
required=False,
9896
label='I authorize "Hackers at UPC" to share my CV with HackUPC 2024 Sponsors.',
@@ -193,7 +191,6 @@ def get_bootstrap_field_info(self):
193191
deadline = getattr(settings, "REIMBURSEMENT_DEADLINE", False)
194192
r_enabled = getattr(settings, "REIMBURSEMENT_ENABLED", False)
195193
personal_info_fields.append({"name": "origin", "space": 12})
196-
197194

198195
# Fields that we only need the first time the hacker fills the application
199196
# https://stackoverflow.com/questions/9704067/test-if-django-modelform-has-instance
@@ -233,7 +230,24 @@ class Meta(_BaseApplicationForm.Meta):
233230
"Plase type following this schema: <strong>city, province, country</strong>",
234231
}
235232

233+
class CustomSelect(forms.Select):
234+
def create_option(
235+
self, name, value, label, selected, index, subindex=None, attrs=None
236+
):
237+
if index == 0:
238+
attrs = {"disabled": "disabled"}
239+
return super().create_option(
240+
name, value, label, selected, index, subindex=subindex, attrs=attrs
241+
)
242+
243+
def clean_discover(self):
244+
discover = self.cleaned_data.get("discover")
245+
if discover == "":
246+
raise forms.ValidationError("Please select an option.")
247+
return discover
248+
236249
discover_choices = (
250+
("", "- Select an option -"),
237251
(1, "HackUPC's social media"),
238252
(2, "Through your university (social media, emails...)"),
239253
(3, "Friends"),
@@ -248,7 +262,7 @@ class Meta(_BaseApplicationForm.Meta):
248262
"origin": forms.TextInput(attrs={"autocomplete": "off"}),
249263
"description": forms.Textarea(attrs={"rows": 3, "cols": 40}),
250264
"projects": forms.Textarea(attrs={"rows": 3, "cols": 40}),
251-
"discover": forms.Select(choices=discover_choices),
265+
"discover": CustomSelect(choices=discover_choices),
252266
"graduation_year": forms.RadioSelect(),
253267
}
254268

@@ -263,5 +277,5 @@ class Meta(_BaseApplicationForm.Meta):
263277
"origin": "Where are you joining us from?",
264278
"description": "Why are you excited about %s?" % settings.HACKATHON_NAME,
265279
"projects": "What projects have you worked on?",
266-
"resume": "Upload your resume"
280+
"resume": "Upload your resume",
267281
}

0 commit comments

Comments
 (0)