aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-06-21 14:26:46 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-06-21 14:26:46 +0200
commit4e3a07d57519d6964b8c946e929a09ba19c13590 (patch)
tree799982e64b4292187aee7b6996fa4c850d8dc3dc /server
parentDoc, doctypes, users all done (diff)
downloadscout-subs-4e3a07d57519d6964b8c946e929a09ba19c13590.tar.gz
scout-subs-4e3a07d57519d6964b8c946e929a09ba19c13590.zip
Pdf download, filter on doc type
Diffstat (limited to 'server')
-rw-r--r--server/templates/server/doc_list.html123
-rw-r--r--server/templates/server/doc_type.html94
-rw-r--r--server/templates/server/index.html3
-rw-r--r--server/views.py106
4 files changed, 302 insertions, 24 deletions
diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html
index 0b3d800..730837c 100644
--- a/server/templates/server/doc_list.html
+++ b/server/templates/server/doc_list.html
@@ -3,16 +3,13 @@
{% block title %}Admin - Documenti{% endblock %}
{% block nav %}
- <nav>
+ <nav class="nav-extended">
<div class="nav-wrapper red lighten-1">
<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 'doclist' %}" class="breadcrumb hide-on-med-and-down">Documenti</a>
<ul class="right">
{% if user.is_staff %}
- <li><a onclick="send('archive')">Archivia selezionati</a></li>
- <li><a onclick="send('approve')">Approva selezionati</a></li>
- <li><a onclick="send('delete')">Elimina selezionati</a></li>
<li><a href="{% url 'server' %}">Pannello Admin</a></li>
{% endif %}
{% if user.is_authenticated %}
@@ -28,12 +25,86 @@
{% endif %}
</ul>
</div>
+ <div class="nav-wrapper red lighten-1">
+ <ul>
+ <li>
+ <input id="select-all" type="checkbox" class="filled-in"/>
+ <label for="select-all">
+ <a class="tooltipped" data-position="top" data-tooltip="(De)Seleziona tutti" onclick=""><i class="material-icons">select_all</i>
+ </label>
+ </a>
+ </li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Archivia selezionati" onclick="send('archive')"><i class="material-icons">archive</i></a></li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Dearchivia selezionati" Onclick="send('unarchive')"><i class="material-icons">unarchive</i></a></li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Approva selezionati" Onclick="send('approve')"><i class="material-icons left">check</i>DEBUG</a></li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Elimina selezionati" Onclick="send('delete')"><i class="material-icons left">delete</i>DEBUG</a></li>
+ </ul>
+ <ul class="right">
+ <li><a href="#modal1" data-target="modal1" class="modal-trigger tooltipped" data-position="top" data-tooltip="Filtri"><i class="material-icons">filter_list</i></a></li>
+ </ul>
+ </div>
</nav>
{% endblock %}
{% block content %}
<form id="selection" action="{% url 'doclist' %}" method="post">
{% csrf_token %}
+<div id="modal1" class="modal">
+ <div class="modal-content">
+ <h5>Filtri</h5>
+ <div class="row">
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_hidden" type="checkbox" class="filled-in" {{hidden_check}}/>
+ <span><i class="material-icons left">archive</i>Archiviati</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_public" type="checkbox" class="filled-in" {{public_check}}/>
+ <span><i class="material-icons left">timelapse</i>In Attesa</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_selfsign" type="checkbox" class="filled-in" {{selfsign_check}}/>
+ <span><i class="material-icons left">assignment_turned_in</i>No firma</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_personal" type="checkbox" class="filled-in" {{personal_check}}/>
+ <span><i class="material-icons left">check</i>Approvati</span>
+ </label>
+ </div>
+ </div>
+ <div class="row">
+ <div class="input-field col s6">
+ <label for="tetanus_date">Pi&ugrave; recenti di</label>
+ <input value="{{tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text" class="datepicker">
+ </div>
+ <div class="input-field col s6">
+ <label for="tetanus_date">Pi&ugrave; vecchi di</label>
+ <input value="{{tetanus_date}}" name="tetanus_date" id="tetanus_date" type="text" class="datepicker">
+ </div>
+ </div>
+ <div class ="row">
+ <div class="input-field col s12">
+ <input value="{{misc}}" name="misc" id="misc" type="text" data-length="250">
+ <label for="misc">Tipo di documento</label>
+ </div>
+ </div>
+ <div class ="row">
+ <div class="input-field col s12">
+ <input value="{{misc}}" name="misc" id="misc" type="text" data-length="250">
+ <label for="misc">Proprietario del documento</label>
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <a href="#!" onclick="send('filter')" class="modal-close waves-effect waves-green btn-flat">Applica</a>
+ </div>
+</div>
<input type="hidden" name="action" id="action">
<ul class="collapsible">
{% for doc in docs %}
@@ -49,6 +120,8 @@
<i class="material-icons">check</i>
{% elif doc.0.status == "archive" %}
<i class="material-icons">archive</i>
+ {% elif doc.0.status == "autosign" %}
+ <i class="material-icons">assignment_turned_in</i>
{% endif %}
{{doc.0.document_type.name}}
<span class="badge" data-badge-caption="">{{doc.0.user.username}}</span>
@@ -123,6 +196,11 @@
{%block script%}
$(document).ready(function(){
$('.collapsible').collapsible();
+ $('.tooltipped').tooltip();
+ $('.modal').modal();
+ {% if error %}
+ M.toast({html: '{{ error_text}}', classes: 'orange'})
+ {% endif %}
});
function send(id) {
var form = document.getElementById('selection')
@@ -130,4 +208,41 @@ function send(id) {
action.setAttribute('value', id);
form.submit()
}
+$('#select-all').click(function(event) {
+ if(this.checked) {
+ // Iterate each checkbox
+ $(':checkbox').each(function() {
+ this.checked = true;
+ });
+ } else {
+ $(':checkbox').each(function() {
+ this.checked = false;
+ });
+ }
+});
+var options = {
+ container: document.getElementById('main'),
+ yearRange:100,
+ format:'dd mmmm yyyy',
+ i18n: {
+ months: [ 'gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre' ],
+ monthsShort: [ 'gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic' ],
+ weekdays: [ 'domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato' ],
+ weekdaysShort: [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ],
+ weekdaysAbbrev: [ 'D', 'L', 'M', 'M', 'G', 'V', 'S' ],
+ today: 'Oggi',
+ clear: 'Cancella',
+ close: 'Chiudi',
+ firstDay: 1,
+ format: 'dddd d mmmm yyyy',
+ formatSubmit: 'yyyy/mm/dd',
+ labelMonthNext: 'Mese successivo',
+ labelMonthPrev: 'Mese precedente',
+ labelMonthSelect: 'Seleziona un mese',
+ labelYearSelect: 'Seleziona un anno'
+ }}
+ document.addEventListener('DOMContentLoaded', function() {
+ var elems = document.querySelectorAll('.datepicker');
+ var instances = M.Datepicker.init(elems, options);
+ });
{% endblock %} \ No newline at end of file
diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html
index 15ac30e..4e8a14a 100644
--- a/server/templates/server/doc_type.html
+++ b/server/templates/server/doc_type.html
@@ -3,15 +3,13 @@
{% block title %}Admin - Tipo Documenti{% endblock %}
{% block nav %}
- <nav>
+ <nav class="nav-extended">
<div class="nav-wrapper red lighten-1">
<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 'doctype' %}" class="breadcrumb hide-on-med-and-down">Tipo Doc</a>
<ul class="right">
{% if user.is_staff %}
- <li><a onclick="send('hide')">Nascondi/mostra selezionati</a></li>
- <li><a onclick="send('delete')">Elimina selezionati</a></li>
<li><a href="{% url 'server' %}">Pannello Admin</a></li>
{% endif %}
{% if user.is_authenticated %}
@@ -27,12 +25,84 @@
{% endif %}
</ul>
</div>
+ <div class="nav-wrapper red lighten-1">
+ <ul>
+ <li>
+ <input id="select-all" type="checkbox" class="filled-in"/>
+ <label for="select-all">
+ <a class="tooltipped" data-position="top" data-tooltip="(De)Seleziona tutti" onclick=""><i class="material-icons">select_all</i>
+ </label>
+ </a>
+ </li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Mostra selezionati" onclick="send('show')"><i class="material-icons">visibility</i></a></li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Nascondi selezionati" Onclick="send('hide')"><i class="material-icons">visibility_off</i></a></li>
+ <li><a class="tooltipped" data-position="top" data-tooltip="Elimina selezionati" Onclick="send('delete')"><i class="material-icons">delete</i></a></li>
+ </ul>
+ <ul class="right">
+ <li><a href="#modal1" data-target="modal1" class="modal-trigger tooltipped" data-position="top" data-tooltip="Filtri"><i class="material-icons">filter_list</i></a></li>
+ </ul>
+ </div>
</nav>
{% endblock %}
{% block content %}
<form id="selection" action="{% url 'doctype' %}" method="post">
{% csrf_token %}
+<div id="modal1" class="modal">
+ <div class="modal-content">
+ <h5>Filtri</h5>
+ <div class="row">
+ <div class="input-field col s4">
+ <label>
+ <input name="filter_hidden" type="checkbox" class="filled-in" {{hidden_check}}/>
+ <span><i class="material-icons left">visibility_off</i>Disabilitati</span>
+ </label>
+ </div>
+ <div class="input-field col s4">
+ <label>
+ <input name="filter_public" type="checkbox" class="filled-in" {{public_check}}/>
+ <span><i class="material-icons left">public</i>Pubblici</span>
+ </label>
+ </div>
+ <div class="input-field col s4">
+ <label>
+ <input name="filter_selfsign" type="checkbox" class="filled-in" {{selfsign_check}}/>
+ <span><i class="material-icons left">assignment_turned_in</i>No firma</span>
+ </label>
+ </div>
+ </div>
+ <div class="row">
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_personal" type="checkbox" class="filled-in" {{personal_check}}/>
+ <span><i class="material-icons left">person</i>Personali</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_medic" type="checkbox" class="filled-in" {{medic_check}}/>
+ <span><i class="material-icons left">healing</i>Medici</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_custom" type="checkbox" class="filled-in" {{custom_check}}/>
+ <span><i class="material-icons left">add_circle_outline</i>Personalizzati</span>
+ </label>
+ </div>
+ <div class="input-field col s3">
+ <label>
+ <input name="filter_message" type="checkbox" class="filled-in" {{message_check}}/>
+ <span><i class="material-icons left">message</i>Messaggi</span>
+ </label>
+ </div>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <a href="#!" onclick="send('filter')" class="modal-close waves-effect waves-green btn-flat">Applica</a>
+ </div>
+</div>
+
<input type="hidden" name="action" id="action">
<ul class="collapsible">
{% for doctype in docs %}
@@ -114,6 +184,11 @@
{%block script%}
$(document).ready(function(){
$('.collapsible').collapsible();
+ $('.tooltipped').tooltip();
+ $('.modal').modal();
+ {% if error %}
+ M.toast({html: '{{ error_text}}', classes: 'orange'})
+ {% endif %}
});
function send(id) {
@@ -122,4 +197,17 @@ function send(id) {
action.setAttribute('value', id);
form.submit()
}
+
+$('#select-all').click(function(event) {
+ if(this.checked) {
+ // Iterate each checkbox
+ $(':checkbox').each(function() {
+ this.checked = true;
+ });
+ } else {
+ $(':checkbox').each(function() {
+ this.checked = false;
+ });
+ }
+});
{% endblock %} \ No newline at end of file
diff --git a/server/templates/server/index.html b/server/templates/server/index.html
index 199feb5..6b2f597 100644
--- a/server/templates/server/index.html
+++ b/server/templates/server/index.html
@@ -50,6 +50,9 @@
{% if not doctype.0.group_private %}
<i class="material-icons">public</i>
{% endif %}
+ {% if doctype.0.auto_sign %}
+ <i class="material-icons">assignment_turned_in</i>
+ {% endif %}
{{doctype.0.name}}
<span class="new badge red lighten-1" data-badge-caption="">{{doctype.1}}</span>
</div>
diff --git a/server/views.py b/server/views.py
index 6c651f1..f29cb00 100644
--- a/server/views.py
+++ b/server/views.py
@@ -33,7 +33,7 @@ def index(request):
0]
group = Group.objects.get(name=parent_group)
public_types = DocumentType.objects.filter(
- Q(group_private=False) | Q(group=group))
+ Q(group_private=False) | Q(group=group) & Q(enabled=True))
docs = []
for doc in public_types:
ref_docs = Document.objects.filter(document_type=doc)
@@ -196,38 +196,96 @@ def ulist(request):
def doctype(request):
context = {}
if request.user.is_staff:
+ error = False
+ error_text = ""
+
+ public = True
+ selfsign = True
+ hidden = False
+ personal = True
+ medic = True
+ custom = True
+ message = True
+ public_check = 'checked="checked"'
+ selfsign_check = 'checked="checked"'
+ hidden_check = 'checked="checked"'
+ personal_check = 'checked="checked"'
+ medic_check = 'checked="checked"'
+ custom_check = 'checked="checked"'
+ message_check = 'checked="checked"'
if request.method == "POST":
selected = []
for i in request.POST.keys():
- if i == "csrfmiddlewaretoken":
- continue
- if i == "action":
- continue
-
- selected.append(DocumentType.objects.get(id=i))
+ if i.isdigit():
+ selected.append(DocumentType.objects.get(id=i))
for i in selected:
if request.POST["action"] == 'delete':
try:
i.delete()
except ProtectedError:
- print("nope")
+ error = True
+ error_text = "Non puoi eliminare un tipo a cui é collegato uno o piú documenti"
elif request.POST["action"] == 'hide':
- i.enabled = not i.enabled
+ i.enabled = False
+ i.save()
+ elif request.POST["action"] == 'show':
+ i.enabled = True
i.save()
+ public = "filter_public" in request.POST
+ selfsign = "filter_selfsign" in request.POST
+ hidden = "filter_hidden" in request.POST
+ personal = "filter_personal" in request.POST
+ medic = "filter_medic" in request.POST
+ custom = "filter_custom" in request.POST
+ message = "filter_message" in request.POST
+
parent_group = request.user.groups.values_list('name', flat=True)[
0]
group = Group.objects.get(name=parent_group)
public_types = DocumentType.objects.filter(
Q(group_private=False) | Q(group=group))
+ if not public:
+ public_types = public_types.filter(group_private=True)
+ public_check = ""
+ if not selfsign:
+ public_types = public_types.filter(auto_sign=False)
+ selfsign_check = ""
+ if not hidden:
+ public_types = public_types.filter(enabled=True)
+ hidden_check = ""
+ if not personal:
+ public_types = public_types.filter(personal_data=False)
+ personal_check = ""
+ if not medic:
+ public_types = public_types.filter(medical_data=False)
+ medic_check = ""
+ if not custom:
+ public_types = public_types.filter(custom_data=False)
+ custom_check = ""
+ if not message:
+ public_types = public_types.filter(custom_message=False)
+ message_check = ""
+
out = []
for doc in public_types:
custom_keys = Keys.objects.filter(container=doc)
ref_docs = Document.objects.filter(document_type=doc)
out.append([doc, custom_keys, len(ref_docs)])
- context = {'docs': out}
+ context = {
+ 'docs': out,
+ 'public_check': public_check,
+ 'selfsign_check': selfsign_check,
+ 'hidden_check': hidden_check,
+ 'personal_check': personal_check,
+ 'medic_check': medic_check,
+ 'custom_check': custom_check,
+ 'message_check': message_check,
+ 'error': error,
+ 'error_text': error_text,
+ }
return render(request, 'server/doc_type.html', context)
else:
return render(request, 'client/index.html', context)
@@ -292,6 +350,8 @@ def doccreate(request):
def doclist(request):
context = {}
if request.user.is_staff:
+ error = False
+ error_text = ""
if request.method == "POST":
selected = []
for i in request.POST.keys():
@@ -304,16 +364,24 @@ def doclist(request):
for i in selected:
if request.POST["action"] == 'delete':
- try:
- i.delete()
- except ProtectedError:
- print("nope")
+ i.delete()
elif request.POST["action"] == 'approve':
i.status = 'ok'
i.save()
elif request.POST["action"] == 'archive':
- i.status = 'archive'
- i.save()
+ if i.status == 'ok':
+ i.status = 'archive'
+ i.save()
+ else:
+ error = True
+ error_text = "Non puoi archiviare un documento non approvato"
+ elif request.POST["action"] == 'unarchive':
+ if i.status == 'archive':
+ i.status = 'ok'
+ i.save()
+ else:
+ error = True
+ error_text = "Non puoi dearchiviare un documento non archiviato"
parent_group = request.user.groups.values_list('name', flat=True)[
0]
@@ -329,7 +397,11 @@ def doclist(request):
medical = i.medical_data.__dict__.values()
out.append([i, KeyVal.objects.filter(container=i), personal, medical])
- context = {"docs": out}
+ context = {
+ "docs": out,
+ 'error': error,
+ 'error_text': error_text,
+ }
return render(request, 'server/doc_list.html', context)
else:
return render(request, 'client/index.html', context)