From dd4d3315c156d79c1141e3b44dae440364a693fb Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Wed, 17 Nov 2021 12:06:31 +0100 Subject: add account data validation --- accounts/templates/accounts/index.html | 75 +++++++++++++++++++++------------ accounts/views.py | 29 +++++++++++++ requirements.txt | 1 + templates/registration/base_client.html | 5 +++ version.txt | 2 +- 5 files changed, 85 insertions(+), 27 deletions(-) diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index 0b66290..0af8ce1 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -27,17 +27,22 @@ {% csrf_token %}
- + +
- + +
- + +
+
+
+ +
- - + + +
- + +
- + +
- + +
- + +
- + +
- +
- + +
- +
- +
@@ -114,23 +127,27 @@
- + +
- + +
- + +
- + +
- +
@@ -141,16 +158,19 @@
- + +
- + +
- + +
@@ -169,16 +189,19 @@
Medico di famiglia
- + +
- + +
- + +
diff --git a/accounts/views.py b/accounts/views.py index 7038ccd..c73ecfd 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -93,6 +93,11 @@ def personal(request): branca_pionieri = "" branca_rover = "" + # variables for validation + validation_dic = {} + required_fields = ["first_name", "last_name", "email", "parent_name", "via", "cap", "country", "nationality", "phone", "avs_number", "emer_name", "emer_relative", "cell_phone", "address", "health_care", "injuries", "rc", "medic_name", "medic_phone", "medic_address"] + + # variables for throwing errors to the user error = False error_text = "" @@ -144,6 +149,7 @@ def personal(request): usercode.phone = request.POST["phone"] usercode.school = request.POST["school"] usercode.avs_number = request.POST["avs_number"] + if request.POST["year"].isdigit(): usercode.year = request.POST["year"] else: @@ -174,6 +180,21 @@ def personal(request): medic.misc = request.POST["misc"] medic.save() + if request.POST["birth_date"] == "" or request.POST["birth_date"] == "01 Gennaio 1970" or request.POST["birth_date"] == "None": + validation_dic["birth_date"] = 'class="datepicker validate invalid" required="" aria-required="true"' + error = True + error_text = "Alcuni campi richiesti non sono stati compilati" + else: + validation_dic["birth_date"] = 'class="datepicker validate" required="" aria-required="true"' + + for i in required_fields: + if request.POST[i] == "": + error = True + error_text = "Alcuni campi richiesti non sono stati compilati" + validation_dic[i] = 'class="validate invalid" required="" aria-required="true"' + else: + validation_dic[i] = 'class="validate" required="" aria-required="true"' + # if "branca" in request.POST: # if request.POST["branca"] != "": # request.user.groups.clear() @@ -280,6 +301,12 @@ def personal(request): if not error: return HttpResponseRedirect("") + else: + # no post, create empty validation + validation_dic["birth_date"] = 'class="datepicker validate" required="" aria-required="true"' + for i in required_fields: + validation_dic[i] = 'class="validate" required="" aria-required="true"' + # check if user is in a group and set multiple choice to that if len(request.user.groups.values_list('name', flat=True)) == 0: branca_default = "selected" @@ -323,8 +350,10 @@ def personal(request): else: card_name = '' + # fill context context = { + 'validation_dic': validation_dic, 'first_name': request.user.first_name, 'last_name': request.user.last_name, 'email': request.user.email, diff --git a/requirements.txt b/requirements.txt index 90dceca..7682c40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pdfkit dateparser pytz pdf2image +django-debug-toolbar diff --git a/templates/registration/base_client.html b/templates/registration/base_client.html index 3e251a2..3e78397 100644 --- a/templates/registration/base_client.html +++ b/templates/registration/base_client.html @@ -70,6 +70,11 @@ blockquote { border-left: 5px solid {{hexcolor}}; } + + .input-field input[type=text].valid { + border-bottom: none; + box-shadow: 0 1px 0 0 #9e9e9e; + } diff --git a/version.txt b/version.txt index 40347d9..b5aac86 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.4 -rev=3 +rev=4 -- cgit v1.2.1