From 0a19d5ff7a7b09dbc81f5e4c8ec4fee334505cda Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 30 Aug 2020 22:38:42 +0200 Subject: custom query and group capi --- server/templates/server/data_request.html | 52 +++++++++++++++++++++++++++++++ server/templates/server/index.html | 21 ++++++++++--- server/templates/server/user_list.html | 15 +++++++-- server/urls.py | 3 +- server/views.py | 46 ++++++++++++++++++++++++--- 5 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 server/templates/server/data_request.html (limited to 'server') diff --git a/server/templates/server/data_request.html b/server/templates/server/data_request.html new file mode 100644 index 0000000..8b0ed7c --- /dev/null +++ b/server/templates/server/data_request.html @@ -0,0 +1,52 @@ +{% extends 'registration/base.html' %} + +{% block title %}Admin - Richiesta dati{% endblock %} + +{% block nav %} + Home + Admin + Richiesta dati +{% endblock %} + +{% block content %} + +
+
+
+
+ {% csrf_token %} +
+
+ + +
+ +
+ +
+
+
+
+{% endblock %} + +{% block script %} +document.addEventListener('DOMContentLoaded', function() { + var elems = document.querySelectorAll('select'); + var options = {}; + var instances = M.FormSelect.init(elems, options); +}); + +function copy() { + var copyText = document.getElementById("data"); + copyText.select(); + copyText.setSelectionRange(0, 99999); /*For mobile devices*/ + document.execCommand("copy"); +} +{% endblock%} \ No newline at end of file diff --git a/server/templates/server/index.html b/server/templates/server/index.html index 2e299d1..83be995 100644 --- a/server/templates/server/index.html +++ b/server/templates/server/index.html @@ -10,7 +10,7 @@ {% block content %}
{% if user.is_staff %} -
+

@@ -31,14 +31,27 @@

{% endif %} {% if user.is_staff %} -
+
{% else %}
{% endif %} @@ -62,14 +75,14 @@
-
+ -
+
Lista tipo doc

diff --git a/server/templates/server/user_list.html b/server/templates/server/user_list.html index 721f284..54b7b77 100644 --- a/server/templates/server/user_list.html +++ b/server/templates/server/user_list.html @@ -45,7 +45,9 @@
  • {% if user.0.is_staff %} - grade + star + {% elif user.6 %} + star_border {% endif %} {{user.0.first_name}} {{user.0.last_name}}
    @@ -64,7 +66,16 @@ Deapprova
  • - remove_circle_outlineDeapprova utente + +

    {% endif %}
      diff --git a/server/urls.py b/server/urls.py index b744730..2095450 100644 --- a/server/urls.py +++ b/server/urls.py @@ -1,4 +1,4 @@ -from django.urls import path, re_path, include +from django.urls import path from . import views @@ -14,4 +14,5 @@ urlpatterns = [ path('docupload', views.upload_doc, name='docupload'), path('docpreview', views.docpreview, name='docpreview'), path('progress', views.get_progress, name='progress'), + path('request', views.data_request, name='request'), ] diff --git a/server/views.py b/server/views.py index 7d9afc2..27618d9 100644 --- a/server/views.py +++ b/server/views.py @@ -10,6 +10,7 @@ from django.contrib.admin.views.decorators import staff_member_required from django.contrib.auth.decorators import user_passes_test from django.contrib.contenttypes.models import ContentType from django.contrib.sessions.backends.db import SessionStore +from django import template import dateparser from datetime import datetime @@ -33,7 +34,6 @@ def isStaff(user): return True return False - @user_passes_test(isStaff) def index(request): context = {} @@ -239,10 +239,25 @@ def ulist(request): content_type=content_type, 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") # list users with their documents - users = User.objects.filter( - groups__name=parent_group).order_by("first_name") + users = list(User.objects.filter( + groups__name=parent_group).filter(groups__name="capi").order_by("first_name")) + users += list(User.objects.filter( + groups__name=parent_group).exclude(groups__name="capi").order_by("first_name")) out = [] for user in users: # list only approved users @@ -267,7 +282,7 @@ def ulist(request): with open(usercode.medic.health_care_certificate.name, 'rb') as image_file: health_file = base64.b64encode(image_file.read()).decode() out.append([user, usercode, parent_group, - documents, vac_file, health_file]) + documents, vac_file, health_file, "capi" in user.groups.values_list('name',flat = True)]) context = {'users': out} return render(request, 'server/user_list.html', context) @@ -869,6 +884,7 @@ def zip_documents(docs, session_key): session['status'] = True session.save() + @user_passes_test(isStaff) def upload_doc(request): # setup group based on staff primary or not @@ -991,3 +1007,25 @@ def docpreview(request): 'health': health_file, 'sign_doc_file': sign_doc_file} return render(request, 'server/download_doc.html', context) + + +@user_passes_test(isStaff) +def data_request(request): + context = {} + parent_group = request.user.groups.values_list('name', flat=True)[0] + if request.method == "POST": + if request.POST["request"] == "email_all": + users = User.objects.filter(groups__name=parent_group) + data = "" + for user in users: + data += user.email + ", " + data = data[:-2] + context["data"] = data + elif request.POST["request"] == "email_non_staff": + users = User.objects.filter(groups__name=parent_group).exclude(groups__name="capi") + data = "" + for user in users: + data += user.email + ", " + data = data[:-2] + context["data"] = data + return render(request, 'server/data_request.html', context) \ No newline at end of file -- cgit v1.2.1