aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/organisations/utils.py
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-19 16:21:03 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-19 16:25:09 +0100
commit9cc3de6d0245bdc4ed87b810a2208efdd09b6277 (patch)
tree2987cca4ef6eb58fa2e6817c40fb920707f167b4 /ctrack/organisations/utils.py
parentbb39f7f52d5ff6dcf311d9e2a987417796e09424 (diff)
can now filter out private events not belonging to logged in user
Diffstat (limited to 'ctrack/organisations/utils.py')
-rw-r--r--ctrack/organisations/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/ctrack/organisations/utils.py b/ctrack/organisations/utils.py
new file mode 100644
index 0000000..121a694
--- /dev/null
+++ b/ctrack/organisations/utils.py
@@ -0,0 +1,13 @@
+from django.contrib.auth.models import User
+from django.db.models import QuerySet, Q
+
+
+def filter_private_events(events: QuerySet, user: User):
+ """
+ Given a QuerySet containing SingleDateTimeEvent objects,
+ ensure that any objects whose user==user and private==True
+ are filtered out. This supports OrganisationDetailView, which
+ lists all events for an organisation but which must hide private
+ events for the logged-in user.
+ """
+ return events.exclude(~Q(user=user) & Q(private=True))