From 26fb6c43a27c014383127d0e4b3fb29f8b923690 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sat, 20 Jun 2020 23:32:55 +0200 Subject: Doc, doctypes, users all done --- accounts/templates/accounts/index.html | 211 +++++++++++++++++++++--- accounts/views.py | 53 ++++++ client/migrations/0015_personaldata_email.py | 18 ++ client/migrations/0016_auto_20200620_1733.py | 26 +++ client/migrations/0017_usercode_medic.py | 19 +++ client/migrations/0018_auto_20200620_2007.py | 18 ++ client/migrations/0019_auto_20200620_2008.py | 18 ++ client/migrations/0020_auto_20200620_2200.py | 109 ++++++++++++ client/migrations/0021_documenttype_sign_req.py | 18 ++ client/migrations/0022_auto_20200620_2316.py | 18 ++ client/models.py | 29 ++++ client/templates/client/doc_create.html | 8 +- client/templates/client/doc_edit.html | 86 ++++++++++ client/templates/client/index.html | 99 ++++++++--- client/urls.py | 1 + client/views.py | 113 +++++++++++-- server/templates/server/doc_create.html | 103 ++++++++++++ server/templates/server/doc_edit.html | 92 ----------- server/templates/server/doc_list.html | 72 +++++--- server/templates/server/doc_type.html | 59 +++++-- server/templates/server/index.html | 17 +- server/urls.py | 2 +- server/views.py | 58 +++++-- 23 files changed, 1039 insertions(+), 208 deletions(-) create mode 100644 client/migrations/0015_personaldata_email.py create mode 100644 client/migrations/0016_auto_20200620_1733.py create mode 100644 client/migrations/0017_usercode_medic.py create mode 100644 client/migrations/0018_auto_20200620_2007.py create mode 100644 client/migrations/0019_auto_20200620_2008.py create mode 100644 client/migrations/0020_auto_20200620_2200.py create mode 100644 client/migrations/0021_documenttype_sign_req.py create mode 100644 client/migrations/0022_auto_20200620_2316.py create mode 100644 client/templates/client/doc_edit.html create mode 100644 server/templates/server/doc_create.html delete mode 100644 server/templates/server/doc_edit.html diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index 5ba2dc1..b3f25f0 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -55,16 +55,16 @@
-
+ {% csrf_token %}
- - + +
- - + +
@@ -84,72 +84,242 @@
- +
- +
- +
- +
- - + +
- +
- +
- +
- +
- +
+
+
+
+ +
+
+
+
+ {% csrf_token %} +
+
+
Persona di contatto in caso di necessità
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+
Assicurazione
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ È sostenitore REGA   + +
+
+
+
+
Medico di famiglia
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+
Scheda medica personale
+
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+ Deve assumere regolarmente medicamenti   + +
+
+
+ +
+ + +
+
+
+
+ Informazioni particolari sullo stato di salute: (postumi di operazioni, incidenti, malattie, disturbi fisici)   + +
+
+ + +
+
+
+
+
Allegati
+
+
+
+
+ Certificato delle vacinazioni +
+
+ Tessera della cassa malati +
+
+
-
Tabella medica
{% endblock %} {% block script %} var elem = $('.tabs') var options = { yearRange:100, - format:'dd.mm.yyyy', + format:'dd mmmm yyyy', i18n: { months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ], monthsShort: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic' ], @@ -176,4 +346,7 @@ var elems = document.querySelectorAll('select'); var instances = M.FormSelect.init(elems, options); }); + $(document).ready(function() { + $('input#sickness, input#vaccine, input#allergy, input#drugs, input#misc').characterCounter(); + }); {% endblock %} \ No newline at end of file diff --git a/accounts/views.py b/accounts/views.py index 0723482..36f59cd 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -19,6 +19,7 @@ def personal(request): context = {} if request.user.is_authenticated: usercode = UserCode.objects.filter(user=request.user)[0] + medic = usercode.medic debug = "" branca_default = "" branca_castorini = "" @@ -44,6 +45,28 @@ def personal(request): usercode.year = request.POST["year"] usercode.save() + medic.emer_name = request.POST["emer_name"] + medic.emer_relative = request.POST["emer_relative"] + medic.cell_phone = request.POST["cell_phone"] + medic.address = request.POST["address"] + medic.emer_phone = request.POST["emer_phone"] + medic.health_care = request.POST["health_care"] + medic.injuries = request.POST["injuries"] + medic.rc = request.POST["rc"] + medic.rega = "rega" in request.POST + medic.medic_name = request.POST["medic_name"] + medic.medic_phone = request.POST["medic_phone"] + medic.medic_address = request.POST["medic_address"] + medic.sickness = request.POST["sickness"] + medic.vaccine = request.POST["vaccine"] + medic.tetanus_date = dateparser.parse(request.POST["tetanus_date"]) + medic.allergy = request.POST["allergy"] + medic.drugs_bool = "drugs_bool" in request.POST + medic.drugs = request.POST["drugs"] + medic.misc_bool = "misc_bool" in request.POST + medic.misc = request.POST["misc"] + medic.save() + if request.POST["branca"] != "": request.user.groups.clear() request.user.groups.add( @@ -61,6 +84,16 @@ def personal(request): else: branca_default = "selected" + rega = "" + if medic.rega: + rega = "checked='checked'" + drugs = "" + if medic.drugs_bool: + drugs = "checked='checked'" + misc = "" + if medic.misc_bool: + misc = "checked='checked'" + context = { 'first_name': request.user.first_name, 'last_name': request.user.last_name, @@ -81,6 +114,26 @@ def personal(request): 'branca_esploratori': branca_esploratori, 'branca_pionieri': branca_pionieri, 'branca_rover': branca_rover, + 'emer_name': medic.emer_name, + 'emer_relative': medic.emer_relative, + 'cell_phone': medic.cell_phone, + 'address': medic.address, + 'emer_phone': medic.emer_phone, + 'health_care': medic.health_care, + 'injuries': medic.injuries, + 'rc': medic.rc, + 'rega_check': rega, + 'medic_name': medic.medic_name, + 'medic_phone': medic.medic_phone, + 'medic_address': medic.medic_address, + 'sickness': medic.sickness, + 'vaccine': medic.vaccine, + 'tetanus_date': medic.tetanus_date, + 'allergy': medic.allergy, + 'drugs_check': drugs, + 'drugs': medic.drugs, + 'misc_check': misc, + 'misc': medic.misc, } return render(request, 'accounts/index.html', context) diff --git a/client/migrations/0015_personaldata_email.py b/client/migrations/0015_personaldata_email.py new file mode 100644 index 0000000..86f7213 --- /dev/null +++ b/client/migrations/0015_personaldata_email.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-20 15:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0014_auto_20200620_1506'), + ] + + operations = [ + migrations.AddField( + model_name='personaldata', + name='email', + field=models.CharField(default='', max_length=250), + ), + ] diff --git a/client/migrations/0016_auto_20200620_1733.py b/client/migrations/0016_auto_20200620_1733.py new file mode 100644 index 0000000..11fb49f --- /dev/null +++ b/client/migrations/0016_auto_20200620_1733.py @@ -0,0 +1,26 @@ +# Generated by Django 3.0.7 on 2020-06-20 15:33 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0015_personaldata_email'), + ] + + operations = [ + migrations.CreateModel( + name='MedicalData', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('medic_name', models.CharField(default='', max_length=250)), + ], + ), + migrations.AddField( + model_name='document', + name='medical_data', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='client.MedicalData'), + ), + ] diff --git a/client/migrations/0017_usercode_medic.py b/client/migrations/0017_usercode_medic.py new file mode 100644 index 0000000..1c4071a --- /dev/null +++ b/client/migrations/0017_usercode_medic.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-20 18:04 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0016_auto_20200620_1733'), + ] + + operations = [ + migrations.AddField( + model_name='usercode', + name='medic', + field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.PROTECT, to='client.MedicalData'), + ), + ] diff --git a/client/migrations/0018_auto_20200620_2007.py b/client/migrations/0018_auto_20200620_2007.py new file mode 100644 index 0000000..17f40b3 --- /dev/null +++ b/client/migrations/0018_auto_20200620_2007.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-20 18:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0017_usercode_medic'), + ] + + operations = [ + migrations.AlterField( + model_name='medicaldata', + name='medic_name', + field=models.CharField(default='', max_length=250, null=True), + ), + ] diff --git a/client/migrations/0019_auto_20200620_2008.py b/client/migrations/0019_auto_20200620_2008.py new file mode 100644 index 0000000..15dff2f --- /dev/null +++ b/client/migrations/0019_auto_20200620_2008.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-20 18:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0018_auto_20200620_2007'), + ] + + operations = [ + migrations.AlterField( + model_name='medicaldata', + name='medic_name', + field=models.CharField(default='', max_length=250), + ), + ] diff --git a/client/migrations/0020_auto_20200620_2200.py b/client/migrations/0020_auto_20200620_2200.py new file mode 100644 index 0000000..cdf9cc9 --- /dev/null +++ b/client/migrations/0020_auto_20200620_2200.py @@ -0,0 +1,109 @@ +# Generated by Django 3.0.7 on 2020-06-20 20:00 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0019_auto_20200620_2008'), + ] + + operations = [ + migrations.AddField( + model_name='medicaldata', + name='address', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='allergy', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='cell_phone', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='drugs', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='drugs_bool', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='medicaldata', + name='emer_name', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='emer_phone', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='emer_relative', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='health_care', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='injuries', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='medic_address', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='medic_phone', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='misc', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='misc_bool', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='medicaldata', + name='rc', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='rega', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='medicaldata', + name='sickness', + field=models.CharField(default='', max_length=250), + ), + migrations.AddField( + model_name='medicaldata', + name='tetanus_date', + field=models.DateField(default=datetime.datetime(1970, 1, 1, 1, 0), null=True), + ), + migrations.AddField( + model_name='medicaldata', + name='vaccine', + field=models.CharField(default='', max_length=250), + ), + ] diff --git a/client/migrations/0021_documenttype_sign_req.py b/client/migrations/0021_documenttype_sign_req.py new file mode 100644 index 0000000..5538a2f --- /dev/null +++ b/client/migrations/0021_documenttype_sign_req.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-20 21:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0020_auto_20200620_2200'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='sign_req', + field=models.BooleanField(default=False), + ), + ] diff --git a/client/migrations/0022_auto_20200620_2316.py b/client/migrations/0022_auto_20200620_2316.py new file mode 100644 index 0000000..37a602b --- /dev/null +++ b/client/migrations/0022_auto_20200620_2316.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-06-20 21:16 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0021_documenttype_sign_req'), + ] + + operations = [ + migrations.RenameField( + model_name='documenttype', + old_name='sign_req', + new_name='auto_sign', + ), + ] diff --git a/client/models.py b/client/models.py index e7142ac..78b8df4 100644 --- a/client/models.py +++ b/client/models.py @@ -7,6 +7,7 @@ from datetime import datetime class DocumentType(models.Model): enabled = models.BooleanField(default=False) + auto_sign = models.BooleanField(default=False) group_private = models.BooleanField(default=False) group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE) personal_data = models.BooleanField(default=False) @@ -26,6 +27,30 @@ class PersonalData(models.Model): born_date = models.DateField(null=True, default=datetime.fromtimestamp(0)) home_phone = models.CharField(default="", max_length=250) phone = models.CharField(default="", max_length=250) + email = models.CharField(default="", max_length=250) + + +class MedicalData(models.Model): + emer_name = models.CharField(default="", max_length=250) + emer_relative = models.CharField(default="", max_length=250) + cell_phone = models.CharField(default="", max_length=250) + address = models.CharField(default="", max_length=250) + emer_phone = models.CharField(default="", max_length=250) + health_care = models.CharField(default="", max_length=250) + injuries = models.CharField(default="", max_length=250) + rc = models.CharField(default="", max_length=250) + rega = models.BooleanField(default=False) + medic_name = models.CharField(default="", max_length=250) + medic_phone = models.CharField(default="", max_length=250) + medic_address = models.CharField(default="", max_length=250) + sickness = models.CharField(default="", max_length=250) + vaccine = models.CharField(default="", max_length=250) + tetanus_date = models.DateField(null=True, default=datetime.fromtimestamp(0)) + allergy = models.CharField(default="", max_length=250) + drugs_bool = models.BooleanField(default=False) + drugs = models.CharField(default="", max_length=250) + misc_bool = models.BooleanField(default=False) + misc = models.CharField(default="", max_length=250) class Document(models.Model): @@ -40,6 +65,9 @@ class Document(models.Model): personal_data = models.ForeignKey( PersonalData, default=None, on_delete=models.PROTECT, null=True) + medical_data = models.ForeignKey( + MedicalData, default=None, on_delete=models.PROTECT, null=True) + class Meta: permissions = [ ("approved", "The user is approved") @@ -61,6 +89,7 @@ class Keys(models.Model): 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) parent_name = models.CharField(default="", max_length=250) via = models.CharField(default="", max_length=250) diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html index 550eb54..39deb2d 100644 --- a/client/templates/client/doc_create.html +++ b/client/templates/client/doc_create.html @@ -1,6 +1,6 @@ {% extends 'registration/base.html' %} -{% block title %}Admin - Modifica Tipo{% endblock %} +{% block title %}Crea Documento{% endblock %} {% block nav %} Home @@ -46,14 +46,14 @@ {% if personal_data %}
{% endif %} {% if medical_data %}
{% endif %} @@ -68,7 +68,7 @@ {% for key in keys %}
- +
diff --git a/client/templates/client/doc_edit.html b/client/templates/client/doc_edit.html new file mode 100644 index 0000000..8cd5a98 --- /dev/null +++ b/client/templates/client/doc_edit.html @@ -0,0 +1,86 @@ +{% extends 'registration/base.html' %} + +{% block title %}Modifica documento{% endblock %} + +{% block nav %} + Home + Modifica Documento +{% endblock %} + +{% block content %} +
+
+
+
+
+ {% csrf_token %} + +
+
+ + +
+
+ {% if personal_data %} + + {% endif %} + {% if medical_data %} + + {% endif %} + {% if custom_message %} + + {% endif %} + {% if custom_data %} + {% for key in keys %} +
+
+ + +
+
+ {% endfor %} + {% endif %} + +
+
+
+
+
+{% endblock %} + +{% block script %} +$(document).ready(function(){ + $('select').formSelect(); + {% if error %} + M.toast({html: '{{ error_text}}', classes: 'orange'}) + {% endif %} + }); +function send(id) { + var form = document.getElementById('form') + form.submit() +} +{% endblock %} \ No newline at end of file diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 96179b2..733f62f 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -13,6 +13,12 @@

Usa questo bottone per creare un nuovo documento

+ +
+ {% csrf_token %} + +
+ {% if user.is_authenticated %} {% if user.is_staff or perms.client.approved %} {% if not empty %} @@ -24,40 +30,83 @@ timelapse {% elif doc.0.status == "ok" %} check + {% elif doc.0.status == "autosign" %} + assignment_turned_in {% endif %} {{doc.0.document_type.name}} - {{doc.0.compilation_date}} + {{doc.0.compilation_date}}
{% if doc.0.status == "wait" %} - file_download Scarica documento per approvazione - delete Elimina documento - edit Modifica documento + file_download Scarica documento per approvazione + delete Elimina documento + edit Modifica documento +
+
+ {% elif doc.0.status == "autosign" %} + checkApprova documento + delete Elimina documento + edit Modifica documento

{% endif %} +
    {% if doc.0.document_type.personal_data %} - person +
  • +
    + personDati personali +
    +
    + + + {% for field in doc.2 %} + + + + {% endfor %} + +
    {{field}}
    +
    +
  • {% endif %} {% if doc.0.document_type.medical_data %} - healing +
  • +
    + healingDati medici +
    +
    + + + {% for field in doc.3 %} + + + + {% endfor %} + +
    {{field}}
    +
    +
  • {% endif %} {% if doc.0.document_type.custom_data %} - add_circle_outline - {% endif %} - {% if doc.0.document_type.custom_data %} -
    - - - {% for key in doc.1 %} - - - - - {% endfor %} - -
    {{key.key}}{{key.value}}
    +
  • +
    + add_circle_outlineDati aggiuntivi +
    +
    + + + {% for key in doc.1 %} + + + + + {% endfor %} + +
    {{key.key}}{{key.value}}
    +
    +
  • {% endif %} +
{% endfor %} @@ -73,7 +122,7 @@
-

Il tuo utente non e` ancora stato approvato.

+

Il tuo utente non è ancora stato approvato.

Come farsi approvare l'utente @@ -87,7 +136,7 @@
-

Se hai gia` un account clicca login in alto a destra. Altrimenti clicca registrazione

+

Se hai già un account clicca login in alto a destra. Altrimenti clicca registrazione

@@ -108,4 +157,10 @@ $('*').click(function(event) { $('.tap-target').tapTarget('close'); } }); +function send(id) { + var form = document.getElementById('form') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %} \ No newline at end of file diff --git a/client/urls.py b/client/urls.py index b58433e..164eefc 100644 --- a/client/urls.py +++ b/client/urls.py @@ -6,4 +6,5 @@ urlpatterns = [ path('', views.index, name='index'), path('approve', views.approve, name='approve'), path('create', views.create, name='create'), + path('edit', views.edit, name='edit'), ] diff --git a/client/views.py b/client/views.py index f70d930..b610962 100644 --- a/client/views.py +++ b/client/views.py @@ -1,6 +1,6 @@ from random import randint from django.contrib.auth.models import Group, Permission, User -from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal +from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData from django.db.models import Q from django.http import HttpResponseRedirect @@ -19,17 +19,54 @@ def index(request): code = randint(100000, 999999) if len(UserCode.objects.filter(code=code)) == 0: break - userCode = UserCode(user=request.user, code=code) + medic = MedicalData() + medic.save() + userCode = UserCode(user=request.user, code=code, medic=medic) userCode.save() + if request.method == "POST": + document = Document.objects.get(id=request.POST["action"][1:]) + if request.POST["action"][0] == 'f': + pass + elif request.POST["action"][0] == 'a': + document.status = "ok" + document.save() + elif request.POST["action"][0] == 'd': + document.delete() + elif request.POST["action"][0] == 'e': + document_type = document.document_type + context = { + 'doctype': document_type, + } + context['doc'] = document + context['personal_data'] = document_type.personal_data + context['medical_data'] = document_type.medical_data + context['custom_data'] = document_type.custom_data + keys = Keys.objects.filter(container=document_type) + out_keys = [] + for i in keys: + out_keys.append([i, KeyVal.objects.filter(Q(container=document) & Q(key=i.key))[0].value]) + context['keys'] = out_keys + context['custom_message'] = document_type.custom_message + context['custom_message_text'] = document_type.custom_message_text + return edit_wrapper(request, context) + documents = Document.objects.filter(Q(user=request.user) & ~Q(status='archive')) out = [] for i in documents: - out.append([i, KeyVal.objects.filter(container=i)]) + personal = None + medical = None + if i.document_type.personal_data: + personal = i.personal_data.__dict__.values() + if i.document_type.medical_data: + medical = i.medical_data.__dict__.values() + + out.append([i, KeyVal.objects.filter(container=i), personal, medical]) context = { "docs": out, "empty": len(out) == 0, } + return render(request, 'client/index.html', context) @@ -45,7 +82,6 @@ def approve(request): else: return render(request, 'client/index.html', context) - def create(request): context = {} if request.user.is_authenticated: @@ -59,7 +95,7 @@ def create(request): if len(Document.objects.filter(Q(user=request.user) & Q(document_type=doc))) == 0: out.append(doc) - context = {'docs': out} + context['docs'] = out if request.method == "POST": if request.POST["action"] == "details": if "doctype" not in request.POST.keys(): @@ -85,31 +121,84 @@ def create(request): code = 0 status = "wait" personal_data = None + medical_data = None document_type = DocumentType.objects.get( id=request.POST["doctype"]) + + if document_type.auto_sign: + status = "autosign" + keys = [] if document_type.personal_data: - personal_data = PersonalData(parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country, + personal_data = PersonalData(email=request.user.email, parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country, nationality=usercode.nationality, born_date=usercode.born_date, home_phone=usercode.home_phone, phone=usercode.phone) personal_data.save() + if document_type.medical_data: + medic = usercode.medic + medical_data = MedicalData(emer_name=medic.emer_name, emer_relative=medic.emer_relative, cell_phone=medic.cell_phone, address=medic.address, emer_phone=medic.emer_phone, health_care=medic.health_care, injuries=medic.injuries, rc=medic.rc, rega=medic.rega, medic_name=medic.medic_name, medic_phone=medic.medic_phone, medic_address=medic.medic_address, sickness=medic.sickness, vaccine=medic.vaccine, tetanus_date=medic.tetanus_date, allergy=medic.allergy, drugs_bool=medic.drugs_bool, drugs=medic.drugs, misc_bool=medic.misc_bool, misc=medic.misc) + medical_data.save() + while (True): code = randint(100000, 999999) if len(Document.objects.filter(code=code)) == 0: break document = Document( - user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data) + user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data, medical_data=medical_data) document.save() - for i in request.POST.keys(): - if i == "doctype" or i=="csrfmiddlewaretoken" or i=="action": - continue - key = KeyVal(container=document, key=Keys.objects.get(id=i).key, value=request.POST[i]) - key.save() + if document_type.custom_data: + for i in request.POST.keys(): + if i == "doctype" or i=="csrfmiddlewaretoken" or i=="action": + continue + key = KeyVal(container=document, key=Keys.objects.get(id=i).key, value=request.POST[i]) + key.save() return HttpResponseRedirect('/') return render(request, 'client/doc_create.html', context) else: return render(request, 'client/index.html', context) + +def edit(request): + return edit_wrapper(request, {}) + +def edit_wrapper(request, context): + if request.user.is_authenticated: + if request.method == "POST": + if "action" not in request.POST.keys(): + document = Document.objects.get(id=request.POST["doc"]) + usercode = UserCode.objects.filter(user=document.user)[0] + + if document.document_type.personal_data: + personal_data = PersonalData(email=request.user.email, parent_name=usercode.parent_name, via=usercode.via, cap=usercode.cap, country=usercode.country, + nationality=usercode.nationality, born_date=usercode.born_date, home_phone=usercode.home_phone, phone=usercode.phone) + personal_data.save() + old_data = document.personal_data + document.personal_data = personal_data + document.save() + old_data.delete() + + if document.document_type.medical_data: + medic = usercode.medic + medical_data = MedicalData(emer_name=medic.emer_name, emer_relative=medic.emer_relative, cell_phone=medic.cell_phone, address=medic.address, emer_phone=medic.emer_phone, health_care=medic.health_care, injuries=medic.injuries, rc=medic.rc, rega=medic.rega, medic_name=medic.medic_name, medic_phone=medic.medic_phone, medic_address=medic.medic_address, sickness=medic.sickness, vaccine=medic.vaccine, tetanus_date=medic.tetanus_date, allergy=medic.allergy, drugs_bool=medic.drugs_bool, drugs=medic.drugs, misc_bool=medic.misc_bool, misc=medic.misc) + medical_data.save() + old_data = document.medical_data + document.medical_data = medical_data + document.save() + old_data.delete() + + if document.document_type.custom_data: + for i in request.POST.keys(): + if i == "doc" or i=="csrfmiddlewaretoken": + continue + key = KeyVal.objects.filter(Q(container=document) & Q(key=Keys.objects.get(id=i).key))[0] + key.value = request.POST[i] + key.save() + + return HttpResponseRedirect('/') + + return render(request, 'client/doc_edit.html', context) + else: + return render(request, 'client/index.html', context) diff --git a/server/templates/server/doc_create.html b/server/templates/server/doc_create.html new file mode 100644 index 0000000..6454bee --- /dev/null +++ b/server/templates/server/doc_create.html @@ -0,0 +1,103 @@ +{% extends 'registration/base.html' %} + +{% block title %}Admin - Crea Tipo{% endblock %} + +{% block nav %} + Home + Admin + Tipo Doc + Crea Tipo +{% endblock %} + +{% block content %} +
+
+
+
+
+ {% csrf_token %} +
+
+ + +
+
+
+
+ +
+
+ +
+
+ + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ + +
+
+
+
+ + +
+
+ +
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_edit.html b/server/templates/server/doc_edit.html deleted file mode 100644 index 8b01c35..0000000 --- a/server/templates/server/doc_edit.html +++ /dev/null @@ -1,92 +0,0 @@ -{% extends 'registration/base.html' %} - -{% block title %}Admin - Modifica Tipo{% endblock %} - -{% block nav %} - Home - Admin - Tipo Doc - Modifica Doc -{% endblock %} - -{% block content %} -
-
-
-
-
- {% csrf_token %} -
-
- - -
-
-
-
- -
-
- -
-
-
-
- -
-
- -
-
- -
-
- -
-
-
-
-
- - -
-
-
-
- - -
-
- -
-
-
-
-
-{% endblock %} \ No newline at end of file diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index c5978b1..0b3d800 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -51,36 +51,68 @@ archive {% endif %} {{doc.0.document_type.name}} - {{doc.0.user.username}}
+ {{doc.0.user.username}}
{{doc.0.code}}
{{doc.0.compilation_date}}
+
    {% if doc.0.document_type.personal_data %} - person +
  • +
    + personDati personali +
    +
    + + + {% for field in doc.2 %} + + + + {% endfor %} + +
    {{field}}
    +
    +
  • {% endif %} {% if doc.0.document_type.medical_data %} - healing - {% endif %} - {% if doc.0.document_type.custom_message %} - message - {% endif %} - {% if doc.0.document_type.custom_data %} - add_circle_outline +
  • +
    + healingDati medici +
    +
    + + + {% for field in doc.3 %} + + + + {% endfor %} + +
    {{field}}
    +
    +
  • {% endif %} {% if doc.0.document_type.custom_data %} -
    - - - {% for key in doc.1 %} - - - - - {% endfor %} - -
    {{key.key}}{{key.value}}
    +
  • +
    + add_circle_outlineDati aggiuntivi +
    +
    + + + {% for key in doc.1 %} + + + + + {% endfor %} + +
    {{key.key}}{{key.value}}
    +
    +
  • {% endif %} +
{% endfor %} diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index fecfc9d..15ac30e 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -48,41 +48,64 @@ {% if not doctype.0.group_private %} public {% endif %} + {% if doctype.0.auto_sign %} + assignment_turned_in + {% endif %} {{doctype.0.name}} - {{doctype.2}}
+ {{doctype.2}}
+
    {% if doctype.0.personal_data %} - person +
  • +
    + personDati personali +
    +
  • {% endif %} {% if doctype.0.medical_data %} - healing - {% endif %} - {% if doctype.0.custom_data %} - add_circle_outline - {% endif %} - {% if doctype.0.custom_message %} - message +
  • +
    + healingDati medici +
    +
  • {% endif %} {% if doctype.0.custom_data %} -
    -
      - {% for key in doctype.1 %} -
    • {{key.key}}
    • - {% endfor %} -
    +
  • +
    + add_circle_outlineDati aggiuntivi +
    +
    + + + {% for key in doctype.1 %} + + + + {% endfor %} + +
    {{key.key}}
    +
    +
  • {% endif %} {% if doctype.0.custom_message %} -
    - {{doctype.0.custom_message_text}} +
  • +
    + messageMessaggio aggiuntivo +
    +
    + {{doctype.0.custom_message_text}} +
    +
  • {% endif %} +
{% endfor %}
- + add
diff --git a/server/templates/server/index.html b/server/templates/server/index.html index d88454f..199feb5 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -40,8 +40,21 @@
-

I am a very simple card. I am good at containing small bits of information. - I am convenient because I require little markup to use effectively.

+
    + {% for doctype in docs %} +
  • +
    + {% if not doctype.0.enabled %} + visibility_off + {% endif %} + {% if not doctype.0.group_private %} + public + {% endif %} + {{doctype.0.name}} + {{doctype.1}} +
    + {% endfor %} +
Lista tipo doc diff --git a/server/urls.py b/server/urls.py index fb2c2f2..773d910 100644 --- a/server/urls.py +++ b/server/urls.py @@ -7,7 +7,7 @@ urlpatterns = [ path('uapprove', views.uapprove, name='uapprove'), path('ulist', views.ulist, name='ulist'), path('doctype', views.doctype, name='doctype'), - path('docedit', views.docedit, name='docedit'), + path('doccreate', views.doccreate, name='doccreate'), path('doclist', views.doclist, name='doclist'), path('docapprove', views.docapprove, name='docapprove'), ] diff --git a/server/views.py b/server/views.py index b59dfb8..6c651f1 100644 --- a/server/views.py +++ b/server/views.py @@ -14,7 +14,7 @@ def index(request): parent_group = request.user.groups.values_list('name', flat=True)[ 0] users = User.objects.filter(groups__name=parent_group) - out = [] + users_out = [] for user in users: code = "" if len(UserCode.objects.filter(user=user)) > 0: @@ -26,9 +26,23 @@ def index(request): status = "Attivo" else: status = "In attesa" - out.append([user.username, user.first_name, + users_out.append([user.username, user.first_name, user.last_name, code, status]) - context = {'users': out} + + parent_group = request.user.groups.values_list('name', flat=True)[ + 0] + group = Group.objects.get(name=parent_group) + public_types = DocumentType.objects.filter( + Q(group_private=False) | Q(group=group)) + docs = [] + for doc in public_types: + ref_docs = Document.objects.filter(document_type=doc) + docs.append([doc, len(ref_docs)]) + + context = { + 'docs': docs, + 'users': users_out, + } return render(request, 'server/index.html', context) else: return render(request, 'client/index.html', context) @@ -44,7 +58,6 @@ def uapprove(request): group = Group.objects.get(name=parent_group) permission = Permission.objects.get(codename='approved') data = request.POST["codes"] - data = "".join(data.split()) data.replace("\r", "") data = data.split("\n") for i in range(len(data)): @@ -88,7 +101,6 @@ def docapprove(request): data = [] if request.method == "POST": data = request.POST["codes"] - data = "".join(data.split()) data.replace("\r", "") data = data.split("\n") for i in range(len(data)): @@ -101,7 +113,7 @@ def docapprove(request): else: document = Document.objects.filter(code=data[i])[0] if document.status == 'ok': - data[i] = data[i] + " - Gia` approvato" + data[i] = data[i] + " - GiĆ  approvato" else: document.status = 'ok' document.save() @@ -221,7 +233,7 @@ def doctype(request): return render(request, 'client/index.html', context) -def docedit(request): +def doccreate(request): context = {} if request.user.is_staff: parent_group = request.user.groups.values_list('name', flat=True)[ @@ -234,15 +246,17 @@ def docedit(request): custom_data = False name = "" - enabled_check = "" + enabled_check = 'checked="checked' private_check = 'checked="checked"' personal_check = 'checked="checked"' + sign_check = 'checked="checked' medical_check = "" custom_check = "" custom_message_check = "" context = { "enabled_check": enabled_check, "private_check": private_check, + "sign_check": sign_check, "personal_check": personal_check, "medical_check": medical_check, "custom_check": custom_check, @@ -250,6 +264,7 @@ def docedit(request): } if request.method == "POST": enabled = "enabled" in request.POST.keys() + auto_sign = "sign" not in request.POST.keys() group_private = "group_private" in request.POST.keys() personal_data = "personal_data" in request.POST.keys() medical_data = "medical_data" in request.POST.keys() @@ -257,18 +272,19 @@ def docedit(request): custom_message = "custom_message" in request.POST.keys() custom_message_text = request.POST["custom_message_text"] name = request.POST["name"] - custom = request.POST["custom"] - custom += " " - custom = custom.split("\n") doctype = DocumentType( - custom_message=custom_message, custom_message_text=custom_message_text, name=request.POST["name"], enabled=enabled, group_private=group_private, group=group, personal_data=personal_data, medical_data=medical_data, custom_data=custom_data) + auto_sign=auto_sign, custom_message=custom_message, custom_message_text=custom_message_text, name=request.POST["name"], enabled=enabled, group_private=group_private, group=group, personal_data=personal_data, medical_data=medical_data, custom_data=custom_data) doctype.save() - for i in custom: - key = Keys(key=i[:-1], container=doctype) - key.save() + if custom_data: + custom = request.POST["custom"] + custom.replace("\r", "") + custom = custom.split("\n") + for i in custom: + key = Keys(key=i, container=doctype) + key.save() return HttpResponseRedirect('doctype') - return render(request, 'server/doc_edit.html', context) + return render(request, 'server/doc_create.html', context) else: return render(request, 'client/index.html', context) @@ -305,8 +321,14 @@ def doclist(request): documents = Document.objects.filter(group=group) out = [] for i in documents: - custom_keys = KeyVal.objects.filter(container=i) - out.append([i, custom_keys]) + personal = None + medical = None + if i.document_type.personal_data: + personal = i.personal_data.__dict__.values() + if i.document_type.medical_data: + medical = i.medical_data.__dict__.values() + + out.append([i, KeyVal.objects.filter(container=i), personal, medical]) context = {"docs": out} return render(request, 'server/doc_list.html', context) else: -- cgit v1.2.1