diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2021-09-23 10:34:23 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2021-09-23 10:34:59 +0200 |
commit | 5d461a177ad6b949b462f2f836d7f573060622a9 (patch) | |
tree | 2e4c33aa95e731e2c8d57c0c225fe513650a8056 /client | |
parent | remove last loops for admin interface (diff) | |
download | scout-subs-0.4.tar.gz scout-subs-0.4.zip |
use .count() instead of len(), add debug_toolbar0.4
Diffstat (limited to '')
-rw-r--r-- | client/templatetags/app_filter.py | 19 |
1 files changed, 17 insertions, 2 deletions
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 |