aboutsummaryrefslogtreecommitdiffstats
path: root/server/views.py
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 /server/views.py
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/views.py46
1 files changed, 42 insertions, 4 deletions
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