From e1deaaf4a239db742cea2d1e6c4f48a9656d8a0f Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 26 Jul 2020 21:28:06 +0200 Subject: bug fixes and visual improvements --- accounts/templates/accounts/index.html | 21 ++++++++++++++++++--- accounts/views.py | 10 +++++----- client/templates/client/index.html | 34 ++++++++++++++++++++++++++++------ client/views.py | 15 +++++++++++++-- server/templates/server/doc_list.html | 8 +++++--- server/templates/server/doc_type.html | 31 +++++++++++++++++++------------ server/templates/server/index.html | 12 ++++++++++++ server/templates/server/user_list.html | 31 +++++++++++++++++++++++++++---- 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 @@
- @@ -278,7 +278,7 @@
file_uploadFile - +
@@ -298,7 +298,7 @@
file_uploadFile - +
@@ -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 @@
- checkApprova documento - delete Elimina documento - edit Modifica documento + +

{% 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 @@
  • {% if doc.0.status == "wait" %} @@ -165,6 +165,8 @@ send{{doc.0.compilation_date}}
  • + +
      {% if doc.0.document_type.personal_data %}
    • @@ -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 @@
      - close
    • @@ -57,6 +56,7 @@ {% endblock %} @@ -118,19 +118,22 @@
    -
    -
    -
    - - -
    -
    -
    + + {% if doctype.0.custom_data or doctype.0.custom_message %} + + {% endif %} {% 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 @@
    + + +
    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 @@
    - close
    @@ -51,6 +50,30 @@ {{user.0.first_name}} {{user.0.last_name}}
    + {% if not user.0.is_staff %} + + remove_circle_outlineDeapprova utente +

    + {% endif %} +
      +
    • +
      + confirmation_numberU{{user.1.code}} +
      +
    • +
    • @@ -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" -- cgit v1.2.1