diff options
Diffstat (limited to 'ctrack/organisations/utils.py')
-rw-r--r-- | ctrack/organisations/utils.py | 13 |
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)) |