diff options
Diffstat (limited to '')
-rw-r--r-- | client/migrations/0013_auto_20200620_1113.py | 19 | ||||
-rw-r--r-- | client/migrations/0014_auto_20200620_1506.py | 23 | ||||
-rw-r--r-- | client/models.py | 4 | ||||
-rw-r--r-- | client/templates/client/doc_create.html | 95 | ||||
-rw-r--r-- | client/templates/client/index.html | 55 | ||||
-rw-r--r-- | client/views.py | 77 | ||||
-rw-r--r-- | server/templates/server/approve_doc.html | 43 | ||||
-rw-r--r-- | server/templates/server/approve_user.html | 51 | ||||
-rw-r--r-- | server/templates/server/doc_edit.html | 19 | ||||
-rw-r--r-- | server/templates/server/doc_list.html | 65 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 52 | ||||
-rw-r--r-- | server/templates/server/index.html | 2 | ||||
-rw-r--r-- | server/urls.py | 1 | ||||
-rw-r--r-- | server/views.py | 105 |
14 files changed, 498 insertions, 113 deletions
diff --git a/client/migrations/0013_auto_20200620_1113.py b/client/migrations/0013_auto_20200620_1113.py new file mode 100644 index 0000000..d05a33d --- /dev/null +++ b/client/migrations/0013_auto_20200620_1113.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.7 on 2020-06-20 09:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0012_document_group'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='personal_data', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.PROTECT, to='client.PersonalData'), + ), + ] diff --git a/client/migrations/0014_auto_20200620_1506.py b/client/migrations/0014_auto_20200620_1506.py new file mode 100644 index 0000000..d0abc9c --- /dev/null +++ b/client/migrations/0014_auto_20200620_1506.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.7 on 2020-06-20 13:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('client', '0013_auto_20200620_1113'), + ] + + operations = [ + migrations.AddField( + model_name='documenttype', + name='custom_message', + field=models.BooleanField(default=False), + ), + migrations.AddField( + model_name='documenttype', + name='custom_message_text', + field=models.CharField(default='', max_length=250), + ), + ] diff --git a/client/models.py b/client/models.py index 01d5f4c..e7142ac 100644 --- a/client/models.py +++ b/client/models.py @@ -12,6 +12,8 @@ class DocumentType(models.Model): personal_data = models.BooleanField(default=False) medical_data = models.BooleanField(default=False) custom_data = models.BooleanField(default=False) + custom_message = models.BooleanField(default=False) + custom_message_text = models.CharField(default="", max_length=250) name = models.CharField(default="", max_length=250) @@ -36,7 +38,7 @@ class Document(models.Model): DocumentType, default=None, on_delete=models.PROTECT) personal_data = models.ForeignKey( - PersonalData, default=None, on_delete=models.PROTECT) + PersonalData, default=None, on_delete=models.PROTECT, null=True) class Meta: permissions = [ diff --git a/client/templates/client/doc_create.html b/client/templates/client/doc_create.html index a52518f..550eb54 100644 --- a/client/templates/client/doc_create.html +++ b/client/templates/client/doc_create.html @@ -4,7 +4,7 @@ {% block nav %} <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> - <a href="#!" class="breadcrumb hide-on-med-and-down">Crea Doc</a> + <a href="#!" class="breadcrumb hide-on-med-and-down">Crea Documento</a> {% endblock %} {% block content %} @@ -14,20 +14,78 @@ <div class="row"> <form id="form" action="{% url 'create'%}" method="post" class="col s12"> {% csrf_token %} - <div class="row"> - <div class="input-field col s12"> - <select name="doctype"> - <option value="" disabled selected>Scegli</option> - {% for doctype in docs%} - <option value="{{doctype.id}}">{{doctype.name}}</option> - {% endfor %} - </select> - <label>Documento</label> + <input type="hidden" name="action" id="action"> + {% if not next %} + <div class="row"> + <div class="input-field col s12"> + <select name="doctype"> + <option value="" disabled selected>Scegli</option> + {% for doctype in docs%} + <option value="{{doctype.id}}">{{doctype.name}}</option> + {% endfor %} + </select> + <label>Documento</label> + </div> </div> - </div> - <button class="btn waves-effect waves-light" type="submit" name="action">Invia - <i class="material-icons right">send</i> - </button> + <a class="btn waves-effect waves-light" onclick="window.history.back();" > + <i class="material-icons left">navigate_before</i>Indietro + </a> + <a class="btn waves-effect waves-light" onclick="send('details')" >Avanti + <i class="material-icons right">navigate_next</i> + </a> + {% else %} + <input type="hidden" name="doctype" value="{{doctype.id}}"> + <div class="row"> + <div class="input-field col s12"> + <select> + <option disabled selected>{{doctype.name}}</option> + </select> + <label>Documento</label> + </div> + </div> + {% if personal_data %} + <div class="row"> + <div class="col s12"> + <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterrá le informazioni personali, prego verificare che siano corrette e aggiornate</a> + </div> + </div> + {% endif %} + {% if medical_data %} + <div class="row"> + <div class="col s12"> + <a style="pointer-events: none; cursor: default;" class="btn red lighten-1"> Il documento conterrá le informazioni mediche, prego verificare che siano corrette e aggiornate</a> + </div> + </div> + {% endif %} + {% if custom_message %} + <div class="row"> + <div class="col s12"> + <a style="pointer-events: none; cursor: default;" class="btn red lighten-1">{{custom_message_text}}</a> + </div> + </div> + {% endif %} + {% if custom_data %} + {% for key in keys %} + <div class="row"> + <div class="input-field col s12"> + <input value="{{key.1}}" name="{{key.0.id}}" id="{{key.0.id}}" type="text" class="validate"> + <label for="{{key.0.id}}">{{key.0.key}}</label> + </div> + </div> + {% endfor %} + {% endif %} + <div class="row"> + <div class="col s12"> + <br> + <a class="btn waves-effect waves-light" onclick="window.history.back();" > + <i class="material-icons left">navigate_before</i>Indietro + </a> + <a class="btn waves-effect waves-light" onclick="send('save')" >Crea + <i class="material-icons right">create</i> + </a> + </div> + </div> + {% endif %} </form> </div> </div> @@ -38,5 +96,14 @@ {% 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') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %}
\ No newline at end of file diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 2b19f30..96179b2 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -15,34 +15,56 @@ </div> {% if user.is_authenticated %} {% if user.is_staff or perms.client.approved %} - <form id="selection" action="{% url 'doctype' %}" method="post"> - {% csrf_token %} + {% if not empty %} <ul class="collapsible"> {% for doc in docs %} <li> <div class="collapsible-header"> - <label> - <input name={{doc.id}} type="checkbox" class="filled-in"/> - <span></span> - </label> - {% if doc.enabled %} - <i class="material-icons">visibility_on</i> - {% else %} - <i class="material-icons">visibility_off</i> + {% if doc.0.status == "wait" %} + <i class="material-icons">timelapse</i> + {% elif doc.0.status == "ok" %} + <i class="material-icons">check</i> {% endif %} - {{doc.document_type.name}} + {{doc.0.document_type.name}} + <span class="badge" data-badge-caption="">{{doc.0.compilation_date}}</span></div> </div> <div class="collapsible-body"><span> - {% for key in keys %} - {{key}}<br> - {% endfor %} + {% if doc.0.status == "wait" %} + <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a> + <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">delete</i> Elimina documento</a> + <a class="waves-effect waves-light btn red lighten-1" href="{%url 'server'%}"><i class="material-icons left">edit</i> Modifica documento</a> + <br> + <br> + {% endif %} + {% if doc.0.document_type.personal_data %} + <i class="material-icons">person</i> + {% endif %} + {% if doc.0.document_type.medical_data %} + <i class="material-icons">healing</i> + {% endif %} + {% if doc.0.document_type.custom_data %} + <i class="material-icons">add_circle_outline</i> + {% endif %} + {% if doc.0.document_type.custom_data %} + <br> + <table class="striped"> + <tbody> + {% for key in doc.1 %} + <tr> + <td>{{key.key}}</td> + <td>{{key.value}}</td> + </tr> + {% endfor %} + </tbody> + </table> + {% endif %} </span></div> </li> {% endfor %} </ul> - </form> + {% endif %} <div class="fixed-action-btn"> - <a id="add" class="btn-floating btn-large red lightend-1" href="{% url 'create'%}"> + <a id="add" class="btn-floating btn-large red lighten-1" href="{% url 'create'%}"> <i class="large material-icons">add</i> </a> </div> @@ -75,6 +97,7 @@ {% block script %} $(document).ready(function(){ + $('.collapsible').collapsible(); $('.tap-target').tapTarget(); {% if empty %} $('.tap-target').tapTarget('open'); diff --git a/client/views.py b/client/views.py index 78ca7d1..f70d930 100644 --- a/client/views.py +++ b/client/views.py @@ -1,7 +1,8 @@ from random import randint from django.contrib.auth.models import Group, Permission, User -from client.models import UserCode, Keys, DocumentType, Document, PersonalData +from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal from django.db.models import Q +from django.http import HttpResponseRedirect from django.shortcuts import render @@ -21,10 +22,10 @@ def index(request): userCode = UserCode(user=request.user, code=code) userCode.save() - documents = Document.objects.filter(user=request.user) + documents = Document.objects.filter(Q(user=request.user) & ~Q(status='archive')) out = [] for i in documents: - out.append(i) + out.append([i, KeyVal.objects.filter(container=i)]) context = { "docs": out, "empty": len(out) == 0, @@ -51,31 +52,63 @@ def create(request): 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)) + doctypes = DocumentType.objects.filter( + (Q(group_private=False) | Q(group=group)) & Q(enabled=True)) out = [] - for doc in public_types: - out.append(doc) + for doc in doctypes: + if len(Document.objects.filter(Q(user=request.user) & Q(document_type=doc))) == 0: + out.append(doc) context = {'docs': out} if request.method == "POST": - usercode = UserCode.objects.filter(user=request.user)[0] - code = 0 - status = 0 - document_type = DocumentType.objects.get( - id=request.POST["doctype"]) - personal_data = PersonalData(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 request.POST["action"] == "details": + if "doctype" not in request.POST.keys(): + context['error'] = True + context['error_text'] = "Seleziona un documento" + else: + context['next'] = True + document_type = DocumentType.objects.get( + id=request.POST["doctype"]) + context['doctype'] = document_type + 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, ""]) + context['keys'] = out_keys + context['custom_message'] = document_type.custom_message + context['custom_message_text'] = document_type.custom_message_text + elif request.POST["action"] == "save": + usercode = UserCode.objects.filter(user=request.user)[0] + code = 0 + status = "wait" + personal_data = None + document_type = DocumentType.objects.get( + id=request.POST["doctype"]) + keys = [] + if document_type.personal_data: + personal_data = PersonalData(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() - while (True): - code = randint(100000, 999999) - if len(Document.objects.filter(code=code)) == 0: - break + 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) + 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() - document = Document( - user=request.user, group=group, code=code, status=status, document_type=document_type, personal_data=personal_data) - document.save() + return HttpResponseRedirect('/') return render(request, 'client/doc_create.html', context) else: diff --git a/server/templates/server/approve_doc.html b/server/templates/server/approve_doc.html new file mode 100644 index 0000000..82ecf2a --- /dev/null +++ b/server/templates/server/approve_doc.html @@ -0,0 +1,43 @@ +{% extends 'registration/base.html' %} + +{% block title %}Admin - Approva Utente{% endblock %} + +{% block nav %} + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> + <a href="{% url 'docapprove'%}" class="breadcrumb hide-on-med-and-down">Approva Documento</a> +{% endblock %} + +{% block content %} + +{% if not empty %} + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <ul class="collection"> + {% for i in messages %} + <li class="collection-item">{{ i }}</li> + {% endfor %} + </ul> + </div> + </div> + </div> +{% endif %} + +<div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <form id="form" action="{% url 'docapprove'%}" method="post"> + {% csrf_token %} + <div class="card-content"> + <p>Inserire un codice per riga</p> + <textarea name="codes" class="materialize-textarea"></textarea> + </div> + <div class="card-action"> + <a href="#" onclick="document.getElementById('form').submit()">Invia</a> + </div> + </form> + </div> + </div> +</div> +{% endblock %}
\ No newline at end of file diff --git a/server/templates/server/approve_user.html b/server/templates/server/approve_user.html index 126c0b9..9d4b36c 100644 --- a/server/templates/server/approve_user.html +++ b/server/templates/server/approve_user.html @@ -3,24 +3,41 @@ {% block title %}Admin - Approva Utente{% endblock %} {% block nav %} - <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> - <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> - <a href="#!" class="breadcrumb hide-on-med-and-down">Approva Utente</a> + <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> + <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> + <a href="{% url 'uapprove'%}" class="breadcrumb hide-on-med-and-down">Approva Utente</a> {% endblock %} {% block content %} -<p>Inserire un codice per riga</p> -<ul class="collection"> -{% for i in messages %} - <li class="collection-item">{{ i }}</li> -{% endfor %} -</ul> -<form action="{% url 'uapprove'%}" method="post"> - {% csrf_token %} - <textarea name="codes" class="materialize-textarea"></textarea> - <br><br> - <button type="submit" class="btn waves-effect waves-light">Invia - <i class="material-icons right">send</i> - </button> -</form> + +{% if not empty %} + <div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <ul class="collection"> + {% for i in messages %} + <li class="collection-item">{{ i }}</li> + {% endfor %} + </ul> + </div> + </div> + </div> +{% endif %} + +<div class="row"> + <div class="col l4 offset-l4 m8 offset-m2 s12"> + <div class="card"> + <form id="form" action="{% url 'uapprove'%}" method="post"> + {% csrf_token %} + <div class="card-content"> + <p>Inserire un codice per riga</p> + <textarea name="codes" class="materialize-textarea"></textarea> + </div> + <div class="card-action"> + <a href="#" onclick="document.getElementById('form').submit()">Invia</a> + </div> + </form> + </div> + </div> +</div> {% endblock %}
\ No newline at end of file diff --git a/server/templates/server/doc_edit.html b/server/templates/server/doc_edit.html index cca0607..8b01c35 100644 --- a/server/templates/server/doc_edit.html +++ b/server/templates/server/doc_edit.html @@ -41,31 +41,44 @@ </div> </div> <div class="row"> - <div class="input-field col s3"> + <div class="input-field col s2"> <label> <input name="personal_data" type="checkbox" class="filled-in" {{personal_check}}/> <span>Dati personali</span> </label> </div> - <div class="input-field col s3"> + <div class="input-field col s2"> <label> <input name="medical_data" type="checkbox" class="filled-in" {{medical_check}} /> <span>Dati medici</span> </label> </div> - <div class="input-field col s3"> + <div class="input-field col s4"> <label> <input name="custom_data" type="checkbox" class="filled-in" {{custom_check}}/> <span>Parametri personalizzati</span> </label> </div> + <div class="input-field col s4"> + <label> + <input name="custom_message" type="checkbox" class="filled-in" {{custom_message_check}}/> + <span>Messaggio personalizzato</span> + </label> + </div> </div> + <br> <div class="row"> <div class="input-field col s12"> <textarea name="custom" id="textarea" class="materialize-textarea"></textarea> <label for="textarea">Lista parametri personalizzati, uno per riga</label> </div> </div> + <div class="row"> + <div class="input-field col s12"> + <textarea name="custom_message_text" id="textarea" class="materialize-textarea"></textarea> + <label for="textarea">Messaggio personalizzato</label> + </div> + </div> <div class="fixed-action-btn"> <a class="btn-floating btn-large red lighten-1" onclick="document.getElementById('form').submit()"> <i class="large material-icons">save</i> diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index cf98010..c5978b1 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -7,10 +7,12 @@ <div class="nav-wrapper red lighten-1"> <a style="margin-left: 10px;" href="{% url 'index' %}" class="breadcrumb">Home</a> <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a> - <a href="{% url 'doctype' %}" class="breadcrumb hide-on-med-and-down">Documenti</a> + <a href="{% url 'doclist' %}" class="breadcrumb hide-on-med-and-down">Documenti</a> <ul class="right"> {% if user.is_staff %} - <li><a onclick="document.getElementById('selection').submit()">Elimina selezionati</a></li> + <li><a onclick="send('archive')">Archivia selezionati</a></li> + <li><a onclick="send('approve')">Approva selezionati</a></li> + <li><a onclick="send('delete')">Elimina selezionati</a></li> <li><a href="{% url 'server' %}">Pannello Admin</a></li> {% endif %} {% if user.is_authenticated %} @@ -30,41 +32,70 @@ {% endblock %} {% block content %} -<form id="selection" action="{% url 'doctype' %}" method="post"> +<form id="selection" action="{% url 'doclist' %}" method="post"> {% csrf_token %} +<input type="hidden" name="action" id="action"> <ul class="collapsible"> {% for doc in docs %} <li> <div class="collapsible-header"> <label> - <input name={{doc.id}} type="checkbox" class="filled-in"/> + <input name={{doc.0.id}} type="checkbox" class="filled-in"/> <span></span> </label> - {% if doc.enabled %} - <i class="material-icons">visibility_on</i> - {% else %} - <i class="material-icons">visibility_off</i> + {% if doc.0.status == "wait" %} + <i class="material-icons">timelapse</i> + {% elif doc.0.status == "ok" %} + <i class="material-icons">check</i> + {% elif doc.0.status == "archive" %} + <i class="material-icons">archive</i> {% endif %} - {{doc.document_type.name}} + {{doc.0.document_type.name}} + <span class="badge" data-badge-caption="">{{doc.0.user.username}}</span></div> </div> <div class="collapsible-body"><span> - {% for key in keys %} - {{key}}<br> - {% endfor %} + {{doc.0.code}} <br> + {{doc.0.compilation_date}}<br> + {% if doc.0.document_type.personal_data %} + <i class="material-icons">person</i> + {% endif %} + {% if doc.0.document_type.medical_data %} + <i class="material-icons">healing</i> + {% endif %} + {% if doc.0.document_type.custom_message %} + <i class="material-icons">message</i> + {% endif %} + {% if doc.0.document_type.custom_data %} + <i class="material-icons">add_circle_outline</i> + {% endif %} + {% if doc.0.document_type.custom_data %} + <br> + <table class="striped"> + <tbody> + {% for key in doc.1 %} + <tr> + <td>{{key.key}}</td> + <td>{{key.value}}</td> + </tr> + {% endfor %} + </tbody> + </table> + {% endif %} </span></div> </li> {% endfor %} </ul> </form> -<div class="fixed-action-btn"> - <a class="btn-floating btn-large red lightend-1" href="{% url 'docedit'%}"> - <i class="large material-icons">add</i> - </a> -</div> {% endblock %} {%block script%} $(document).ready(function(){ $('.collapsible').collapsible(); }); +function send(id) { + var form = document.getElementById('selection') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %}
\ No newline at end of file diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index 75bb79a..fecfc9d 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -10,7 +10,8 @@ <a href="{% url 'doctype' %}" class="breadcrumb hide-on-med-and-down">Tipo Doc</a> <ul class="right"> {% if user.is_staff %} - <li><a onclick="document.getElementById('selection').submit()">Elimina selezionati</a></li> + <li><a onclick="send('hide')">Nascondi/mostra selezionati</a></li> + <li><a onclick="send('delete')">Elimina selezionati</a></li> <li><a href="{% url 'server' %}">Pannello Admin</a></li> {% endif %} {% if user.is_authenticated %} @@ -32,32 +33,56 @@ {% block content %} <form id="selection" action="{% url 'doctype' %}" method="post"> {% csrf_token %} +<input type="hidden" name="action" id="action"> <ul class="collapsible"> {% for doctype in docs %} <li> <div class="collapsible-header"> <label> - <input name={{doctype.id}} type="checkbox" class="filled-in"/> + <input name={{doctype.0.id}} type="checkbox" class="filled-in"/> <span></span> </label> - {% if doctype.enabled %} - <i class="material-icons">visibility_on</i> - {% else %} + {% if not doctype.0.enabled %} <i class="material-icons">visibility_off</i> {% endif %} - {{doctype.name}} + {% if not doctype.0.group_private %} + <i class="material-icons">public</i> + {% endif %} + {{doctype.0.name}} + <span class="new badge red lighten-1" data-badge-caption="">{{doctype.2}}</span></div> </div> <div class="collapsible-body"><span> - {% for key in keys %} - {{key}}<br> - {% endfor %} + {% if doctype.0.personal_data %} + <i class="material-icons">person</i> + {% endif %} + {% if doctype.0.medical_data %} + <i class="material-icons">healing</i> + {% endif %} + {% if doctype.0.custom_data %} + <i class="material-icons">add_circle_outline</i> + {% endif %} + {% if doctype.0.custom_message %} + <i class="material-icons">message</i> + {% endif %} + {% if doctype.0.custom_data %} + <br> + <ul class="collection"> + {% for key in doctype.1 %} + <li class="collection-item">{{key.key}}</li> + {% endfor %} + </ul> + {% endif %} + {% if doctype.0.custom_message %} + <br> + {{doctype.0.custom_message_text}} + {% endif %} </span></div> </li> {% endfor %} </ul> </form> <div class="fixed-action-btn"> - <a class="btn-floating btn-large red lightend-1" href="{% url 'docedit'%}"> + <a class="btn-floating btn-large red lighten-1" href="{% url 'docedit'%}"> <i class="large material-icons">add</i> </a> </div> @@ -67,4 +92,11 @@ $(document).ready(function(){ $('.collapsible').collapsible(); }); + +function send(id) { + var form = document.getElementById('selection') + var action = document.getElementById('action') + action.setAttribute('value', id); + form.submit() +} {% endblock %}
\ No newline at end of file diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 4095d4a..d88454f 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -46,7 +46,7 @@ <div class="card-action"> <a href="{% url 'doctype' %}">Lista tipo doc</a> <a href="{% url 'doclist' %}">Lista documenti</a> - <a href="{% url 'uapprove' %}">Approva documento</a> + <a href="{% url 'docapprove' %}">Approva documento</a> </div> </div> </div> diff --git a/server/urls.py b/server/urls.py index de94d50..fb2c2f2 100644 --- a/server/urls.py +++ b/server/urls.py @@ -9,4 +9,5 @@ urlpatterns = [ path('doctype', views.doctype, name='doctype'), path('docedit', views.docedit, name='docedit'), path('doclist', views.doclist, name='doclist'), + path('docapprove', views.docapprove, name='docapprove'), ] diff --git a/server/views.py b/server/views.py index aed1fb6..b59dfb8 100644 --- a/server/views.py +++ b/server/views.py @@ -1,8 +1,9 @@ from django.shortcuts import render -from client.models import UserCode, Keys, DocumentType, Document +from client.models import UserCode, Keys, DocumentType, Document, KeyVal from django.contrib.auth.models import Group, Permission, User from django.db.models import Q from django.http import HttpResponseRedirect +from django.db.models.deletion import ProtectedError # Create your views here. @@ -36,25 +37,27 @@ def index(request): def uapprove(request): context = {} if (request.user.is_staff): + data = [] if request.method == "POST": parent_group = request.user.groups.values_list('name', flat=True)[ 0] group = Group.objects.get(name=parent_group) permission = Permission.objects.get(codename='approved') data = request.POST["codes"] - data += " " + data = "".join(data.split()) + data.replace("\r", "") data = data.split("\n") for i in range(len(data)): if not data[i].startswith("U"): data[i] = data[i] + " - Formato errato" - elif not data[i][1:-1].isdigit(): + elif not data[i][1:].isdigit(): data[i] = data[i] + " - Formato errato" - elif int(data[i][1:-1]) < 100000 or int(data[i][1:-1]) > 999999: + elif int(data[i][1:]) < 100000 or int(data[i][1:]) > 999999: data[i] = data[i] + " - Formato errato" - elif len(UserCode.objects.filter(code=data[i][1:-1])) == 0: + elif len(UserCode.objects.filter(code=data[i][1:])) == 0: data[i] = data[i] + " - Invalido" else: - user = UserCode.objects.filter(code=data[i][1:-1])[0].user + user = UserCode.objects.filter(code=data[i][1:])[0].user if len(user.groups.values_list('name', flat=True)) == 0: user.groups.add(group) user.user_permissions.add(permission) @@ -62,20 +65,58 @@ def uapprove(request): else: if user.groups.values_list('name', flat=True)[0] == parent_group: user.user_permissions.add(permission) - data[i] = data[i] + " - Gia` aggiunto" + data[i] = data[i] + " - Ok" else: user.groups.clear() user.groups.add(group) user.user_permissions.add(permission) data[i] = data[i] + " - Ok, cambio branca" - context = {'messages': data} + context = { + 'messages': data, + 'empty': len(data) == 0, + } return render(request, 'server/approve_user.html', context) else: return render(request, 'client/index.html', context) +def docapprove(request): + context = {} + if (request.user.is_staff): + 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)): + if not data[i].isdigit(): + data[i] = data[i] + " - Formato errato" + elif int(data[i]) < 100000 or int(data[i]) > 999999: + data[i] = data[i] + " - Formato errato" + elif len(Document.objects.filter(code=data[i])) == 0: + data[i] = data[i] + " - Invalido" + else: + document = Document.objects.filter(code=data[i])[0] + if document.status == 'ok': + data[i] = data[i] + " - Gia` approvato" + else: + document.status = 'ok' + document.save() + data[i] = data[i] + " - Ok" + + context = { + 'messages': data, + 'empty': len(data) == 0, + } + + return render(request, 'server/approve_doc.html', context) + else: + return render(request, 'client/index.html', context) + + def ulist(request): context = {} if (request.user.is_staff): @@ -148,10 +189,20 @@ def doctype(request): for i in request.POST.keys(): if i == "csrfmiddlewaretoken": continue + if i == "action": + continue + selected.append(DocumentType.objects.get(id=i)) for i in selected: - i.delete() + if request.POST["action"] == 'delete': + try: + i.delete() + except ProtectedError: + print("nope") + elif request.POST["action"] == 'hide': + i.enabled = not i.enabled + i.save() parent_group = request.user.groups.values_list('name', flat=True)[ 0] @@ -160,7 +211,9 @@ def doctype(request): Q(group_private=False) | Q(group=group)) out = [] for doc in public_types: - out.append(doc) + custom_keys = Keys.objects.filter(container=doc) + ref_docs = Document.objects.filter(document_type=doc) + out.append([doc, custom_keys, len(ref_docs)]) context = {'docs': out} return render(request, 'server/doc_type.html', context) @@ -186,12 +239,14 @@ def docedit(request): personal_check = 'checked="checked"' medical_check = "" custom_check = "" + custom_message_check = "" context = { "enabled_check": enabled_check, "private_check": private_check, "personal_check": personal_check, "medical_check": medical_check, "custom_check": custom_check, + "custom_message_check": custom_message_check, } if request.method == "POST": enabled = "enabled" in request.POST.keys() @@ -199,12 +254,14 @@ def docedit(request): personal_data = "personal_data" in request.POST.keys() medical_data = "medical_data" in request.POST.keys() custom_data = "custom_data" in request.POST.keys() + 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( - name=request.POST["name"], enabled=enabled, group_private=group_private, group=group, personal_data=personal_data, medical_data=medical_data, custom_data=custom_data) + 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) @@ -219,13 +276,37 @@ def docedit(request): def doclist(request): context = {} if request.user.is_staff: + if request.method == "POST": + selected = [] + for i in request.POST.keys(): + if i == "csrfmiddlewaretoken": + continue + if i == "action": + continue + + selected.append(Document.objects.get(id=i)) + + for i in selected: + if request.POST["action"] == 'delete': + try: + i.delete() + except ProtectedError: + print("nope") + elif request.POST["action"] == 'approve': + i.status = 'ok' + i.save() + elif request.POST["action"] == 'archive': + i.status = 'archive' + i.save() + parent_group = request.user.groups.values_list('name', flat=True)[ 0] group = Group.objects.get(name=parent_group) documents = Document.objects.filter(group=group) out = [] for i in documents: - out.append(i) + custom_keys = KeyVal.objects.filter(container=i) + out.append([i, custom_keys]) context = {"docs": out} return render(request, 'server/doc_list.html', context) else: |