diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2020-07-26 21:28:06 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2020-07-26 21:28:06 +0200 |
commit | e1deaaf4a239db742cea2d1e6c4f48a9656d8a0f (patch) | |
tree | c3bbe11e47616f702f4c56734430005a5fc04504 | |
parent | use webp to save images (diff) | |
download | scout-subs-e1deaaf4a239db742cea2d1e6c4f48a9656d8a0f.tar.gz scout-subs-e1deaaf4a239db742cea2d1e6c4f48a9656d8a0f.zip |
bug fixes and visual improvements
Diffstat (limited to '')
-rw-r--r-- | accounts/templates/accounts/index.html | 21 | ||||
-rw-r--r-- | accounts/views.py | 10 | ||||
-rw-r--r-- | client/templates/client/index.html | 34 | ||||
-rw-r--r-- | client/views.py | 15 | ||||
-rw-r--r-- | server/templates/server/doc_list.html | 8 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 31 | ||||
-rw-r--r-- | server/templates/server/index.html | 12 | ||||
-rw-r--r-- | server/templates/server/user_list.html | 31 | ||||
-rw-r--r-- | server/views.py | 21 |
9 files changed, 144 insertions, 39 deletions
diff --git a/accounts/templates/accounts/index.html b/accounts/templates/accounts/index.html index 9a8a79c..69d0717 100644 --- a/accounts/templates/accounts/index.html +++ b/accounts/templates/accounts/index.html @@ -75,7 +75,7 @@ <label for="birth_date">Data di nascita</label> </div> <div class="input-field col l4 s12"> - <select name="branca"> + <select name="branca" disabled> <option value="" disabled {{branca_default}}>Scegli</option> <option value="colonia" {{branca_castorini}}>Castorini</option> <option value="muta" {{branca_lupetti}}>Lupetti</option> @@ -278,7 +278,7 @@ <div class="file-field input-field"> <div class="btn teal"> <span><i class="material-icons left">file_upload</i>File</span> - <input type="file" name="vac_certificate"> + <input type="file" name="vac_certificate" id="vac_certificate"> </div> <div class="file-path-wrapper"> <input id="vac_file" value="{{vac_certificate}}" class="file-path" type="text" placeholder="Certificato di vacinazione"> @@ -298,7 +298,7 @@ <div class="file-field input-field"> <div class="btn teal"> <span><i class="material-icons left">file_upload</i>File</span> - <input type="file" name="health_care_certificate"> + <input type="file" name="health_care_certificate" id="health_care_certificate"> </div> <div class="file-path-wrapper"> <input id="health_care_file" value="{{health_care_certificate}}" class="file-path" type="text" placeholder="Tessera cassa malati"> @@ -377,6 +377,21 @@ $(document).ready(function() { {% if error %} M.toast({html: '{{ error_text}}', classes: 'orange'}) {% endif %} + + document.getElementById("vac_certificate").onchange = function() { + if(this.files[0].size > 1048576*10){ + M.toast({html: 'Il file è troppo grande. Grandezza massima 10MB', classes: 'orange'}); + this.value = ""; + } + }; + + document.getElementById("health_care_certificate").onchange = function() { + if(this.files[0].size > 1048576*10){ + M.toast({html: 'Il file è troppo grande. Grandezza massima 10MB', classes: 'orange'}); + this.value = ""; + } + }; + }); /*! diff --git a/accounts/views.py b/accounts/views.py index 562524e..cc402d2 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -86,11 +86,11 @@ def personal(request): medic.misc = request.POST["misc"] medic.save() - if "branca" in request.POST: - if request.POST["branca"] != "": - request.user.groups.clear() - request.user.groups.add( - Group.objects.get(name=request.POST["branca"])) + #if "branca" in request.POST: + # if request.POST["branca"] != "": + # request.user.groups.clear() + # request.user.groups.add( + # Group.objects.get(name=request.POST["branca"])) if "vac_certificate" in request.FILES: myfile = request.FILES['vac_certificate'] diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 2ddbfdc..b368630 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -38,9 +38,20 @@ </div> <div class="collapsible-body"><span> {% if doc.0.status == "wait" %} - <a class="waves-effect waves-light btn teal" onclick="send('f{{doc.0.id}}')"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a> - <a class="waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a> - <a class="waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a> + <div class="hide-on-med-and-down"> + <a class="waves-effect waves-light btn teal" onclick="send('f{{doc.0.id}}')"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a> + <a class="waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a> + <a class="waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a> + </div> + <div class="hide-on-large-only"> + <a class="s12 waves-effect waves-light btn teal" onclick="send('f{{doc.0.id}}')"><i class="material-icons left">file_download</i> Scarica documento per approvazione</a> + <br> + <br> + <a class="s12 waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a> + <br> + <br> + <a class="s12 waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a> + </div> <br> <br> {% elif doc.0.status == "autosign" %} @@ -56,9 +67,20 @@ <a onclick="send('a{{doc.0.id}}')" class="modal-close waves-effect waves-green btn-flat">Approva</a> </div> </div> - <a class="waves-effect waves-light btn teal modal-trigger" href="#modal{{doc.0.id}}"><i class="material-icons left">check</i>Approva documento</a> - <a class="waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i> Elimina documento</a> - <a class="waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i> Modifica documento</a> + <div class="hide-on-med-and-down"> + <a class="waves-effect waves-light btn teal modal-trigger" href="#modal{{doc.0.id}}"><i class="material-icons left">check</i>Approva documento</a> + <a class="waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i>Elimina documento</a> + <a class="waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i>Modifica documento</a> + </div> + <div class="hide-on-large-only"> + <a class="s12 waves-effect waves-light btn teal modal-trigger" href="#modal{{doc.0.id}}"><i class="material-icons left">check</i>Approva documento</a> + <br> + <br> + <a class="s12 waves-effect waves-light btn teal" onclick="send('d{{doc.0.id}}')"><i class="material-icons left">delete</i>Elimina documento</a> + <br> + <br> + <a class="s12 waves-effect waves-light btn teal" onclick="send('e{{doc.0.id}}')"><i class="material-icons left">edit</i>Modifica documento</a> + </div> <br> <br> {% endif %} diff --git a/client/views.py b/client/views.py index 6cc7a15..c9bb89b 100644 --- a/client/views.py +++ b/client/views.py @@ -52,8 +52,10 @@ def index(request): if document.status == "autosign": document.status = "ok" document.save() + return HttpResponseRedirect("/") elif request.POST["action"][0] == 'd': document.delete() + return HttpResponseRedirect("/") elif request.POST["action"][0] == 'e': document_type = document.document_type context = { @@ -151,13 +153,18 @@ def create(request): context['custom_message'] = document_type.custom_message context['custom_message_text'] = document_type.custom_message_text elif request.POST["action"] == "save": + document_type = DocumentType.objects.get( + id=request.POST["doctype"]) + + current_docs = Document.objects.filter(document_type=document_type) + if len(current_docs) > 0: + return + usercode = UserCode.objects.filter(user=request.user)[0] 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" @@ -202,6 +209,10 @@ def edit_wrapper(request, context): if request.method == "POST": if "action" not in request.POST.keys(): document = Document.objects.get(id=request.POST["doc"]) + + if document.user != request.user: + return + usercode = UserCode.objects.filter(user=document.user)[0] if document.document_type.personal_data: diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html index e5be168..fb201d5 100644 --- a/server/templates/server/doc_list.html +++ b/server/templates/server/doc_list.html @@ -124,7 +124,7 @@ <li> <div class="collapsible-header"> <label> - <input name={{doc.0.id}} type="checkbox" class="filled-in"/> + <input name={{doc.0.id}} type="checkbox" class="filled-in allselect"/> <span></span> </label> {% if doc.0.status == "wait" %} @@ -165,6 +165,8 @@ <i class="material-icons">send</i>{{doc.0.compilation_date}} </div> </li> + </ul> + <ul class="collapsible"> {% if doc.0.document_type.personal_data %} <li> <div class="collapsible-header"> @@ -517,11 +519,11 @@ function send(id) { $('#select-all').click(function(event) { if(this.checked) { // Iterate each checkbox - $(':checkbox').each(function() { + $('.allselect').each(function() { this.checked = true; }); } else { - $(':checkbox').each(function() { + $('.allselect').each(function() { this.checked = false; }); } diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html index e95cef1..82adf83 100644 --- a/server/templates/server/doc_type.html +++ b/server/templates/server/doc_type.html @@ -44,7 +44,6 @@ <div class="input-field"> <input autocomplete="off" id="search" type="search" onkeyup="filterResults()" required> <label class="label-icon" for="search"><i class="material-icons">search</i></label> - <i class="material-icons">close</i> </div> </form> </li> @@ -57,6 +56,7 @@ <ul id='dropdown1' class='dropdown-content'> <li><a Onclick="send('clear')"><i class="material-icons">clear</i>Pulisci</a></li> <li><a href="#modal1" data-target="modal1" class="modal-trigger"><i class="material-icons">filter_list</i>Filtri</a></li> + <li><a href="#modal2" data-target="modal2" class="modal-trigger"><i class="material-icons">search</i>Cerca</a></li> </ul> {% endblock %} @@ -118,19 +118,22 @@ </label> </div> </div> - <div class="row hide-on-large-only"> - <div class="col s12"> - <div class="input-field"> - <input autocomplete="off" id="searchs" type="text" onkeyup="filterResultsSmall()" required> - <label for="searchs"><i class="material-icons">search</i></label> - </div> - </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> +<div id="modal2" class="modal"> + <div class="modal-content"> + <div class="input-field"> + <input autocomplete="off" id="searchs" type="text" onkeyup="filterResultsSmall()" required> + <label for="searchs"><i class="material-icons">search</i></label> + </div> + </div> + <div class="modal-footer"> + <a href="#!" class="modal-close waves-effect waves-green btn-flat">Chiudi</a> + </div> +</div> <input type="hidden" name="action" id="action"> <ul class="collapsible"> @@ -138,7 +141,7 @@ <li> <div class="collapsible-header list"> <label> - <input name={{doctype.0.id}} type="checkbox" class="filled-in"/> + <input name={{doctype.0.id}} type="checkbox" class="filled-in allselect"/> <span></span> </label> {% if not doctype.0.enabled %} @@ -179,6 +182,9 @@ </div> </li> {% endif %} + </ul> + {% if doctype.0.custom_data or doctype.0.custom_message %} + <ul class="collapsible"> {% if doctype.0.custom_data %} <li> <div class="collapsible-header"> @@ -208,6 +214,7 @@ </li> {% endif %} </ul> + {% endif %} </span></div> </li> {% endfor %} @@ -241,11 +248,11 @@ function send(id) { $('#select-all').click(function(event) { if(this.checked) { // Iterate each checkbox - $(':checkbox').each(function() { + $('.allselect').each(function() { this.checked = true; }); } else { - $(':checkbox').each(function() { + $('.allselect').each(function() { this.checked = false; }); } diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 2676c3a..a049f4f 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -60,9 +60,21 @@ </ul> </div> <div class="card-action"> + <div class="hide-on-small-only"> <a class="waves-effect waves-light btn red lighten-1" href="{% url 'doctype' %}">Lista tipo doc</a> <a class="waves-effect waves-light btn red lighten-1" href="{% url 'doclist' %}">Lista documenti</a> <a class="waves-effect waves-light btn red lighten-1" href="{% url 'docapprove' %}">Approva documento</a> + </div> + + <div class="hide-on-med-and-up"> + <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'doctype' %}">Lista tipo doc</a> + <br> + <br> + <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'doclist' %}">Lista documenti</a> + <br> + <br> + <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'docapprove' %}">Approva documento</a> + </div> </div> </div> </div> diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html index 8ee2008..1010bd4 100644 --- a/server/templates/server/user_list.html +++ b/server/templates/server/user_list.html @@ -30,7 +30,6 @@ <div class="input-field"> <input autocomplete="off" id="search" type="search" onkeyup="filterResults()" required> <label class="label-icon" for="search"><i class="material-icons">search</i></label> - <i class="material-icons">close</i> </div> </form> </div> @@ -51,6 +50,30 @@ {{user.0.first_name}} {{user.0.last_name}} </div> <div class="collapsible-body"><span> + {% if not user.0.is_staff %} + <div id="modal{{user.0.id}}" class="modal"> + <div class="modal-content"> + <h4>Attenzione</h4> + <p> + Sei sicuro di volerlere deapprovare l'utente {{user.0.first_name}} {{user.0.last_name}}?<br> + Una volta deapprovato l'utente non potrà più creare documenti e per essere riapprovato dovrà essere usato il codice di approvazione. + </p> + </div> + <div class="modal-footer"> + <a style="color:red" href="#!" class="modal-close waves-effect waves-green btn-flat">Annulla</a> + <a onclick="send('d{{user.0.id}}')" class="modal-close waves-effect waves-green btn-flat">Deapprova</a> + </div> + </div> + <a class="waves-effect waves-light btn red lighten-1 modal-trigger" href="#modal{{user.0.id}}"><i class="material-icons left">remove_circle_outline</i>Deapprova utente</a> + <br><br> + {% endif %} + <ul class="collapsible"> + <li> + <div class="collapsible-header"> + <i class="material-icons">confirmation_number</i>U{{user.1.code}} + </div> + </li> + </ul> <ul class="collapsible"> <li> <div class="collapsible-header"> @@ -292,9 +315,9 @@ {% endblock %} {% block script %} -document.addEventListener('DOMContentLoaded', function() { - var elems = document.querySelectorAll('.collapsible'); - var instances = M.Collapsible.init(elems, {}); +$(document).ready(function(){ + $('.modal').modal(); + $('.collapsible').collapsible(); }); function send(id) { diff --git a/server/views.py b/server/views.py index e4fea63..e4b70ff 100644 --- a/server/views.py +++ b/server/views.py @@ -7,6 +7,7 @@ from django.db.models.deletion import ProtectedError from django.template.loader import get_template from django.conf import settings from django.contrib.admin.views.decorators import staff_member_required +from django.contrib.contenttypes.models import ContentType import dateparser from datetime import datetime @@ -80,18 +81,16 @@ def uapprove(request): data[i] = data[i] + " - Invalido" else: user = UserCode.objects.filter(code=data[i][1:])[0].user + user.user_permissions.add(permission) if len(user.groups.values_list('name', flat=True)) == 0: user.groups.add(group) - user.user_permissions.add(permission) data[i] = data[i] + " - Ok" else: if user.groups.values_list('name', flat=True)[0] == parent_group: - user.user_permissions.add(permission) 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 = { @@ -163,9 +162,19 @@ def ulist(request): result.seek(0) return FileResponse(result, as_attachment=True, filename=document.user.username+"_"+document.document_type.name+".pdf") + elif request.POST["action"][0] == 'd': + user = User.objects.get(id=request.POST["action"][1:]) + if user.groups.all()[0] == group: + content_type = ContentType.objects.get_for_model(Document) + permission = Permission.objects.get(content_type=content_type, codename="approved") + user.user_permissions.remove(permission) + users = User.objects.filter(groups__name=parent_group).order_by("first_name") out = [] for user in users: + if not user.has_perm("client.approved") and not user.is_staff: + continue + usercode = UserCode.objects.filter(user=user)[0] documents = Document.objects.filter(Q(user=user) & ~Q(status='archive') & Q(group__name=parent_group)) vac_file = "" @@ -345,8 +354,12 @@ def doccreate(request): name = request.POST["name"] custom_group = request.POST["custom_group"] + if len(DocumentType.objects.filter(name=name)) > 0: + context["error"] = "true" + context["error_text"] = "Questo nome esiste già. Prego usarne un altro." + return render(request, 'server/doc_create.html', context) + if custom_group != "": - print("here") if custom_group not in request.user.groups.values_list('name', flat=True): context["error"] = "true" context["error_text"] = "Non puoi creare un tipo assegnato ad un gruppo di cui non fai parte" |