Commit aa3d6f59 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Only show active committees that the user is a member of

parent 1f232665
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.contrib import admin from django.contrib import admin
from django.db.models import Q
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
...@@ -10,7 +11,6 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -10,7 +11,6 @@ from django.utils.translation import ugettext_lazy as _
from activemembers.models import Committee from activemembers.models import Committee
from members.models import Member from members.models import Member
from utils.translation import TranslatedModelAdmin from utils.translation import TranslatedModelAdmin
from . import forms, models from . import forms, models
...@@ -108,11 +108,17 @@ class EventAdmin(DoNextModelAdmin): ...@@ -108,11 +108,17 @@ class EventAdmin(DoNextModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs): def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'organiser': if db_field.name == 'organiser':
# Use custom queryset for organiser field # Use custom queryset for organiser field
# Only get the current active committees the user is a member of
try: try:
if not request.user.is_superuser: if not request.user.is_superuser:
member = request.user.member member = request.user.member
kwargs['queryset'] = Committee.active_committees.filter( kwargs['queryset'] = Committee.objects.filter(
members=member) Q(committeemembership__member=member) &
(
Q(committeemembership__until=None) |
Q(committeemembership__until__gt=timezone.now())
)).exclude(active=False)
except Member.DoesNotExist: except Member.DoesNotExist:
pass pass
return super().formfield_for_foreignkey(db_field, request, **kwargs) return super().formfield_for_foreignkey(db_field, request, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment