Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifikation om invitationer: Vis ikke hvis man deltager i aktivitet #1122

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading