From 5d461a177ad6b949b462f2f836d7f573060622a9 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Thu, 23 Sep 2021 10:34:23 +0200 Subject: use .count() instead of len(), add debug_toolbar --- CHANGELOG.md | 4 +++ client/templatetags/app_filter.py | 19 ++++++++++-- manager/settings.py | 7 +++++ manager/urls.py | 5 ++++ server/templates/server/doc_type.html | 55 ++++++++++++++++++----------------- server/templates/server/index.html | 11 +++---- server/views.py | 46 +++++++---------------------- 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 %}
{% csrf_token %}