aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2021-09-23 10:34:23 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2021-09-23 10:34:59 +0200
commit5d461a177ad6b949b462f2f836d7f573060622a9 (patch)
tree2e4c33aa95e731e2c8d57c0c225fe513650a8056 /server
parentremove last loops for admin interface (diff)
downloadscout-subs-5d461a177ad6b949b462f2f836d7f573060622a9.tar.gz
scout-subs-5d461a177ad6b949b462f2f836d7f573060622a9.zip
use .count() instead of len(), add debug_toolbar0.4
Diffstat (limited to '')
-rw-r--r--server/templates/server/doc_type.html55
-rw-r--r--server/templates/server/index.html11
-rw-r--r--server/views.py46
3 files changed, 45 insertions, 67 deletions
diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html
index 047a15a..8b2131d 100644
--- a/server/templates/server/doc_type.html
+++ b/server/templates/server/doc_type.html
@@ -42,6 +42,7 @@
{% endblock %}
{% block content %}
+{% load app_filter %}
<form id="selection" action="{% url 'doctype' %}" method="post">
{% csrf_token %}
<div id="modal1" class="modal">
@@ -122,73 +123,73 @@
<li>
<div class="collapsible-header list">
<label>
- <input name={{doctype.0.id}} type="checkbox" class="filled-in allselect"/>
+ <input name={{doctype.id}} type="checkbox" class="filled-in allselect"/>
<span></span>
</label>
- {% if not doctype.0.enabled %}
+ {% if not doctype.enabled %}
<i class="material-icons">visibility_off</i>
{% endif %}
- {% if not doctype.0.group_private %}
+ {% if not doctype.group_private %}
<i class="material-icons">public</i>
{% endif %}
- {% if doctype.0.custom_group %}
+ {% if doctype.custom_group %}
<i class="material-icons">group_work</i>
{% endif %}
- {% if doctype.0.auto_sign %}
+ {% if doctype.auto_sign %}
<i class="material-icons">assignment_turned_in</i>
{% endif %}
- {% if doctype.0.staff_only %}
+ {% if doctype.staff_only %}
<i class="material-icons">lock</i>
{% endif %}
- {{doctype.0.name}}
- <span class="new badge {{color}}" data-badge-caption="">{{doctype.2}}</span>
+ {{doctype.name}}
+ <span class="new badge {{color}}" data-badge-caption="">{{doctype|doc_count}}</span>
</div>
<div class="collapsible-body"><span>
<div class="hide-on-med-and-down">
- <a class="waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a>
- <a class="waves-effect waves-light btn {{color}}" onclick="send('p{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a>
- {% if doctype.0.medical_data %}
- <a class="waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a>
+ <a class="waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a>
+ <a class="waves-effect waves-light btn {{color}}" onclick="send('p{{doctype.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a>
+ {% if doctype.medical_data %}
+ <a class="waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a>
{% endif %}
</div>
<div style="margin-bottom: 0px;" class="hide-on-large-only row">
- <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.0.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a>
+ <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('e{{doctype.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a>
<br>
<br>
- <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('d{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a>
- {% if doctype.0.medical_data %}
+ <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('d{{doctype.id}}')"><i class="material-icons left">file_download</i> Scarica CSV</a>
+ {% if doctype.medical_data %}
<br>
<br>
- <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.0.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a>
+ <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.id}}')"><i class="material-icons left">file_download</i> Scarica CSV (con dati medici)</a>
{% endif %}
</div>
<br>
<br>
<ul class="collection">
- {% if not doctype.0.group_private %}
+ {% if not doctype.group_private %}
<li class="collection-item">
- <i class="material-icons left">group_work</i>{{doctype.0.group.name}}
+ <i class="material-icons left">group_work</i>{{doctype.group.name}}
</li>
{% endif %}
- {% if doctype.0.personal_data %}
+ {% if doctype.personal_data %}
<li class="collection-item">
<i class="material-icons left">person</i>Dati personali
</li>
{% endif %}
- {% if doctype.0.medical_data %}
+ {% if doctype.medical_data %}
<li class="collection-item">
<i class="material-icons left">healing</i>Dati medici
</li>
{% endif %}
- {% if doctype.0.max_instances != 0 %}
+ {% if doctype.max_instances != 0 %}
<li class="collection-item">
- <i class="material-icons left">control_point_duplicate</i>Numero massimo di partecipanti: {{doctype.0.max_instances}}
+ <i class="material-icons left">control_point_duplicate</i>Numero massimo di partecipanti: {{doctype.max_instances}}
</li>
{% endif %}
</ul>
- {% if doctype.0.custom_data or doctype.0.custom_message %}
+ {% if doctype.custom_data or doctype.custom_message %}
<ul class="collapsible">
- {% if doctype.0.custom_data %}
+ {% if doctype.custom_data %}
<li>
<div class="collapsible-header">
<i class="material-icons">add_circle_outline</i>Dati aggiuntivi
@@ -196,7 +197,7 @@
<div class="collapsible-body"><span>
<table class="striped">
<tbody>
- {% for key in doctype.1 %}
+ {% for key in doctype|doc_key_type %}
<tr>
<td>{{key.key}}</td>
</tr>
@@ -206,13 +207,13 @@
</span></div>
</li>
{% endif %}
- {% if doctype.0.custom_message %}
+ {% if doctype.custom_message %}
<li>
<div class="collapsible-header">
<i class="material-icons">message</i>Messaggio aggiuntivo
</div>
<div class="collapsible-body"><span>
- {{doctype.0.custom_message_text}}
+ {{doctype.custom_message_text}}
</span></div>
</li>
{% endif %}
diff --git a/server/templates/server/index.html b/server/templates/server/index.html
index af95153..8c60b48 100644
--- a/server/templates/server/index.html
+++ b/server/templates/server/index.html
@@ -7,6 +7,7 @@
{% endblock %}
{% block content %}
+{% load app_filter %}
<div class="row">
<div class="col l5 s12">
<div class="card large">
@@ -69,17 +70,17 @@
<ul class="collection">
{% for doctype in docs %}
<li class="collection-item">
- {% if not doctype.0.enabled %}
+ {% if not doctype.enabled %}
<i class="material-icons left">visibility_off</i>
{% endif %}
- {% if not doctype.0.group_private %}
+ {% if not doctype.group_private %}
<i class="material-icons left">public</i>
{% endif %}
- {% if doctype.0.auto_sign %}
+ {% if doctype.auto_sign %}
<i class="material-icons left">assignment_turned_in</i>
{% endif %}
- {{doctype.0.name}}
- <span class="new badge {{color}}" data-badge-caption="">{{doctype.1}}</span>
+ {{doctype.name}}
+ <span class="new badge {{color}}" data-badge-caption="">{{doctype|doc_count}}</span>
{% endfor %}
</ul>
</div>
diff --git a/server/views.py b/server/views.py
index a15d8bc..7d045bb 100644
--- a/server/views.py
+++ b/server/views.py
@@ -53,12 +53,12 @@ def index(request):
if request.user.is_staff:
groups = request.user.groups.all()
- public_types = DocumentType.objects.filter(
+ doc_types = DocumentType.objects.filter(
Q(group_private=False) | Q(group=groups[0]) & Q(enabled=True)).order_by("-id")
else:
groups = request.user.groups.all()[1:]
- public_types = DocumentType.objects.filter(
+ doc_types = DocumentType.objects.filter(
Q(group_private=False) & Q(enabled=True)).order_by("-id")
# check for settings
@@ -101,19 +101,8 @@ def index(request):
return HttpResponseRedirect("/server")
- # count documents of that type to show statistics
- docs = []
- for doc in public_types:
- doc_count = str(len(Document.objects.filter(document_type=doc)))
- ref_docs_archived = len(Document.objects.filter(document_type=doc, status="archive"))
- if ref_docs_archived > 0:
- doc_count += "-" + str(ref_docs_archived)
- if doc.max_instances != 0:
- doc_count += "/" + str(doc.max_instances)
- docs.append([doc, doc_count])
-
context = {
- 'docs': docs,
+ 'docs': doc_types,
'groups': group_check,
'doc_view_check': doc_view_check,
}
@@ -146,13 +135,13 @@ def uapprove(request):
data[i] = data[i] + " - Formato errato"
elif int(data[i][1:]) < 100000 or int(data[i][1:]) > 999999:
data[i] = data[i] + " - Formato errato"
- elif len(UserCode.objects.filter(code=data[i][1:])) == 0:
+ 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)
# if user not in any group add to the same group as staff
- if len(user.groups.values_list('name', flat=True)) == 0:
+ if user.groups.values_list('name', flat=True).count() == 0:
user.groups.add(group)
data[i] = data[i] + " - Ok"
else:
@@ -195,7 +184,7 @@ def docapprove(request):
data[i] = data[i] + " - Formato errato"
elif int(data[i]) < 100000 or int(data[i]) > 999999:
data[i] = data[i] + " - Formato errato"
- elif len(Document.objects.filter(code=data[i])) == 0:
+ elif Document.objects.filter(code=data[i]).count() == 0:
data[i] = data[i] + " - Invalido"
elif Document.objects.filter(code=data[i])[0].group.name not in groups:
# check if user has permission to approve document
@@ -569,21 +558,8 @@ def doctype(request):
public_types = public_types.filter(custom_group=False)
group_check = ""
- # get custom keys from types
- out = []
- for doc in public_types:
- custom_keys = Keys.objects.filter(container=doc)
- doc_count = str(len(Document.objects.filter(document_type=doc)))
- ref_docs_archived = len(Document.objects.filter(document_type=doc, status="archive"))
- if ref_docs_archived > 0:
- doc_count += "-" + str(ref_docs_archived)
- if doc.max_instances != 0:
- doc_count += "/" + str(doc.max_instances)
-
- out.append([doc, custom_keys, doc_count])
-
context = {
- 'docs': out,
+ 'docs': public_types,
'public_check': public_check,
'selfsign_check': selfsign_check,
'hidden_check': hidden_check,
@@ -668,7 +644,7 @@ def doccreate(request):
return render(request, 'server/doc_create.html', context)
# if already existing name throw error
- if len(DocumentType.objects.filter(name=name)) > 0:
+ if DocumentType.objects.filter(name=name).count() > 0:
context["error"] = "true"
context["error_text"] = "Questo nome esiste giĆ . Prego usarne un altro."
return render(request, 'server/doc_create.html', context)
@@ -1379,7 +1355,7 @@ def upload_doc(request):
elif int(data) < 100000 or int(data) > 999999:
error_text = "Formato codice errato"
error = True
- elif len(Document.objects.filter(code=data)) == 0:
+ elif Document.objects.filter(code=data).count() == 0:
error_text = "Codice invalido"
error = True
elif Document.objects.filter(code=data)[0].group.name not in groups:
@@ -1442,7 +1418,7 @@ def docpreview(request):
# check if code valid and user has permission
if not code.isdigit():
return render(request, 'server/download_doc.html', context)
- if len(Document.objects.filter(code=code)) == 0:
+ if Document.objects.filter(code=code).count() == 0:
return render(request, 'server/download_doc.html', context)
if Document.objects.filter(code=code)[0].group.name not in groups:
return render(request, 'server/download_doc.html', context)
@@ -1612,7 +1588,7 @@ def media_request(request, id=0, t="", flag=""):
doc_group = doc.group.name
groups = request.user.groups.values_list('name', flat=True)
- group_view = "capi" in groups and len(GroupSettings.objects.filter(group__name=doc_group).filter(view_documents=True)) != 0
+ group_view = "capi" in groups and GroupSettings.objects.filter(group__name=doc_group).filter(view_documents=True).count() != 0
# check if user can view media
if request.user.is_staff: