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 --- client/templatetags/app_filter.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'client') 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 -- cgit v1.2.1