diff options
-rw-r--r-- | accounts/views.py | 8 | ||||
-rw-r--r-- | client/templates/client/approve_doc_pdf.html | 99 | ||||
-rw-r--r-- | client/views.py | 15 | ||||
-rw-r--r-- | server/templates/server/doc_list.html | 123 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 94 | ||||
-rw-r--r-- | server/templates/server/index.html | 3 | ||||
-rw-r--r-- | server/views.py | 106 | ||||
-rw-r--r-- | templates/registration/base_custom.html | 2 |
8 files changed, 422 insertions, 28 deletions
diff --git a/accounts/views.py b/accounts/views.py index 36f59cd..804a841 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -77,10 +77,16 @@ def personal(request): else: parent_group = request.user.groups.values_list('name', flat=True)[ 0] - if parent_group == "muta": + if parent_group == "colonia": + branca_castorini = "selected" + elif parent_group == "muta": branca_lupetti = "selected" elif parent_group == "reparto": branca_esploratori = "selected" + elif parent_group == "posto": + branca_pionieri = "selected" + elif parent_group == "clan": + branca_rover = "selected" else: branca_default = "selected" diff --git a/client/templates/client/approve_doc_pdf.html b/client/templates/client/approve_doc_pdf.html new file mode 100644 index 0000000..4b7df8b --- /dev/null +++ b/client/templates/client/approve_doc_pdf.html @@ -0,0 +1,99 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title></title> +<style> +.center { + text-align: center; +} +.left { + text-align: left; +} +.right { + text-align: right; +} + +h1, h2, h3, h4, h5, h6 { + font-weight: 400; + line-height: 1.3; +} + +h1 { + font-size: 4.2rem; + line-height: 110%; + margin: 2.8rem 0 1.68rem 0; +} + +h2 { + font-size: 3.56rem; + line-height: 110%; + margin: 2.3733333333rem 0 1.424rem 0; +} + +h3 { + font-size: 2.92rem; + line-height: 110%; + margin: 1.9466666667rem 0 1.168rem 0; +} + +h4 { + font-size: 2.28rem; + line-height: 110%; + margin: 1.52rem 0 0.912rem 0; +} + +h5 { + font-size: 1.64rem; + line-height: 110%; + margin: 1.0933333333rem 0 0.656rem 0; +} + +h6 { + font-size: 1.15rem; + line-height: 110%; + margin: 0.7666666667rem 0 0.46rem 0; +} + +.footer { +} + +.content { + margin-left: 25%; + width: 50%; +} + +table { + border-collapse:collapse; + margin:0px; + padding:0; + width:100%; +} + +</style> +</head> +<body> + <main style="margin-left: 10px;margin-right: 10px;margin-top: 10px;"> + <div class="title"><h1 class="center">{{doc.code}}</h1></div> + <div class="code"><h3 class="center">{{doc.document_type.name}}</h3></div> + <div class="content"> + <p>Con la presente firma approvo il documento con codice {{doc.code}} accettando + tutte le clausole apposte su di esso. + Inoltre comprovo come veritieri e completi tutti i dati apposti sul documento. + </p> + </div> + <br><br><br><br> + <br><br><br><br> + <br><br><br><br> + <br><br><br><br> + <div class"footer"> + <table> + <tr> + <td><h4 class="left">Data</h4></div></td> + <td><h4 class="right">Firma</h4></td> + </tr> + </table> + </div> + </main> +</body> +</html>
\ No newline at end of file diff --git a/client/views.py b/client/views.py index b610962..b16e64a 100644 --- a/client/views.py +++ b/client/views.py @@ -2,10 +2,14 @@ from random import randint from django.contrib.auth.models import Group, Permission, User from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData from django.db.models import Q -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, FileResponse from django.shortcuts import render +from xhtml2pdf import pisa +from django.template.loader import get_template +from io import BytesIO + # Create your views here. @@ -27,7 +31,14 @@ def index(request): if request.method == "POST": document = Document.objects.get(id=request.POST["action"][1:]) if request.POST["action"][0] == 'f': - pass + template = get_template('client/approve_doc_pdf.html') + context = {'doc': document} + html = template.render(context) + result = BytesIO() + pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result) + + result.seek(0) + return FileResponse(result, as_attachment=True, filename=document.document_type.name+".pdf") elif request.POST["action"][0] == 'a': document.status = "ok" document.save() diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index 0b3d800..730837c 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -3,16 +3,13 @@ {% block title %}Admin - Documenti{% endblock %} {% block nav %} - <nav> + <nav class="nav-extended"> <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 'doclist' %}" class="breadcrumb hide-on-med-and-down">Documenti</a> <ul class="right"> {% if user.is_staff %} - <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 %} @@ -28,12 +25,86 @@ {% endif %} </ul> </div> + <div class="nav-wrapper red lighten-1"> + <ul> + <li> + <input id="select-all" type="checkbox" class="filled-in"/> + <label for="select-all"> + <a class="tooltipped" data-position="top" data-tooltip="(De)Seleziona tutti" onclick=""><i class="material-icons">select_all</i> + </label> + </a> + </li> + <li><a class="tooltipped" data-position="top" data-tooltip="Archivia selezionati" onclick="send('archive')"><i class="material-icons">archive</i></a></li> + <li><a class="tooltipped" data-position="top" data-tooltip="Dearchivia selezionati" Onclick="send('unarchive')"><i class="material-icons">unarchive</i></a></li> + <li><a class="tooltipped" data-position="top" data-tooltip="Approva selezionati" Onclick="send('approve')"><i class="material-icons left">check</i>DEBUG</a></li> + <li><a class="tooltipped" data-position="top" data-tooltip="Elimina selezionati" Onclick="send('delete')"><i class="material-icons left">delete</i>DEBUG</a></li> + </ul> + <ul class="right"> + <li><a href="#modal1" data-target="modal1" class="modal-trigger tooltipped" data-position="top" data-tooltip="Filtri"><i class="material-icons">filter_list</i></a></li> + </ul> + </div> </nav> {% endblock %} {% block content %} <form id="selection" action="{% url 'doclist' %}" method="post"> {% csrf_token %} +<div id="modal1" class="modal"> + <div class="modal-content"> + <h5>Filtri</h5> + <div class="row"> + <div class="input-field col s3"> + <label> + <input name="filter_hidden" type="checkbox" class="filled-in" {{hidden_check}}/> + <span><i class="material-icons left">archive</i>Archiviati</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_public" type="checkbox" class="filled-in" {{public_check}}/> + <span><i class="material-icons left">timelapse</i>In Attesa</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_selfsign" type="checkbox" class="filled-in" {{selfsign_check}}/> + <span><i class="material-icons left">assignment_turned_in</i>No firma</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_personal" type="checkbox" class="filled-in" {{personal_check}}/> + <span><i class="material-icons left">check</i>Approvati</span> + </label> + </div> + </div> + <div class="row"> + <div class="input-field col s6"> + <label for="tetanus_date">Più recenti di</label> + <input value="{{tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text" class="datepicker"> + </div> + <div class="input-field col s6"> + <label for="tetanus_date">Più vecchi di</label> + <input value="{{tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text" class="datepicker"> + </div> + </div> + <div class ="row"> + <div class="input-field col s12"> + <input value="{{misc}}" name="misc" id="misc" type="text" data-length="250"> + <label for="misc">Tipo di documento</label> + </div> + </div> + <div class ="row"> + <div class="input-field col s12"> + <input value="{{misc}}" name="misc" id="misc" type="text" data-length="250"> + <label for="misc">Proprietario del documento</label> + </div> + </div> + </div> + <div class="modal-footer"> + <a href="#!" onclick="send('filter')" class="modal-close waves-effect waves-green btn-flat">Applica</a> + </div> +</div> <input type="hidden" name="action" id="action"> <ul class="collapsible"> {% for doc in docs %} @@ -49,6 +120,8 @@ <i class="material-icons">check</i> {% elif doc.0.status == "archive" %} <i class="material-icons">archive</i> + {% elif doc.0.status == "autosign" %} + <i class="material-icons">assignment_turned_in</i> {% endif %} {{doc.0.document_type.name}} <span class="badge" data-badge-caption="">{{doc.0.user.username}}</span> @@ -123,6 +196,11 @@ {%block script%} $(document).ready(function(){ $('.collapsible').collapsible(); + $('.tooltipped').tooltip(); + $('.modal').modal(); + {% if error %} + M.toast({html: '{{ error_text}}', classes: 'orange'}) + {% endif %} }); function send(id) { var form = document.getElementById('selection') @@ -130,4 +208,41 @@ function send(id) { action.setAttribute('value', id); form.submit() } +$('#select-all').click(function(event) { + if(this.checked) { + // Iterate each checkbox + $(':checkbox').each(function() { + this.checked = true; + }); + } else { + $(':checkbox').each(function() { + this.checked = false; + }); + } +}); +var options = { + container: document.getElementById('main'), + yearRange:100, + 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' ], + weekdays: [ 'domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato' ], + weekdaysShort: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ], + weekdaysAbbrev: [ 'D', 'L', 'M', 'M', 'G', 'V', 'S' ], + today: 'Oggi', + clear: 'Cancella', + close: 'Chiudi', + firstDay: 1, + format: 'dddd d mmmm yyyy', + formatSubmit: 'yyyy/mm/dd', + labelMonthNext: 'Mese successivo', + labelMonthPrev: 'Mese precedente', + labelMonthSelect: 'Seleziona un mese', + labelYearSelect: 'Seleziona un anno' + }} + document.addEventListener('DOMContentLoaded', function() { + var elems = document.querySelectorAll('.datepicker'); + var instances = M.Datepicker.init(elems, options); + }); {% endblock %}
\ No newline at end of file diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index 15ac30e..4e8a14a 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -3,15 +3,13 @@ {% block title %}Admin - Tipo Documenti{% endblock %} {% block nav %} - <nav> + <nav class="nav-extended"> <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">Tipo Doc</a> <ul class="right"> {% if user.is_staff %} - <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 %} @@ -27,12 +25,84 @@ {% endif %} </ul> </div> + <div class="nav-wrapper red lighten-1"> + <ul> + <li> + <input id="select-all" type="checkbox" class="filled-in"/> + <label for="select-all"> + <a class="tooltipped" data-position="top" data-tooltip="(De)Seleziona tutti" onclick=""><i class="material-icons">select_all</i> + </label> + </a> + </li> + <li><a class="tooltipped" data-position="top" data-tooltip="Mostra selezionati" onclick="send('show')"><i class="material-icons">visibility</i></a></li> + <li><a class="tooltipped" data-position="top" data-tooltip="Nascondi selezionati" Onclick="send('hide')"><i class="material-icons">visibility_off</i></a></li> + <li><a class="tooltipped" data-position="top" data-tooltip="Elimina selezionati" Onclick="send('delete')"><i class="material-icons">delete</i></a></li> + </ul> + <ul class="right"> + <li><a href="#modal1" data-target="modal1" class="modal-trigger tooltipped" data-position="top" data-tooltip="Filtri"><i class="material-icons">filter_list</i></a></li> + </ul> + </div> </nav> {% endblock %} {% block content %} <form id="selection" action="{% url 'doctype' %}" method="post"> {% csrf_token %} +<div id="modal1" class="modal"> + <div class="modal-content"> + <h5>Filtri</h5> + <div class="row"> + <div class="input-field col s4"> + <label> + <input name="filter_hidden" type="checkbox" class="filled-in" {{hidden_check}}/> + <span><i class="material-icons left">visibility_off</i>Disabilitati</span> + </label> + </div> + <div class="input-field col s4"> + <label> + <input name="filter_public" type="checkbox" class="filled-in" {{public_check}}/> + <span><i class="material-icons left">public</i>Pubblici</span> + </label> + </div> + <div class="input-field col s4"> + <label> + <input name="filter_selfsign" type="checkbox" class="filled-in" {{selfsign_check}}/> + <span><i class="material-icons left">assignment_turned_in</i>No firma</span> + </label> + </div> + </div> + <div class="row"> + <div class="input-field col s3"> + <label> + <input name="filter_personal" type="checkbox" class="filled-in" {{personal_check}}/> + <span><i class="material-icons left">person</i>Personali</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_medic" type="checkbox" class="filled-in" {{medic_check}}/> + <span><i class="material-icons left">healing</i>Medici</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_custom" type="checkbox" class="filled-in" {{custom_check}}/> + <span><i class="material-icons left">add_circle_outline</i>Personalizzati</span> + </label> + </div> + <div class="input-field col s3"> + <label> + <input name="filter_message" type="checkbox" class="filled-in" {{message_check}}/> + <span><i class="material-icons left">message</i>Messaggi</span> + </label> + </div> + </div> + </div> + <div class="modal-footer"> + <a href="#!" onclick="send('filter')" class="modal-close waves-effect waves-green btn-flat">Applica</a> + </div> +</div> + <input type="hidden" name="action" id="action"> <ul class="collapsible"> {% for doctype in docs %} @@ -114,6 +184,11 @@ {%block script%} $(document).ready(function(){ $('.collapsible').collapsible(); + $('.tooltipped').tooltip(); + $('.modal').modal(); + {% if error %} + M.toast({html: '{{ error_text}}', classes: 'orange'}) + {% endif %} }); function send(id) { @@ -122,4 +197,17 @@ function send(id) { action.setAttribute('value', id); form.submit() } + +$('#select-all').click(function(event) { + if(this.checked) { + // Iterate each checkbox + $(':checkbox').each(function() { + this.checked = true; + }); + } else { + $(':checkbox').each(function() { + this.checked = false; + }); + } +}); {% endblock %}
\ No newline at end of file diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 199feb5..6b2f597 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -50,6 +50,9 @@ {% if not doctype.0.group_private %} <i class="material-icons">public</i> {% endif %} + {% if doctype.0.auto_sign %} + <i class="material-icons">assignment_turned_in</i> + {% endif %} {{doctype.0.name}} <span class="new badge red lighten-1" data-badge-caption="">{{doctype.1}}</span> </div> diff --git a/server/views.py b/server/views.py index 6c651f1..f29cb00 100644 --- a/server/views.py +++ b/server/views.py @@ -33,7 +33,7 @@ def index(request): 0] group = Group.objects.get(name=parent_group) public_types = DocumentType.objects.filter( - Q(group_private=False) | Q(group=group)) + Q(group_private=False) | Q(group=group) & Q(enabled=True)) docs = [] for doc in public_types: ref_docs = Document.objects.filter(document_type=doc) @@ -196,38 +196,96 @@ def ulist(request): def doctype(request): context = {} if request.user.is_staff: + error = False + error_text = "" + + public = True + selfsign = True + hidden = False + personal = True + medic = True + custom = True + message = True + public_check = 'checked="checked"' + selfsign_check = 'checked="checked"' + hidden_check = 'checked="checked"' + personal_check = 'checked="checked"' + medic_check = 'checked="checked"' + custom_check = 'checked="checked"' + message_check = 'checked="checked"' if request.method == "POST": selected = [] for i in request.POST.keys(): - if i == "csrfmiddlewaretoken": - continue - if i == "action": - continue - - selected.append(DocumentType.objects.get(id=i)) + if i.isdigit(): + selected.append(DocumentType.objects.get(id=i)) for i in selected: if request.POST["action"] == 'delete': try: i.delete() except ProtectedError: - print("nope") + error = True + error_text = "Non puoi eliminare un tipo a cui é collegato uno o piú documenti" elif request.POST["action"] == 'hide': - i.enabled = not i.enabled + i.enabled = False + i.save() + elif request.POST["action"] == 'show': + i.enabled = True i.save() + public = "filter_public" in request.POST + selfsign = "filter_selfsign" in request.POST + hidden = "filter_hidden" in request.POST + personal = "filter_personal" in request.POST + medic = "filter_medic" in request.POST + custom = "filter_custom" in request.POST + message = "filter_message" in request.POST + 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)) + if not public: + public_types = public_types.filter(group_private=True) + public_check = "" + if not selfsign: + public_types = public_types.filter(auto_sign=False) + selfsign_check = "" + if not hidden: + public_types = public_types.filter(enabled=True) + hidden_check = "" + if not personal: + public_types = public_types.filter(personal_data=False) + personal_check = "" + if not medic: + public_types = public_types.filter(medical_data=False) + medic_check = "" + if not custom: + public_types = public_types.filter(custom_data=False) + custom_check = "" + if not message: + public_types = public_types.filter(custom_message=False) + message_check = "" + out = [] for doc in public_types: 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} + context = { + 'docs': out, + 'public_check': public_check, + 'selfsign_check': selfsign_check, + 'hidden_check': hidden_check, + 'personal_check': personal_check, + 'medic_check': medic_check, + 'custom_check': custom_check, + 'message_check': message_check, + 'error': error, + 'error_text': error_text, + } return render(request, 'server/doc_type.html', context) else: return render(request, 'client/index.html', context) @@ -292,6 +350,8 @@ def doccreate(request): def doclist(request): context = {} if request.user.is_staff: + error = False + error_text = "" if request.method == "POST": selected = [] for i in request.POST.keys(): @@ -304,16 +364,24 @@ def doclist(request): for i in selected: if request.POST["action"] == 'delete': - try: - i.delete() - except ProtectedError: - print("nope") + i.delete() elif request.POST["action"] == 'approve': i.status = 'ok' i.save() elif request.POST["action"] == 'archive': - i.status = 'archive' - i.save() + if i.status == 'ok': + i.status = 'archive' + i.save() + else: + error = True + error_text = "Non puoi archiviare un documento non approvato" + elif request.POST["action"] == 'unarchive': + if i.status == 'archive': + i.status = 'ok' + i.save() + else: + error = True + error_text = "Non puoi dearchiviare un documento non archiviato" parent_group = request.user.groups.values_list('name', flat=True)[ 0] @@ -329,7 +397,11 @@ def doclist(request): medical = i.medical_data.__dict__.values() out.append([i, KeyVal.objects.filter(container=i), personal, medical]) - context = {"docs": out} + context = { + "docs": out, + 'error': error, + 'error_text': error_text, + } return render(request, 'server/doc_list.html', context) else: return render(request, 'client/index.html', context) diff --git a/templates/registration/base_custom.html b/templates/registration/base_custom.html index 56b9180..9843f5e 100644 --- a/templates/registration/base_custom.html +++ b/templates/registration/base_custom.html @@ -10,7 +10,7 @@ <body> {% block nav %} {% endblock %} - <main style="margin-left: 10px;margin-right: 10px;margin-top: 10px;"> + <main id="main" style="margin-left: 10px;margin-right: 10px;margin-top: 10px;"> {% block content %} {% endblock %} </main> |