aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <aleporia@gmail.com>2023-07-25 12:14:12 +0200
committerAndrea Lepori <aleporia@gmail.com>2023-07-25 12:14:13 +0200
commitda6654f57ef683c8c1f2f4c2eab52d907ba1925b (patch)
tree086273bf46a649b10349bfdda752c13571f3d6b1
parentclean up old settings menu (diff)
downloadscout-subs-da6654f57ef683c8c1f2f4c2eab52d907ba1925b.tar.gz
scout-subs-da6654f57ef683c8c1f2f4c2eab52d907ba1925b.zip
change branca and color to show
-rw-r--r--accounts/templates/accounts/user_edit.html8
-rw-r--r--accounts/views.py69
-rw-r--r--client/migrations/0018_alter_usercode_branca.py20
-rw-r--r--client/migrations/0019_alter_document_usercode.py19
-rw-r--r--client/models.py4
-rw-r--r--client/templates/client/index.html3
-rw-r--r--client/views.py13
-rw-r--r--version.txt2
8 files changed, 80 insertions, 58 deletions
diff --git a/accounts/templates/accounts/user_edit.html b/accounts/templates/accounts/user_edit.html
index bbbbecd..44eae5b 100644
--- a/accounts/templates/accounts/user_edit.html
+++ b/accounts/templates/accounts/user_edit.html
@@ -10,8 +10,8 @@
{% block content %}
<div class="tap-target {{color}}" data-target="home_btn">
<div class="tap-target-content">
- <h5 style="color:white">Continua l'attivazione</h5>
- <p style="color:white">Usa questo pulsante per tornare alla home e continuare il processo d'attivazione</p>
+ <h5 style="color:white">Continua l'iscrizione</h5>
+ <p style="color:white">Usa questo pulsante per tornare alla home e continuare il processo d'iscrizione</p>
</div>
</div>
@@ -44,7 +44,7 @@
</div>
<div class="row">
<div class="input-field col l4 s12">
- <select name="branca" disabled>
+ <select name="branca">
<option value="" disabled {{branca_default}}>Nessuna</option>
<option value="diga" {{branca_castorini}}>Castorini</option>
<option value="muta" {{branca_lupetti}}>Lupetti</option>
@@ -52,7 +52,7 @@
<option value="posto" {{branca_pionieri}}>Pionieri</option>
<option value="clan" {{branca_rover}}>Rover</option>
</select>
- <label>Branca (campo non modificabile)</label>
+ <label>Branca</label>
</div>
<div class="input-field col l4 s12">
<input value="{{parent_name}}" name="parent_name" id="parent_name" type="text" {{validation_dic.parent_name|safe}}>
diff --git a/accounts/views.py b/accounts/views.py
index a76ba8d..59afbf8 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -3,7 +3,7 @@ from django.shortcuts import render
from django.urls import reverse
from django.conf import settings
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm, SetPasswordForm, UserCreationForm
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, Group
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth.views import LoginView
from django.http import FileResponse
@@ -422,9 +422,6 @@ def edit(request, code):
errors = []
context = {}
ok_message = ""
- personal_active = "active"
- medic_active = ""
- settings_active = ""
# additional user information
if (code == 0):
# generate code
@@ -434,7 +431,7 @@ def edit(request, code):
break
medic = MedicalData()
medic.save()
- userCode = UserCode(user=request.user, code=code, medic=medic)
+ userCode = UserCode(user=request.user, code=code, medic=medic, branca=None)
userCode.save()
usercode = UserCode.objects.filter(user=request.user, code=code)
@@ -458,9 +455,7 @@ def edit(request, code):
# variables for validation
validation_dic = {}
- required_fields = ["first_name", "last_name", "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"]
- personal_fields = ["first_name", "last_name", "parent_name", "via", "cap", "country", "nationality", "phone", "avs_number"]
- medic_fields = ["emer_name", "emer_relative", "cell_phone", "address", "health_care", "injuries", "rc", "medic_name", "medic_phone", "medic_address"]
+ required_fields = ["first_name", "last_name", "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", "sickness", "vaccine"]
if request.method == "POST":
# requested download
@@ -524,6 +519,10 @@ def edit(request, code):
else:
errors.append("L'anno scolastico deve essere un numero")
+ if "branca" in request.POST:
+ if request.POST["branca"] != "" and request.POST["branca"] in ["diga", "muta", "reparto", "posto", "clan"]:
+ usercode.branca = Group.objects.get(name=request.POST["branca"])
+
usercode.save()
medic.emer_name = request.POST["emer_name"]
@@ -549,35 +548,28 @@ def edit(request, code):
medic.save()
missing_fields = False
- missing_personal_field = False
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"'
missing_fields = True
- missing_personal_field = True
else:
validation_dic["birth_date"] = 'class="datepicker validate" required="" aria-required="true"'
+ if request.POST["tetanus_date"] == "" or request.POST["tetanus_date"] == "01 Gennaio 1970" or request.POST["tetanus_date"] == "None":
+ validation_dic["tetanus_date"] = 'class="datepicker validate invalid" required="" aria-required="true"'
+ missing_fields = True
+ else:
+ validation_dic["tetanus_date"] = 'class="datepicker validate" required="" aria-required="true"'
+
for i in required_fields:
if request.POST[i] == "":
missing_fields = True
- if i in personal_fields:
- missing_personal_field = True
validation_dic[i] = 'class="validate invalid" required="" aria-required="true"'
else:
validation_dic[i] = 'class="validate" required="" aria-required="true"'
if missing_fields:
errors.append("Alcuni campi richiesti non sono stati compilati")
- if not missing_personal_field:
- personal_active = ""
- medic_active = "active"
-
- # if "branca" in request.POST:
- # if request.POST["branca"] != "":
- # request.user.groups.clear()
- # request.user.groups.add(
- # Group.objects.get(name=request.POST["branca"]))
# check if user uploaded a file
if "vac_certificate" in request.FILES:
@@ -678,19 +670,19 @@ def edit(request, code):
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:
+ if usercode.branca == None:
branca_default = "selected"
else:
- parent_group = request.user.groups.values_list('name', flat=True)[0]
- if parent_group == "diga":
+ branca = usercode.branca.name
+ if branca == "diga":
branca_castorini = "selected"
- elif parent_group == "muta":
+ elif branca == "muta":
branca_lupetti = "selected"
- elif parent_group == "reparto":
+ elif branca == "reparto":
branca_esploratori = "selected"
- elif parent_group == "posto":
+ elif branca == "posto":
branca_pionieri = "selected"
- elif parent_group == "clan":
+ elif branca == "clan":
branca_rover = "selected"
else:
branca_default = "selected"
@@ -719,23 +711,11 @@ def edit(request, code):
else:
card_name = ''
- # check if user is connected with midata
- midata_user = (usercode.midata_id > 0)
- midata_disable = ""
-
- # get user info from midata
- if midata_user:
- midata_disable = " readonly disabled"
- if not copy_from_midata(request, usercode):
- return HttpResponseRedirect(request.get_full_path())
-
- usable_password = request.user.has_usable_password()
-
# check if user has saved the form
home_tooltip = False
if "saved" in request.GET:
# show tooltip only if user is not approved and there are no errors
- home_tooltip = (not request.user.has_perm("client.approved")) and (len(errors) == 0)
+ home_tooltip = (len(errors) == 0)
# fill context
context = {
@@ -784,13 +764,6 @@ def edit(request, code):
'vac_certificate': vac_name,
'errors': errors,
'ok_message': ok_message,
- 'midata_user': midata_user,
- 'midata_disable': midata_disable,
- 'usable_password': usable_password,
- 'personal_active': personal_active,
- 'medic_active': medic_active,
- 'settings_active': settings_active,
- 'midata_enabled': MIDATA_ENABLED,
'home_tooltip': home_tooltip,
}
diff --git a/client/migrations/0018_alter_usercode_branca.py b/client/migrations/0018_alter_usercode_branca.py
new file mode 100644
index 0000000..2e43506
--- /dev/null
+++ b/client/migrations/0018_alter_usercode_branca.py
@@ -0,0 +1,20 @@
+# Generated by Django 4.1.5 on 2023-07-25 09:58
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('auth', '0012_alter_user_first_name_max_length'),
+ ('client', '0017_document_usercode'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='usercode',
+ name='branca',
+ field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='auth.group'),
+ ),
+ ]
diff --git a/client/migrations/0019_alter_document_usercode.py b/client/migrations/0019_alter_document_usercode.py
new file mode 100644
index 0000000..04f030a
--- /dev/null
+++ b/client/migrations/0019_alter_document_usercode.py
@@ -0,0 +1,19 @@
+# Generated by Django 4.1.5 on 2023-07-25 09:59
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('client', '0018_alter_usercode_branca'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='document',
+ name='usercode',
+ field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='client.usercode'),
+ ),
+ ]
diff --git a/client/models.py b/client/models.py
index 1548893..c39a5ea 100644
--- a/client/models.py
+++ b/client/models.py
@@ -77,7 +77,7 @@ class UserCode(models.Model):
user = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
medic = models.ForeignKey(MedicalData, default=None, on_delete=models.PROTECT)
code = models.IntegerField(default=0)
- branca = models.ForeignKey(Group, default=1, on_delete=models.PROTECT)
+ branca = models.ForeignKey(Group, default=None, on_delete=models.PROTECT, null=True)
first_name = models.CharField(default="", max_length=250)
last_name = models.CharField(default="", max_length=250)
email = models.CharField(default="", max_length=250)
@@ -97,7 +97,7 @@ class UserCode(models.Model):
class Document(models.Model):
- usercode = models.ForeignKey(UserCode, default=1, on_delete=models.CASCADE)
+ usercode = models.ForeignKey(UserCode, default=None, on_delete=models.CASCADE, null=True)
user = models.ForeignKey(User, default=None, on_delete=models.CASCADE)
group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE)
code = models.IntegerField(default=0)
diff --git a/client/templates/client/index.html b/client/templates/client/index.html
index ef9b67d..8bb2d41 100644
--- a/client/templates/client/index.html
+++ b/client/templates/client/index.html
@@ -35,8 +35,7 @@
<div class="card">
<div class="card-content">
<span class="card-title">
- {{data.0.first_name}} {{data.0.last_name}}
- <a href="{% url "edit_user" code=data.0.code %}" class="btn-flat"><i class="material-icons">edit</i></a>
+ <p style="text-decoration: underline; text-decoration-thickness: 3px; text-decoration-color: {{data.2}};">{{data.0.first_name}} {{data.0.last_name}}<a href="{% url "edit_user" code=data.0.code %}" class="btn-flat"><i class="material-icons">edit</i></a></p>
<div style="font-size: 0.5em; line-height: normal;">{{data.0.born_date}}</div>
</span>
<a id="add" class="btn-floating halfway-fab btn-large {{color}}" href="{% url 'create'%}"><i class="material-icons">add</i></a>
diff --git a/client/views.py b/client/views.py
index dfb5dbf..5160927 100644
--- a/client/views.py
+++ b/client/views.py
@@ -95,7 +95,18 @@ def index(request):
for uc in ucs:
documents = Document.objects.filter(
Q(usercode=uc) & ~Q(status='archive')).select_related("personal_data", "medical_data", "document_type", "user")
- docs.append([uc, documents])
+ color_mapping = {
+ "diga": "#ffeb3b",
+ "muta": "#03a9f4",
+ "reparto": "#795548",
+ "posto": "#f44336",
+ "clan": "#4caf50"
+ }
+ if uc.branca == None:
+ color = "black"
+ else:
+ color = color_mapping[uc.branca.name]
+ docs.append([uc, documents, color])
# show only docs of the user and non archived
vac_file = ["/server/media/", "/vac_certificate/doc"]
diff --git a/version.txt b/version.txt
index 3647ad5..4936b1d 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
version=0.6
-rev=30
+rev=31