aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--accounts/templates/accounts/index.html75
-rw-r--r--accounts/views.py29
-rw-r--r--requirements.txt1
-rw-r--r--templates/registration/base_client.html5
-rw-r--r--version.txt2
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 %}
<div class="row">
<div class="input-field col l4 s12">
- <input name="first_name" value="{{first_name}}" id="first_name" type="text" >
+ <input name="first_name" value="{{first_name}}" id="first_name" type="text" {{validation_dic.first_name|safe}}>
<label for="first_name">Nome</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input name="last_name" value="{{last_name}}" id="last_name" type="text" >
+ <input name="last_name" value="{{last_name}}" id="last_name" type="text" {{validation_dic.last_name|safe}}>
<label for="last_name">Cognome</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input name="birth_date" value="{{birth_date}}" id="birth_date" type="text" class="datepicker">
+ <input name="birth_date" value="{{birth_date}}" id="birth_date" type="text" {{validation_dic.birth_date|safe}}>
<label for="birth_date">Data di nascita</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
+ </div>
+ <div class="row">
<div class="input-field col l4 s12">
<select name="branca" disabled>
<option value="" disabled {{branca_default}}>Nessuna</option>
@@ -50,47 +55,55 @@
<label>Branca</label>
</div>
<div class="input-field col l4 s12">
- <input value="{{parent_name}}" name="parent_name" id="parent_name" type="text" >
+ <input value="{{parent_name}}" name="parent_name" id="parent_name" type="text" {{validation_dic.parent_name|safe}}>
<label for="parent_name">Nome dei genitori</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{avs_number}}" name="avs_number" id="avs_number" type="text" placeholder="756.1234.5678.90">
- <label for="avs_number">Numero AVS</label>
+ <input value="{{avs_number}}" name="avs_number" id="avs_number" type="text" placeholder="756.1234.5678.90" {{validation_dic.avs_number|safe}}>
+ <label for="avs_number" data-error="wrong">Numero AVS</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l12 s12">
- <input value="{{via}}" name="via" id="via" type="text" >
+ <input value="{{via}}" name="via" id="via" type="text" {{validation_dic.via|safe}}>
<label for="via">Via e numero</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{cap}}" name="cap" id="cap" type="text" >
+ <input value="{{cap}}" name="cap" id="cap" type="text" {{validation_dic.cap|safe}}>
<label for="cap">CAP</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{country}}" name="country" id="country" type="text" >
+ <input value="{{country}}" name="country" id="country" type="text" {{validation_dic.country|safe}}>
<label for="country">Comune</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{nationality}}" name="nationality" id="nationality" type="text" >
+ <input value="{{nationality}}" name="nationality" id="nationality" type="text" {{validation_dic.nationality|safe}}>
<label for="nationality">Nazionalit&agrave;</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{phone}}" name="phone" id="phone" type="text" >
+ <input value="{{phone}}" name="phone" id="phone" type="text" {{validation_dic.phone|safe}}>
<label for="phone">Cellulare</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{home_phone}}" name="home_phone" id="home_phone" type="text" >
+ <input value="{{home_phone}}" name="home_phone" id="home_phone" type="text" {{validation_dic.home_phone|safe}}>
<label for="home_phone">Telefono di casa</label>
</div>
<div class="input-field col l4 s12">
- <input value="{{email}}" name="email" id="email" type="text" >
+ <input value="{{email}}" name="email" id="email" type="text" {{validation_dic.email|safe}}>
<label for="email">Email</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l8 s12">
- <input value="{{school}}" name="school" id="school" type="text" >
+ <input value="{{school}}" name="school" id="school" type="text" {{validation_dic.school|safe}}>
<label for="school">Scuola frequentata (o professione)</label>
</div>
<div class="input-field col l4 s12">
- <input value="{{year}}" name="year" id="year" type="text" >
+ <input value="{{year}}" name="year" id="year" type="text" {{validation_dic.year|safe}}>
<label for="year">Classe scolastica</label>
</div>
</div>
@@ -114,23 +127,27 @@
</div>
<div class="row">
<div class="input-field col l6 s12">
- <input name="emer_name" value="{{emer_name}}" id="emer_name" type="text" >
+ <input name="emer_name" value="{{emer_name}}" id="emer_name" type="text" {{validation_dic.emer_name|safe}}>
<label for="emer_name">Nome e cognome</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l3 s12">
- <input name="emer_relative" value="{{emer_relative}}" id="emer_relative" type="text" >
+ <input name="emer_relative" value="{{emer_relative}}" id="emer_relative" type="text" {{validation_dic.emer_relative|safe}}>
<label for="emer_releative">Parentela</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l3 s12">
- <input name="cell_phone" value="{{cell_phone}}" id="cellphone" type="text" >
+ <input name="cell_phone" value="{{cell_phone}}" id="cellphone" type="text" {{validation_dic.cell_phone|safe}}>
<label for="cell_phone">Cellulare</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l9 s12">
- <input value="{{address}}" name="address" id="address" type="text" >
+ <input value="{{address}}" name="address" id="address" type="text" {{validation_dic.address|safe}}>
<label for="address">Indirizzo completo</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l3 s12">
- <input value="{{emer_phone}}" name="emer_phone" id="emer_phone" type="text" >
+ <input value="{{emer_phone}}" name="emer_phone" id="emer_phone" type="text" {{validation_dic.emer_phone|safe}}>
<label for="emer_phone">Telefono di casa</label>
</div>
</div>
@@ -141,16 +158,19 @@
</div>
<div class="row">
<div class="input-field col l4 s12">
- <input value="{{health_care}}" name="health_care" id="health_care" type="text" >
+ <input value="{{health_care}}" name="health_care" id="health_care" type="text" {{validation_dic.health_care|safe}}>
<label for="health_care">Cassa Malati</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{injuries}}" name="injuries" id="injuries" type="text" >
+ <input value="{{injuries}}" name="injuries" id="injuries" type="text" {{validation_dic.injuries|safe}}>
<label for="injuries">Infortuni</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l4 s12">
- <input value="{{rc}}" name="rc" id="rc" type="text" >
+ <input value="{{rc}}" name="rc" id="rc" type="text" {{validation_dic.rc|safe}}>
<label for="rc">Responsabilit&agrave; civile</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
</div>
<div class="row">
@@ -169,16 +189,19 @@
<h6>Medico di famiglia</h6>
</div>
<div class="input-field col l6 s12">
- <input value="{{medic_name}}" name="medic_name" id="medic_name" type="text" >
+ <input value="{{medic_name}}" name="medic_name" id="medic_name" type="text" {{validation_dic.medic_name|safe}}>
<label for="medic_name">Nome e cognome</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l6 s12">
- <input value="{{medic_phone}}" name="medic_phone" id="medic_phone" type="text" >
+ <input value="{{medic_phone}}" name="medic_phone" id="medic_phone" type="text" {{validation_dic.medic_phone|safe}}>
<label for="medic_phone">Telefono studio</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
<div class="input-field col l12 s12">
- <input value="{{medic_address}}" name="medic_address" id="medic_address" type="text" >
+ <input value="{{medic_address}}" name="medic_address" id="medic_address" type="text" {{validation_dic.medic_address|safe}}>
<label for="medic_address">Indirizzo completo</label>
+ <span class="helper-text" data-error="Campo richiesto"></span>
</div>
</div>
<div class="row">
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;
+ }
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="utf-8">
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