Skip to content

Commit

Permalink
Notifikation om invitationer
Browse files Browse the repository at this point in the history
Filtrer så deltagere ikke vises (dvs hvis man har tilmeldt sig efter modtaget invitation).
  • Loading branch information
mhewel committed Oct 27, 2024
1 parent 4bef9d5 commit 3964b60
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
10 changes: 3 additions & 7 deletions members/views/EntryPage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.views.decorators.clickjacking import xframe_options_exempt
from django.shortcuts import render
from django.utils import timezone

from members.models.activityinvite import ActivityInvite
from members.utils.user import user_to_person
from members.views.UnacceptedInvitations import get_unaccepted_invitations_for_family


@xframe_options_exempt
Expand All @@ -15,12 +14,9 @@ def EntryPage(request):
context = {}
else:
family = user.family
invites = ActivityInvite.objects.filter(
person__family=family, expire_dtm__gte=timezone.now(), rejected_at=None
)

unaccepted_invitations = get_unaccepted_invitations_for_family(family)
context = {
"invites": invites,
"invites": unaccepted_invitations,
}
else:
context = {}
Expand Down
9 changes: 3 additions & 6 deletions members/views/FamilyDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from django.utils import timezone
from django.contrib.auth.decorators import login_required, user_passes_test

from members.models.activityinvite import ActivityInvite
from members.models.person import Person
from members.utils.user import user_to_person, has_user
from members.views.UnacceptedInvitations import get_unaccepted_invitations_for_family


@login_required
Expand All @@ -23,10 +23,7 @@ def FamilyDetails(request):
< timezone.now()
- datetime.timedelta(days=settings.REQUEST_FAMILY_VALIDATION_PERIOD)
)

invites = ActivityInvite.objects.filter(
person__family=family, expire_dtm__gte=timezone.now(), rejected_at=None
)
unaccepted_invitations = get_unaccepted_invitations_for_family(family)

context = {
"family": family,
Expand All @@ -35,6 +32,6 @@ def FamilyDetails(request):
"request_parents": family.person_set.exclude(membertype=Person.CHILD).count()
< 1,
"ordered_persons": family.person_set.order_by("membertype").all(),
"invites": invites,
"invites": unaccepted_invitations,
}
return render(request, "members/family_details.html", context)
26 changes: 26 additions & 0 deletions members/views/UnacceptedInvitations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.utils import timezone
from django.db.models import OuterRef, Exists

from members.models.activityinvite import ActivityInvite
from members.models.activityparticipant import ActivityParticipant


def get_unaccepted_invitations_for_family(family_id):
participant_subquery = ActivityParticipant.objects.filter(
person__family_id=family_id,
person_id=OuterRef("person_id"),
activity_id=OuterRef("activity_id"),
)

# Get invitations where the participant record does not exist
unaccepted_invitations = (
ActivityInvite.objects.filter(
person__family_id=family_id,
expire_dtm__gte=timezone.now(),
rejected_at=None,
)
.annotate(is_participant=Exists(participant_subquery))
.filter(is_participant=False)
)

return unaccepted_invitations

0 comments on commit 3964b60

Please sign in to comment.