Skip to content

Commit

Permalink
Merge pull request #290 from hackupc/FIX--add-default-optn-discover
Browse files Browse the repository at this point in the history
FIX: Added default option and fixed clean discover
  • Loading branch information
gerardm27 authored Feb 12, 2024
2 parents 78de7da + 9b0e2b8 commit 458d4d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions applications/forms/common_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def social_media_field(field_name, placeholder):
label=field_name.capitalize(),
)


def social_required(field_name, placeholder):
return forms.CharField(
required=True,
Expand All @@ -52,6 +53,7 @@ def social_required(field_name, placeholder):
label=field_name.capitalize(),
)


def common_online():
return forms.TypedChoiceField(
required=True,
Expand Down
24 changes: 19 additions & 5 deletions applications/forms/hacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class HackerApplicationForm(_BaseApplicationForm):

online = common_online()


def clean_resume(self):
resume = self.cleaned_data["resume"]
size = getattr(resume, "_size", 0)
Expand Down Expand Up @@ -92,7 +91,6 @@ def clean_projects(self):
),
)


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


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

class CustomSelect(forms.Select):
def create_option(
self, name, value, label, selected, index, subindex=None, attrs=None
):
if index == 0:
attrs = {"disabled": "disabled"}
return super().create_option(
name, value, label, selected, index, subindex=subindex, attrs=attrs
)

def clean_discover(self):
discover = self.cleaned_data.get("discover")
if discover == "":
raise forms.ValidationError("Please select an option.")
return discover

discover_choices = (
("", "- Select an option -"),
(1, "HackUPC's social media"),
(2, "Through your university (social media, emails...)"),
(3, "Friends"),
Expand All @@ -248,7 +262,7 @@ class Meta(_BaseApplicationForm.Meta):
"origin": forms.TextInput(attrs={"autocomplete": "off"}),
"description": forms.Textarea(attrs={"rows": 3, "cols": 40}),
"projects": forms.Textarea(attrs={"rows": 3, "cols": 40}),
"discover": forms.Select(choices=discover_choices),
"discover": CustomSelect(choices=discover_choices),
"graduation_year": forms.RadioSelect(),
}

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

0 comments on commit 458d4d6

Please sign in to comment.