diff options
Diffstat (limited to '')
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | client/templatetags/app_filter.py | 19 | ||||
-rw-r--r-- | manager/settings.py | 7 | ||||
-rw-r--r-- | manager/urls.py | 5 | ||||
-rw-r--r-- | server/templates/server/doc_type.html | 55 | ||||
-rw-r--r-- | server/templates/server/index.html | 11 | ||||
-rw-r--r-- | server/views.py | 46 | ||||
-rw-r--r-- | version.txt | 4 |
8 files changed, 80 insertions, 71 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b26b4f5..eae250a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4 (23 set 2021) +- Bug: emergency document list visible also to non "capi" +- Overall performance improvements leveraging SQL queries + # 0.3 (23 jul 2021) - Bug: Reconvert images to JPEG so that all device can show them diff --git a/client/templatetags/app_filter.py b/client/templatetags/app_filter.py index e49e8a9..9f378e1 100644 --- a/client/templatetags/app_filter.py +++ b/client/templatetags/app_filter.py @@ -1,12 +1,16 @@ from django import template from django.db.models.query_utils import Q -from client.models import Document, KeyVal +from client.models import Document, KeyVal, Keys register = template.Library() @register.filter(name="doc_key") def doc_key(doc): return KeyVal.objects.filter(container=doc) +@register.filter(name="doc_key_type") +def doc_key_type(doc_type): + return Keys.objects.filter(container=doc_type) + @register.filter(name="user_docs") def user_docs(admin_user, user): parent_group = admin_user.groups.values_list('name', flat=True)[0] @@ -19,4 +23,15 @@ def user_groups(user): @register.filter(name="user_primary_group") def user_primary_group(user): - return user.groups.values_list('name', flat=True)[0]
\ No newline at end of file + return user.groups.values_list('name', flat=True)[0] + +@register.filter(name="doc_count") +def doc_count(doc): + 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) + + return doc_count
\ No newline at end of file diff --git a/manager/settings.py b/manager/settings.py index 03942d9..fae2385 100644 --- a/manager/settings.py +++ b/manager/settings.py @@ -69,6 +69,13 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] +if DEBUG: + INSTALLED_APPS.append('debug_toolbar') + MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware') + INTERNAL_IPS = [ + '127.0.0.1', + ] + ROOT_URLCONF = 'manager.urls' TEMPLATES = [ diff --git a/manager/urls.py b/manager/urls.py index a2c0ebf..f3b8008 100644 --- a/manager/urls.py +++ b/manager/urls.py @@ -15,6 +15,7 @@ Including another URLconf """ from django.contrib import admin from django.urls import path, include +from django.conf import settings urlpatterns = [ path('', include('client.urls')), @@ -23,3 +24,7 @@ urlpatterns = [ path('accounts/', include('django.contrib.auth.urls')), path('admin/', admin.site.urls), ] + +if settings.DEBUG: + import debug_toolbar + urlpatterns.append(path('__debug__/', include(debug_toolbar.urls)))
\ No newline at end of file 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:
diff --git a/version.txt b/version.txt index e25165c..5dafcc3 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -version=0.3 -rev=12 +version=0.4 +rev=1 |