Skip to content

Commit 4bcd757

Browse files
committed
Wip urlvalidator with custom msg
1 parent 1acd97b commit 4bcd757

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

applications/forms/common_fields.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django import forms
22
from django.conf import settings
3+
from django.core.validators import URLValidator
34

45

56
def common_first_timer():
@@ -34,7 +35,20 @@ def common_degree():
3435
)
3536

3637

38+
# class CustomURLValidator(URLValidator):
39+
# message = "Please enter a valid URL"
40+
41+
3742
def social_media_field(field_name, placeholder):
43+
if field_name == "website":
44+
return forms.CharField(
45+
required=False,
46+
widget=forms.TextInput(
47+
attrs={"class": "form-control", "placeholder": placeholder},
48+
validators=[URLValidator(message="Please enter a valid URL")],
49+
),
50+
label=field_name.capitalize(),
51+
)
3852
return forms.CharField(
3953
required=False,
4054
widget=forms.TextInput(
@@ -43,6 +57,7 @@ def social_media_field(field_name, placeholder):
4357
label=field_name.capitalize(),
4458
)
4559

60+
4661
def social_required(field_name, placeholder):
4762
return forms.CharField(
4863
required=True,
@@ -52,6 +67,7 @@ def social_required(field_name, placeholder):
5267
label=field_name.capitalize(),
5368
)
5469

70+
5571
def common_online():
5672
return forms.TypedChoiceField(
5773
required=True,

applications/forms/hacker.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ def clean_projects(self):
7979
)
8080
return data
8181

82-
def clean_site(self):
83-
data = self.cleaned_data["site"]
84-
validate_url(data, "website")
85-
return data
82+
# def clean_site(self,):
83+
# data = self.cleaned_data["site"]
84+
85+
# if not URLValidator(data):
86+
# raise forms.ValidationError("Please enter a valid website url")
87+
# return data
8688

8789
first_timer = common_first_timer()
8890

@@ -97,7 +99,6 @@ def clean_site(self):
9799
),
98100
)
99101

100-
101102
cvs_edition = forms.BooleanField(
102103
required=False,
103104
label='I authorize "Hackers at UPC" to share my CV with HackUPC 2023 Sponsors.',
@@ -134,8 +135,6 @@ def clean_cvs_edition(self):
134135
cc = self.cleaned_data.get("cvs_edition", False)
135136
return cc
136137

137-
138-
139138
def clean_reimb_amount(self):
140139
data = self.cleaned_data["reimb_amount"]
141140
reimb = self.cleaned_data.get("reimb", False)
@@ -187,7 +186,6 @@ def get_bootstrap_field_info(self):
187186
r_enabled = getattr(settings, "REIMBURSEMENT_ENABLED", False)
188187
personal_info_fields.append({"name": "origin", "space": 12})
189188

190-
191189
# Fields that we only need the first time the hacker fills the application
192190
# https://stackoverflow.com/questions/9704067/test-if-django-modelform-has-instance
193191
if not self.instance.pk:
@@ -257,5 +255,5 @@ class Meta(_BaseApplicationForm.Meta):
257255
"origin": "Where are you joining us from?",
258256
"description": "Why are you excited about %s?" % settings.HACKATHON_NAME,
259257
"projects": "What projects have you worked on?",
260-
"resume": "Upload your resume"
258+
"resume": "Upload your resume",
261259
}

0 commit comments

Comments
 (0)