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 --- 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 +++++++++++++++++++++--- 14 files changed, 542 insertions(+), 38 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 (limited to 'client') 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) -- cgit v1.2.1