From 58f3293762b098ae0f4668fe2118aa7198f162ca Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Thu, 19 Aug 2021 22:19:58 +0200 Subject: remove some for loops user db query instead --- 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 3120b8e..e49e8a9 100644 --- a/client/templatetags/app_filter.py +++ b/client/templatetags/app_filter.py @@ -1,7 +1,22 @@ from django import template -from client.models import KeyVal +from django.db.models.query_utils import Q +from client.models import Document, KeyVal register = template.Library() @register.filter(name="doc_key") def doc_key(doc): - return KeyVal.objects.filter(container=doc) \ No newline at end of file + return KeyVal.objects.filter(container=doc) + +@register.filter(name="user_docs") +def user_docs(admin_user, user): + parent_group = admin_user.groups.values_list('name', flat=True)[0] + documents = Document.objects.filter(Q(user=user) & ~Q(status='archive') & Q(group__name=parent_group)) + return documents + +@register.filter(name="user_groups") +def user_groups(user): + return user.groups.values_list('name', flat=True) + +@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 -- cgit v1.2.1