Skip to content

Commit

Permalink
Merge pull request #1122 from CodingPirates/857-bug-notifikationer-gå…
Browse files Browse the repository at this point in the history
…r-ikke-væk-når-man-tilmelder-barn-til-aktiviteten

Notifikation om invitationer: Vis ikke hvis man deltager i aktivitet
  • Loading branch information
rasmusselsmark authored Oct 27, 2024
2 parents a365cec + 611e6a0 commit 7e6802f
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 7e6802f

Please sign in to comment.