aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAndrea Lepori <aleporia@gmail.com>2023-07-28 18:03:29 +0200
committerAndrea Lepori <aleporia@gmail.com>2023-07-28 18:03:29 +0200
commit72dc2a4e287fe04e2b62af599b25c91477bfb905 (patch)
treecdedb381c52e3243bae4d7e064e00c35e78d9e58 /server
parentremove branca from uc from admin panel (diff)
downloadscout-subs-72dc2a4e287fe04e2b62af599b25c91477bfb905.tar.gz
scout-subs-72dc2a4e287fe04e2b62af599b25c91477bfb905.zip
new doc list from doc types
Diffstat (limited to '')
-rw-r--r--server/templates/server/debug_usercode.html2
-rw-r--r--server/templates/server/doc_list.html5
-rw-r--r--server/templates/server/doc_list_table.html24
-rw-r--r--server/templates/server/doc_type.html120
-rw-r--r--server/templates/server/index.html12
-rw-r--r--server/urls.py4
-rw-r--r--server/views.py101
7 files changed, 222 insertions, 46 deletions
diff --git a/server/templates/server/debug_usercode.html b/server/templates/server/debug_usercode.html
index 014d6fd..9549d77 100644
--- a/server/templates/server/debug_usercode.html
+++ b/server/templates/server/debug_usercode.html
@@ -6,7 +6,7 @@
<pre>
{% for user in data %}
-[{{user.0.id}}] {{user.0.username}} {{user.0.first_name}} {{user.0.last_name}}
+[{{user.0.id}}] {{user.0.username}} {{user.0.first_name}} {{user.0.last_name}} ({{user.2}})
{% for uc in user.1 %} [{{uc.id}}] {{uc.code}} {{uc.first_name}} {{uc.last_name}} ({{uc.branca}})
{% endfor %} {% endfor %}
</pre>
diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html
index 28511e7..27c209c 100644
--- a/server/templates/server/doc_list.html
+++ b/server/templates/server/doc_list.html
@@ -4,6 +4,7 @@
{% block breadcrumb %}
<a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a>
+ <a href="{% url 'doctype'%}" class="breadcrumb hide-on-med-and-down">Tipi</a>
<a class="breadcrumb hide-on-med-and-down">Documenti</a>
{% endblock %}
{% block toolbar %}
@@ -62,7 +63,7 @@
</div>
</div>
-<form id="selection" action="{% url 'doclist' %}" method="post">
+<form id="selection" action="{% url 'doclist' type_id=type_id %}" method="post">
{% csrf_token %}
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-content">
@@ -106,7 +107,7 @@
</div>
</div>
<div class = "row">
- <div class="col s12">
+ <div class="col s12" {% if type_id != 0 %} hidden {% endif %}>
<div id="chips_type" class="chips chips-placeholder chips-autocomplete"></div>
</div>
<div class="col s12">
diff --git a/server/templates/server/doc_list_table.html b/server/templates/server/doc_list_table.html
index 6b3556b..6a12378 100644
--- a/server/templates/server/doc_list_table.html
+++ b/server/templates/server/doc_list_table.html
@@ -4,6 +4,7 @@
{% block breadcrumb %}
<a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a>
+ <a href="{% url 'doctype'%}" class="breadcrumb hide-on-med-and-down">Tipi</a>
<a class="breadcrumb hide-on-med-and-down">Documenti</a>
{% endblock %}
{% block toolbar %}
@@ -20,7 +21,7 @@
{% block content %}
{% load app_filter %}
-<form id="selection" action="{% url 'doclist-table' %}" method="post">
+<form id="selection" action="{% url 'doclist-table' type_id=type_id %}" method="post">
{% csrf_token %}
<div id="modal2" class="modal modal-fixed-footer">
<div class="modal-content">
@@ -64,7 +65,7 @@
</div>
</div>
<div class = "row">
- <div class="col s12">
+ <div class="col s12" {% if type_id != 0 %} hidden {% endif %}>
<div id="chips_type" class="chips chips-placeholder chips-autocomplete"></div>
</div>
<div class="col s12">
@@ -170,6 +171,9 @@
allergy: "{{doc.medical_data.allergy}}",
drugs: "{{doc.medical_data.drugs}}",
misc: "{{doc.medical_data.misc}}",
+ {% for key in doc|doc_key %}
+ custom_key_{{forloop.counter0}}: "{{key.value}}",
+ {% endfor %}
},
{% endfor %}
];
@@ -179,11 +183,11 @@
var col_categories = [
{field: "base", name: "Informazioni base", cols:
[
+ {title: "Nome", field: "name", frozen: true},
+ {title: "Cognome", field: "last_name", frozen: true},
{title: "Stato", field: "status", formatter: iconFormatter},
{title: "Tipo", field: "type"},
{title: "Codice", field: "code"},
- {title: "Nome", field: "name"},
- {title: "Cognome", field: "last_name"},
{title: "Capo", field: "capo", formatter:"tickCross"},
{title: "Data compilazione", field: "compilation_date"},
{title: "Branca", field: "branca"},
@@ -227,6 +231,15 @@
{title: "Info particolari", field: "misc", visible: false},
]
},
+ {% if custom_keys|length > 0 %}
+ {field: "custom", name: "Parametri personalizzati", cols:
+ [
+ {% for key in custom_keys %}
+ {title: "{{key.1}}", field: "custom_key_{{key.0}}", visible: true, width: "7%"},
+ {% endfor %}
+ ]
+ },
+ {% endif %}
]
var docTypes = {};
@@ -261,8 +274,9 @@
var table = new Tabulator("#example-table", {
movableColumns: true,
layout:"fitDataFill",
- responsiveLayout: "hide",
+ {% if type_id == 0 %}
groupBy: "type",
+ {% endif %}
data:tabledata,
columns:columns,
groupHeader:function(value, count, data, group){
diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html
index 4f8fe6f..c81bcdb 100644
--- a/server/templates/server/doc_type.html
+++ b/server/templates/server/doc_type.html
@@ -4,7 +4,7 @@
{% block breadcrumb %}
<a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a>
- <a class="breadcrumb hide-on-med-and-down">Tipo Doc</a>
+ <a class="breadcrumb hide-on-med-and-down">Tipi</a>
{% endblock %}
{% block toolbar %}
<div class="nav-wrapper {{color}}">
@@ -119,7 +119,7 @@
<input type="hidden" name="action" id="action">
<ul class="collapsible">
- {% for doctype in docs %}
+ {% for doctype, dat in docs %}
<li>
<div class="collapsible-header list">
<label>
@@ -142,15 +142,17 @@
<i class="material-icons">lock</i>
{% endif %}
{{doctype.name}}
- <span class="new badge {{color}}" data-badge-caption="">{{doctype|doc_count}}</span>
+ <span class="new badge {{color}}" data-badge-caption="">{{dat.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.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>
+ <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>
+ <a class="waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.id}}')"><i class="material-icons left">download_for_offline</i>Scarica CSV (con dati medici)</a>
{% endif %}
+ <a class="waves-effect waves-light btn {{color}}" href={% url "doclist" type_id=doctype.id %}><i class="material-icons left">description</i>Documenti</a>
+ <a class="waves-effect waves-light btn {{color}}" href={% url "doclist-table" type_id=doctype.id %}><i class="material-icons left">document_scanner</i>Documenti formato tabella (BETA)</a>
</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.id}}')"><i class="material-icons left">edit</i> Modifica tipo</a>
@@ -160,11 +162,16 @@
{% if doctype.medical_data %}
<br>
<br>
- <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>
+ <a class="col s12 waves-effect waves-light btn {{color}}" onclick="send('m{{doctype.id}}')"><i class="material-icons left">download_for_offline</i> Scarica CSV (con dati medici)</a>
+ <br>
+ <br>
+ <a class="col s12 waves-effect waves-light btn {{color}}" href={% url "doclist" type_id=doctype.id %}><i class="material-icons left">description</i>Documenti</a>
+ <br>
+ <br>
+ <a class="col s12 waves-effect waves-light btn {{color}}" href={% url "doclist-table" type_id=doctype.id %}><i class="material-icons left">document_scanner</i>Documenti formato tabella (BETA)</a>
{% endif %}
</div>
<br>
- <br>
<ul class="collection">
{% if not doctype.group_private %}
<li class="collection-item">
@@ -187,6 +194,103 @@
</li>
{% endif %}
</ul>
+ <br>
+
+ <div class="hide-on-med-and-down">
+ <div class="row">
+ <div class="col s6">
+ <table class="responsive-table striped">
+ <tbody>
+ <tr>
+ <td><b>Riassuntivo</b></td>
+ <td><b>Partecipanti</b></td>
+ <td><b>Capi</b></td>
+ <td><b>Totale</b></td>
+ </tr>
+ <tr>
+ <td><b>diga</b></td>
+ <td>{{dat.diga.0}}</td>
+ <td>{{dat.diga.1}}</td>
+ <td>{{dat.diga.2}}</td>
+ </tr>
+ <tr>
+ <td><b>muta</b></td>
+ <td>{{dat.muta.0}}</td>
+ <td>{{dat.muta.1}}</td>
+ <td>{{dat.muta.2}}</td>
+ </tr>
+ <tr>
+ <td><b>reparto</b></td>
+ <td>{{dat.reparto.0}}</td>
+ <td>{{dat.reparto.1}}</td>
+ <td>{{dat.reparto.2}}</td>
+ </tr>
+ <tr>
+ <td><b>posto</b></td>
+ <td>{{dat.posto.0}}</td>
+ <td>{{dat.posto.1}}</td>
+ <td>{{dat.posto.2}}</td>
+ </tr>
+ <tr>
+ <td><b>clan</b></td>
+ <td>{{dat.clan.0}}</td>
+ <td>{{dat.clan.1}}</td>
+ <td>{{dat.clan.2}}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ <div class="hide-on-large-only row">
+ <div class="row">
+ <div class="col s12">
+ <table class="responsive-table striped">
+ <tbody>
+ <tr>
+ <td><b>Riassuntivo</b></td>
+ <td><b>Partecipanti</b></td>
+ <td><b>Capi</b></td>
+ <td><b>Totale</b></td>
+ </tr>
+ <tr>
+ <td><b>diga</b></td>
+ <td>{{dat.diga.0}}</td>
+ <td>{{dat.diga.1}}</td>
+ <td>{{dat.diga.2}}</td>
+ </tr>
+ <tr>
+ <td><b>muta</b></td>
+ <td>{{dat.muta.0}}</td>
+ <td>{{dat.muta.1}}</td>
+ <td>{{dat.muta.2}}</td>
+ </tr>
+ <tr>
+ <td><b>reparto</b></td>
+ <td>{{dat.reparto.0}}</td>
+ <td>{{dat.reparto.1}}</td>
+ <td>{{dat.reparto.2}}</td>
+ </tr>
+ <tr>
+ <td><b>posto</b></td>
+ <td>{{dat.posto.0}}</td>
+ <td>{{dat.posto.1}}</td>
+ <td>{{dat.posto.2}}</td>
+ </tr>
+ <tr>
+ <td><b>clan</b></td>
+ <td>{{dat.clan.0}}</td>
+ <td>{{dat.clan.1}}</td>
+ <td>{{dat.clan.2}}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ <br>
{% if doctype.custom_data or doctype.custom_message %}
<ul class="collapsible">
{% if doctype.custom_data %}
diff --git a/server/templates/server/index.html b/server/templates/server/index.html
index 487ef71..5a8bd5f 100644
--- a/server/templates/server/index.html
+++ b/server/templates/server/index.html
@@ -87,20 +87,12 @@
</div>
<div class="card-action">
<div class="hide-on-med-and-down">
- <a class="waves-effect waves-light btn {{color}}" href="{% url 'doctype' %}">Tipi</a>
- <a class="waves-effect waves-light btn {{color}}" href="{% url 'doclist' %}">Documenti</a>
- <a class="waves-effect waves-light btn {{color}}" href="{% url 'doclist-table' %}">Documenti (Tabella BETA)</a>
+ <a class="waves-effect waves-light btn {{color}}" href="{% url 'doctype' %}">Documenti</a>
<a class="waves-effect waves-light btn {{color}}" href="{% url 'docapprove' %}">Approva documento</a>
</div>
<div class="hide-on-large-only">
- <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'doctype' %}">Tipi</a>
- <br>
- <br>
- <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'doclist' %}">Documenti</a>
- <br>
- <br>
- <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'docapprove' %}">Approva documento</a>
+ <a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'doctype' %}">Documenti</a>
<br>
<br>
<a class="col s12 waves-effect waves-light btn {{color}}" href="{% url 'docupload' %}">Carica firma</a>
diff --git a/server/urls.py b/server/urls.py
index 33ba3d8..5937707 100644
--- a/server/urls.py
+++ b/server/urls.py
@@ -11,8 +11,8 @@ urlpatterns = [
path('doctype', views.doctype, name='doctype'),
path('doccreate', views.doccreate, name='doccreate'),
path('docedit', views.docedit, name='docedit'),
- path('doclist', views.doclist, name='doclist'),
- path('doclist-table', views.doclist_table, name='doclist-table'),
+ path('doclist/<int:type_id>', views.doclist, name='doclist'),
+ path('doclist-table/<int:type_id>', views.doclist_table, name='doclist-table'),
path('doclistro', views.doclist_readonly, name='doclistro'),
path('docapprove', views.docapprove, name='docapprove'),
path('docupload', views.upload_doc, name='docupload'),
diff --git a/server/views.py b/server/views.py
index e264b68..d44ac66 100644
--- a/server/views.py
+++ b/server/views.py
@@ -745,8 +745,47 @@ def doctype(request):
public_types = public_types.filter(custom_group=False)
group_check = ""
+ docs = []
+ for doc in public_types:
+ doc_count = str(Document.objects.filter(document_type=doc).count())
+ ref_docs_archived = Document.objects.filter(document_type=doc, status="archive").count()
+ if ref_docs_archived > 0:
+ doc_count += "-" + str(ref_docs_archived)
+ if doc.max_instances != 0:
+ doc_count += "/" + str(doc.max_instances)
+
+ count = {
+ "diga": [
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="diga") & ~Q(status="archive") & ~Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="diga") & ~Q(status="archive") & Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="diga") & ~Q(status="archive")).count(),
+ ],
+ "muta": [
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="muta") & ~Q(status="archive") & ~Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="muta") & ~Q(status="archive") & Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="muta") & ~Q(status="archive")).count(),
+ ],
+ "reparto": [
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="reparto") & ~Q(status="archive") & ~Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="reparto") & ~Q(status="archive") & Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="reparto") & ~Q(status="archive")).count(),
+ ],
+ "posto": [
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="posto") & ~Q(status="archive") & ~Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="posto") & ~Q(status="archive") & Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="posto") & ~Q(status="archive")).count(),
+ ],
+ "clan": [
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="clan") & ~Q(status="archive") & ~Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="clan") & ~Q(status="archive") & Q(usercode__user__groups__name__contains="capi")).count(),
+ Document.objects.filter(Q(document_type=doc) & Q(usercode__branca__name="clan") & ~Q(status="archive")).count(),
+ ],
+ "doc_count": doc_count,
+ }
+ docs.append([doc, count])
+
context = {
- 'docs': public_types,
+ 'docs': docs,
'public_check': public_check,
'selfsign_check': selfsign_check,
'hidden_check': hidden_check,
@@ -1021,12 +1060,19 @@ def docedit_wrapper(request, context):
return render(request, 'server/doc_edit.html', context)
@user_passes_test(isStaff)
-def doclist(request):
+def doclist(request, type_id):
context = {}
# group name and obj
parent_groups = getGroups(request)
+ # check if type is selected
+ doc_type = None
+ if type_id != 0:
+ doc_type = DocumentType.objects.get(id=type_id)
+ if doc_type.group not in parent_groups:
+ return
+
# create typezone
zurich = pytz.timezone('Europe/Zurich')
@@ -1156,6 +1202,9 @@ def doclist(request):
# filter documents based on group of staff and date range
q_obj = Q(group__in=parent_groups) & Q(compilation_date__range=[newer, older])
+ if type_id != 0:
+ q_obj &= Q(document_type=doc_type)
+
# filter documents
if not hidden:
q_obj &= ~Q(status="archive")
@@ -1187,7 +1236,7 @@ def doclist(request):
if len(groups) > 0:
if groups[0] != "":
- q_obj &= Q(user__groups__name__in=groups)
+ q_obj &= Q(usercode__branca__name__in=groups)
chips_groups += groups
# run query
@@ -1202,7 +1251,7 @@ def doclist(request):
# get types and users for chips autocompletation
if request.user.is_staff:
auto_types = DocumentType.objects.filter(
- Q(group_private=False) | Q(group=getGroups(request)[0]))
+ Q(group_private=False) | Q(group__in=getGroups(request)))
else:
auto_types = DocumentType.objects.filter(Q(group_private=False))
@@ -1228,11 +1277,12 @@ def doclist(request):
'error_text': error_text,
'settings': settings,
'total_count': documents.count,
- 'diga_count': documents.filter(user__groups__name__contains="diga").count,
- 'muta_count': documents.filter(user__groups__name__contains="muta").count,
- 'reparto_count': documents.filter(user__groups__name__contains="reparto").count,
- 'posto_count': documents.filter(user__groups__name__contains="posto").count,
- 'clan_count': documents.filter(user__groups__name__contains="clan").count,
+ 'diga_count': documents.filter(usercode__branca__name="diga").count,
+ 'muta_count': documents.filter(usercode__branca__name="muta").count,
+ 'reparto_count': documents.filter(usercode__branca__name="reparto").count,
+ 'posto_count': documents.filter(usercode__branca__name="posto").count,
+ 'clan_count': documents.filter(usercode__branca__name="clan").count,
+ 'type_id': type_id,
}
# check if download multiple documents
@@ -1253,12 +1303,19 @@ def doclist(request):
return render(request, 'server/doc_list.html', context)
@user_passes_test(isStaff)
-def doclist_table(request):
+def doclist_table(request, type_id):
context = {}
# group name and obj
parent_groups = getGroups(request)
+ # check if type is selected
+ doc_type = None
+ if type_id != 0:
+ doc_type = DocumentType.objects.get(id=type_id)
+ if doc_type.group not in parent_groups:
+ return
+
# create typezone
zurich = pytz.timezone('Europe/Zurich')
@@ -1321,6 +1378,12 @@ def doclist_table(request):
# filter documents based on group of staff and date range
q_obj = Q(group__in=parent_groups) & Q(compilation_date__range=[newer, older])
+ custom_keys = []
+ if type_id != 0:
+ q_obj &= Q(document_type=doc_type)
+ custom_keys = list(Keys.objects.filter(container=doc_type).values_list("key", flat=True))
+ custom_keys = list(enumerate(custom_keys))
+
# filter documents
if not hidden:
q_obj &= ~Q(status="archive")
@@ -1352,7 +1415,7 @@ def doclist_table(request):
if len(groups) > 0:
if groups[0] != "":
- q_obj &= Q(user__groups__name__in=groups)
+ q_obj &= Q(usercode__branca__name__in=groups)
chips_groups += groups
# run query
@@ -1385,6 +1448,8 @@ def doclist_table(request):
'error': error,
'error_text': error_text,
'settings': settings,
+ 'type_id': type_id,
+ 'custom_keys': custom_keys,
}
return render(request, 'server/doc_list_table.html', context)
@@ -1557,7 +1622,7 @@ def doclist_readonly(request):
if len(groups) > 0:
if groups[0] != "":
- q_obj &= Q(user__groups__name__in=groups)
+ q_obj &= Q(usercode__branca__name__in=groups)
chips_groups += groups
# run query
@@ -1595,11 +1660,11 @@ def doclist_readonly(request):
'error_text': error_text,
'settings': settings,
'total_count': documents.count,
- 'diga_count': documents.filter(user__groups__name__contains="diga").count,
- 'muta_count': documents.filter(user__groups__name__contains="muta").count,
- 'reparto_count': documents.filter(user__groups__name__contains="reparto").count,
- 'posto_count': documents.filter(user__groups__name__contains="posto").count,
- 'clan_count': documents.filter(user__groups__name__contains="clan").count,
+ 'diga_count': documents.filter(usercode__branca__name="diga").count,
+ 'muta_count': documents.filter(usercode__branca__name="muta").count,
+ 'reparto_count': documents.filter(usercode__branca__name="reparto").count,
+ 'posto_count': documents.filter(usercode__branca__name="posto").count,
+ 'clan_count': documents.filter(usercode__branca__name="clan").count,
}
# check if download multiple documents
@@ -1810,7 +1875,7 @@ def debug_uc(request):
data = []
users = User.objects.all()
for u in users:
- data.append([u, UserCode.objects.filter(user=u)])
+ data.append([u, UserCode.objects.filter(user=u), list(u.groups.all().values_list("name", flat=True))])
context = {
"data": data,