diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2021-08-19 22:19:58 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2021-08-19 22:20:13 +0200 |
commit | 58f3293762b098ae0f4668fe2118aa7198f162ca (patch) | |
tree | f1e4f01781e75e5c59f7413c3b8e748f9b04ac03 /client | |
parent | use query instead of for loop in client (diff) | |
download | scout-subs-58f3293762b098ae0f4668fe2118aa7198f162ca.tar.gz scout-subs-58f3293762b098ae0f4668fe2118aa7198f162ca.zip |
remove some for loops user db query instead
Diffstat (limited to 'client')
-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 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 |