From 7577628b360c78742d4d9d1b709f3749ca4fa022 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Thu, 27 Jul 2023 11:26:43 +0200 Subject: user list and branca tansfer with new uc --- server/templates/server/index.html | 4 +- server/templates/server/user_list.html | 34 ++------------- server/templates/server/user_list_table.html | 16 +++---- server/views.py | 63 +++++++--------------------- version.txt | 2 +- 5 files changed, 30 insertions(+), 89 deletions(-) diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 2db42e4..487ef71 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -48,7 +48,7 @@
Utenti Utenti (Tabella BETA) - Approva utente + Trasferta utente Richiedi dati
@@ -56,7 +56,7 @@ Utenti

- Approva utente + Trasferta utente

Richiedi dati diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html index dffb8b2..22788e9 100644 --- a/server/templates/server/user_list.html +++ b/server/templates/server/user_list.html @@ -31,35 +31,9 @@ {% elif "capi" in user.user|user_groups %} star_border {% endif %} - {{user.user.first_name}} {{user.user.last_name}} + {{user.first_name}} {{user.last_name}}
- {% if not user.user.is_staff %} - - - -

- {% endif %}
  • confirmation_numberU{{user.code}} @@ -73,11 +47,11 @@
    - +
    - +
    @@ -85,7 +59,7 @@
    - +
    diff --git a/server/templates/server/user_list_table.html b/server/templates/server/user_list_table.html index 89903a5..624fced 100644 --- a/server/templates/server/user_list_table.html +++ b/server/templates/server/user_list_table.html @@ -39,12 +39,12 @@ {% for user in users %} { capo: {% if "capi" in user.user|user_groups %}true{% else %}false{% endif %}, - username: "{{user.user.username}}", - name: "{{user.user.first_name}}", - last_name: "{{user.user.last_name}}", + ucode: "U{{user.code}}", email: "{{user.user.email}}", + name: "{{user.first_name}}", + last_name: "{{user.last_name}}", birth_date: "{{user.born_date}}", - branca: "{{ user.user|user_primary_group }}", + branca: "{{ user.branca }}", parent_name: "{{user.parent_name}}", avs_number: "{{user.avs_number}}", via: "{{user.via}}", @@ -82,11 +82,11 @@ var col_categories = [ {field: "base", name: "Informazioni base", cols: [ - {title: "Capo", field: "capo", formatter:"tickCross", frozen: true}, - {title: "Username", field: "username", frozen: true}, - {title: "Nome", field: "name"}, - {title: "Cognome", field: "last_name"}, + {title: "Nome", field: "name", frozen: true}, + {title: "Cognome", field: "last_name", frozen: true}, + {title: "Capo", field: "capo", formatter:"tickCross"}, {title: "Email", field: "email"}, + {title: "Codice", field: "ucode"}, {title: "Data di nascita", field: "birth_date"}, {title: "Branca", field: "branca"}, ] diff --git a/server/views.py b/server/views.py index 4bcdf53..edb9d0c 100644 --- a/server/views.py +++ b/server/views.py @@ -144,10 +144,6 @@ def uapprove(request): if request.method == "POST": # get group name and obj group = getGroups(request)[0] - parent_group = group.name - - # get permission object - permission = Permission.objects.get(codename='approved') # parse text to array data = request.POST["codes"] @@ -163,21 +159,18 @@ def uapprove(request): elif UserCode.objects.filter(code=data[i][1:]).count() == 0: data[i] = data[i] + " - Invalido" else: - user = UserCode.objects.filter(code=data[i][1:])[0].user - user.user_permissions.add(permission) + usercode = UserCode.objects.filter(code=data[i][1:])[0] # if user not in any group add to the same group as staff - if user.groups.values_list('name', flat=True).count() == 0: - user.groups.add(group) + if usercode.branca == None: + usercode.branca = group + usercode.save() data[i] = data[i] + " - Ok" + elif usercode.branca == group: + data[i] = data[i] + " - Già " + group.name else: - if user.groups.values_list('name', flat=True)[0] == parent_group: - # if user already in group do nothing - data[i] = data[i] + " - Già approvato" - else: - # if user in another group notify staff of group change - user.groups.remove(Group.objects.get(name=user.groups.values_list('name', flat=True)[0])) - user.groups.add(group) - data[i] = data[i] + " - Ok, cambio branca" + usercode.branca = group + usercode.save() + data[i] = data[i] + " - Ok, cambio branca" context = { 'messages': data, @@ -379,14 +372,14 @@ def approve_direct(request): def ulist(request): context = {} # group name and obj - group = getGroups(request)[0] + groups = getGroups(request) if request.method == "POST": # request to download document if request.POST["action"][0] == 'f': document = Document.objects.get(id=request.POST["action"][1:]) # check if user has permission to view document - if document.group == group: + if document.group == groups[0]: vac_file = "" health_file = "" sign_doc_file = "" @@ -419,34 +412,10 @@ def ulist(request): pdf = pdfkit.from_string(html, False) result = BytesIO(pdf) result.seek(0) - return FileResponse(result, filename=document.user.username+"_"+document.document_type.name+".pdf") - - # deapprove user - elif request.POST["action"][0] == 'd': - user = User.objects.get(id=request.POST["action"][1:]) - # check if user has permission to deapprove user - if user.groups.all()[0] == group: - permission = Permission.objects.get(codename="approved") - user.user_permissions.remove(permission) - return HttpResponseRedirect("ulist") - # make user "capo" - elif request.POST["action"][0] == 'c': - user = User.objects.get(id=request.POST["action"][1:]) - capi = Group.objects.get(name="capi") - # check if user has permission to modify - if user.groups.all()[0] == group: - if "capi" in user.groups.values_list('name', flat=True): - # remove group - user.groups.remove(capi) - else: - # add group - user.groups.add(capi) - return HttpResponseRedirect("ulist") + return FileResponse(result, filename=document.usercode.first_name+"_"+document.usercode.last_name+"_"+document.document_type.name+".pdf") # list users with their documents - permission = Permission.objects.get(codename="approved") - - usercodes = UserCode.objects.filter(Q(user__user_permissions=permission) | Q(user__is_staff=True)).filter(user__groups__name__contains=group.name).select_related("user", "medic").order_by("user__last_name") + usercodes = UserCode.objects.filter(branca__in=groups).select_related("user", "medic").order_by("last_name") vac_file = ["/server/media/", "/vac_certificate/usercode"] health_file = ["/server/media/", "/health_care_certificate/usercode"] @@ -462,12 +431,10 @@ def ulist(request): def ulist_table(request): context = {} # group name and obj - group = getGroups(request)[0] + groups = getGroups(request) # list users with their documents - permission = Permission.objects.get(codename="approved") - - usercodes = UserCode.objects.filter(Q(user__user_permissions=permission) | Q(user__is_staff=True)).filter(user__groups__name__contains=group.name).select_related("user", "medic").order_by("user__last_name") + usercodes = UserCode.objects.filter(branca__in=groups).select_related("user", "medic").order_by("user__last_name") vac_file = ["/server/media/", "/vac_certificate/usercode"] health_file = ["/server/media/", "/health_care_certificate/usercode"] diff --git a/version.txt b/version.txt index c157b42..b110dc6 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.6 -rev=32 +rev=33 -- cgit v1.2.1