aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2021-08-19 22:19:58 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2021-08-19 22:20:13 +0200
commit58f3293762b098ae0f4668fe2118aa7198f162ca (patch)
treef1e4f01781e75e5c59f7413c3b8e748f9b04ac03 /client
parentuse query instead of for loop in client (diff)
downloadscout-subs-58f3293762b098ae0f4668fe2118aa7198f162ca.tar.gz
scout-subs-58f3293762b098ae0f4668fe2118aa7198f162ca.zip
remove some for loops user db query instead
Diffstat (limited to '')
-rw-r--r--client/templatetags/app_filter.py19
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