aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-08-30 22:38:42 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-08-30 22:38:42 +0200
commit0a19d5ff7a7b09dbc81f5e4c8ec4fee334505cda (patch)
tree4e099998348b73f634bbfe052b134f96c15d4c37
parentuse session varables to store progress bar data (diff)
downloadscout-subs-0a19d5ff7a7b09dbc81f5e4c8ec4fee334505cda.tar.gz
scout-subs-0a19d5ff7a7b09dbc81f5e4c8ec4fee334505cda.zip
custom query and group capi
Diffstat (limited to '')
-rw-r--r--server/templates/server/data_request.html52
-rw-r--r--server/templates/server/index.html21
-rw-r--r--server/templates/server/user_list.html15
-rw-r--r--server/urls.py3
-rw-r--r--server/views.py46
5 files changed, 126 insertions, 11 deletions
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 %}
+ <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 'request'%}" class="breadcrumb hide-on-med-and-down">Richiesta dati</a>
+{% endblock %}
+
+{% block content %}
+
+<div class="row">
+ <div class="col l4 offset-l4 m8 offset-m2 s12">
+ <div class="card">
+ <form id="form" action="{% url 'request'%}" method="post">
+ {% csrf_token %}
+ <div class="card-content">
+ <div class="input-field col s12">
+ <select name="request">
+ <option value="" disabled selected>Scegli</option>
+ <option value="email_all">Email (tutti gli utenti)</option>
+ <option value="email_non_staff">Email (solo non capi)</option>
+ </select>
+ <label>Richiesta dati</label>
+ </div>
+ <textarea id="data" class="materialize-textarea">{{data}}</textarea>
+ </div>
+ <div class="card-action">
+ <a class="waves-effect waves-light btn red lighten-1" href="#" onclick="document.getElementById('form').submit()">Invia</a>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="copy()">Copia risultato</a>
+ </div>
+ </form>
+ </div>
+ </div>
+</div>
+{% 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 %}
<div class="row">
{% if user.is_staff %}
- <div class="col l4 s12">
+ <div class="col l5 s12">
<div class="card large">
<div class="card-content">
<p>
@@ -31,14 +31,27 @@
</p>
</div>
<div class="card-action">
+ <div class="hide-on-med-and-down">
<a class="waves-effect waves-light btn red lighten-1" href="{% url 'ulist' %}">Lista utenti</a>
<a class="waves-effect waves-light btn red lighten-1" href="{% url 'uapprove' %}">Approva utente</a>
+ <a class="waves-effect waves-light btn red lighten-1" href="{% url 'request' %}">Richiedi dati</a>
+ </div>
+
+ <div class="hide-on-large-only">
+ <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'ulist' %}">Lista utenti</a>
+ <br>
+ <br>
+ <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'uapprove' %}">Approva utente</a>
+ <br>
+ <br>
+ <a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'request' %}">Richiedi dati</a>
+ </div>
</div>
</div>
</div>
{% endif %}
{% if user.is_staff %}
- <div class="col l8 s12">
+ <div class="col l7 s12">
{% else %}
<div class="col s12">
{% endif %}
@@ -62,14 +75,14 @@
</ul>
</div>
<div class="card-action">
- <div class="hide-on-small-only">
+ <div class="hide-on-med-and-down">
<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>
<a class="waves-effect waves-light btn red lighten-1" href="{% url 'docupload' %}">Carica firma</a>
</div>
- <div class="hide-on-med-and-up">
+ <div class="hide-on-large-only">
<a class="col s12 waves-effect waves-light btn red lighten-1" href="{% url 'doctype' %}">Lista tipo doc</a>
<br>
<br>
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 @@
<li>
<div class="collapsible-header list">
{% if user.0.is_staff %}
- <i class="material-icons">grade</i>
+ <i class="material-icons">star</i>
+ {% elif user.6 %}
+ <i class="material-icons">star_border</i>
{% endif %}
{{user.0.first_name}} {{user.0.last_name}}
</div>
@@ -64,7 +66,16 @@
<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>
+ <div class="hide-on-med-and-down">
+ <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>
+ <a class="waves-effect waves-light btn red lighten-1" onclick="send('c{{user.0.id}}')"><i class="material-icons left">star_border</i>Capo/non</a>
+ </div>
+ <div style="margin-bottom: 0px;" class="hide-on-large-only row">
+ <a class="col s12 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>
+ <a class="col s12 waves-effect waves-light btn red lighten-1" onclick="send('c{{user.0.id}}')"><i class="material-icons left">star_border</i>Capo/non</a>
+ </div>
<br><br>
{% endif %}
<ul class="collection">
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