aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2020-06-22 12:56:03 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2020-06-22 12:56:03 +0200
commit8dabcc7622207781c1bd18f5285ab3393e9b7619 (patch)
tree04c2fb80c68b61d3464dfde5ed26299dd7c6d0da /server
parentFilter improve, missing chips and date (diff)
downloadscout-subs-8dabcc7622207781c1bd18f5285ab3393e9b7619.tar.gz
scout-subs-8dabcc7622207781c1bd18f5285ab3393e9b7619.zip
Chips filter, date filter, fix buttons with text
Diffstat (limited to '')
-rw-r--r--server/templates/server/doc_list.html50
-rw-r--r--server/templates/server/doc_type.html1
-rw-r--r--server/views.py66
3 files changed, 107 insertions, 10 deletions
diff --git a/server/templates/server/doc_list.html b/server/templates/server/doc_list.html
index 331a3d5..8a6be37 100644
--- a/server/templates/server/doc_list.html
+++ b/server/templates/server/doc_list.html
@@ -40,6 +40,7 @@
<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 class="tooltipped" data-position="top" data-tooltip="Pulisci filtri" Onclick="send('clear')"><i class="material-icons">clear</i></a></li>
<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>
@@ -104,6 +105,8 @@
</div>
</div>
<input type="hidden" name="action" id="action">
+<input type="hidden" name="owner" id="owner">
+<input type="hidden" name="type" id="type">
<ul class="collapsible">
{% for doc in docs %}
<li>
@@ -122,12 +125,20 @@
<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>
+ <span class="badge" data-badge-caption="">{{doc.0.user.first_name}} {{doc.0.user.last_name}}</span>
</div>
<div class="collapsible-body"><span>
- {{doc.0.code}} <br>
- {{doc.0.compilation_date}}<br>
<ul class="collapsible">
+ <li>
+ <div class="collapsible-header">
+ <i class="material-icons">confirmation_number</i>DEBUG {{doc.0.code}}
+ </div>
+ </li>
+ <li>
+ <div class="collapsible-header">
+ <i class="material-icons">send</i>{{doc.0.compilation_date}}
+ </div>
+ </li>
{% if doc.0.document_type.personal_data %}
<li>
<div class="collapsible-header">
@@ -212,7 +223,12 @@ $('#chips_type').chips({
},
limit: Infinity,
minLength: 0
- }
+ },
+ data: [
+ {% for d in chips_type %}
+ {tag: '{{d}}'},
+ {% endfor %}
+ ]
});
$('#chips_owner').chips({
placeholder: 'Utente',
@@ -220,18 +236,40 @@ $('#chips_owner').chips({
autocompleteOptions: {
data: {
{% for user in users %}
- '{{user.first_name}} {{user.last_name}}': null,
+ '{{user.username}} ({{user.first_name}} {{user.last_name}})': null,
{% endfor %}
},
limit: Infinity,
minLength: 0
- }
+ },
+ data: [
+ {% for d in chips_owner %}
+ {tag: '{{d}}'},
+ {% endfor %}
+ ]
});
function send(id) {
var form = document.getElementById('selection')
var action = document.getElementById('action')
+ var owner = document.getElementById('owner')
+ var type = document.getElementById('type')
+ var chips_owner = M.Chips.getInstance(document.getElementById('chips_owner'));
+ var chips_type = M.Chips.getInstance(document.getElementById('chips_type'));
+ var type_array = []
+ var owner_array = []
+
+ for (i=0; i < chips_owner.chipsData.length; i++) {
+ owner_array.push(chips_owner.chipsData[i].tag)
+ }
+
+ for (i=0; i < chips_type.chipsData.length; i++) {
+ type_array.push(chips_type.chipsData[i].tag)
+ }
+
action.setAttribute('value', id);
+ owner.setAttribute('value', owner_array.join("^|"))
+ type.setAttribute('value', type_array.join("^|"))
form.submit()
}
$('#select-all').click(function(event) {
diff --git a/server/templates/server/doc_type.html b/server/templates/server/doc_type.html
index 4e8a14a..39b5101 100644
--- a/server/templates/server/doc_type.html
+++ b/server/templates/server/doc_type.html
@@ -39,6 +39,7 @@
<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 class="tooltipped" data-position="top" data-tooltip="Pulisci filtri" Onclick="send('clear')"><i class="material-icons">clear</i></a></li>
<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>
diff --git a/server/views.py b/server/views.py
index 9ab4cde..296dae4 100644
--- a/server/views.py
+++ b/server/views.py
@@ -5,6 +5,11 @@ from django.db.models import Q
from django.http import HttpResponseRedirect
from django.db.models.deletion import ProtectedError
+import dateparser
+from datetime import datetime
+from datetime import timedelta
+import pytz
+
# Create your views here.
@@ -241,6 +246,15 @@ def doctype(request):
custom = "filter_custom" in request.POST
message = "filter_message" in request.POST
+ if request.POST["action"] == 'clear':
+ public = True
+ selfsign = True
+ hidden = False
+ personal = True
+ medic = True
+ custom = True
+ message = True
+
parent_group = request.user.groups.values_list('name', flat=True)[
0]
group = Group.objects.get(name=parent_group)
@@ -350,6 +364,7 @@ def doccreate(request):
def doclist(request):
context = {}
if request.user.is_staff:
+ zurich = pytz.timezone('Europe/Zurich')
error = False
error_text = ""
@@ -362,8 +377,12 @@ def doclist(request):
wait_check = 'checked="checked"'
selfsign_check = 'checked="checked"'
ok_check = 'checked="checked"'
- newer = ""
- older = ""
+ newer = zurich.localize(dateparser.parse("1970-01-01"))
+ older = zurich.localize(datetime.now())
+ owner = []
+ types = []
+ chips_owner = []
+ chips_types = []
if request.method == "POST":
selected = []
@@ -396,6 +415,20 @@ def doclist(request):
wait = "filter_wait" in request.POST
selfsign = "filter_selfsign" in request.POST
ok = "filter_ok" in request.POST
+ newer = zurich.localize(dateparser.parse(request.POST["newer"]))
+ older = zurich.localize(dateparser.parse(request.POST["older"]) + timedelta(days=1))
+ owner = request.POST["owner"].split("^|")
+ types = request.POST["type"].split("^|")
+
+ if request.POST["action"] == 'clear':
+ hidden = False
+ wait = True
+ selfsign = True
+ ok = True
+ newer = zurich.localize(dateparser.parse("1970-01-01"))
+ older = zurich.localize(datetime.now())
+ owner = []
+ types = []
parent_group = request.user.groups.values_list('name', flat=True)[
0]
@@ -415,6 +448,27 @@ def doclist(request):
documents = documents.filter(~Q(status="ok"))
ok_check = ""
+ documents = documents.filter(compilation_date__range=[newer, older])
+
+ if len(types) > 0:
+ if types[0] != "":
+ q_obj = Q()
+ for t in types:
+ q_obj |= Q(document_type__name=t)
+ chips_types.append(t)
+
+ documents = documents.filter(q_obj)
+
+ if len(owner) > 0:
+ if owner[0] != "":
+ q_obj = Q()
+ for u in owner:
+ user = u.split("(")[0][:-1]
+ q_obj |= Q(user__username=user)
+ chips_owner.append(u)
+
+ documents = documents.filter(q_obj)
+
out = []
for i in documents:
personal = None
@@ -426,16 +480,20 @@ def doclist(request):
out.append([i, KeyVal.objects.filter(container=i), personal, medical])
- types = DocumentType.objects.filter(Q(group_private=False) | Q(group=group))
+ auto_types = DocumentType.objects.filter(Q(group_private=False) | Q(group=group))
users = User.objects.filter(groups__name=parent_group)
context = {
- "types": types,
+ "types": auto_types,
"users": users,
"docs": out,
"hidden_check": hidden_check,
"wait_check": wait_check,
"selfsign_check": selfsign_check,
"ok_check": ok_check,
+ "newer": newer,
+ "older": older,
+ "chips_owner": chips_owner,
+ "chips_type": chips_types,
'error': error,
'error_text': error_text,
}