From c328c1457c93fa693c855a620021ec4eb28158bf Mon Sep 17 00:00:00 2001 From: bleizi Date: Mon, 28 Aug 2023 22:27:45 +0200 Subject: [PATCH] add register button at the end of WEI registration --- apps/wei/views.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/apps/wei/views.py b/apps/wei/views.py index 7c8f3664..dd7b3fa1 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -1084,7 +1084,44 @@ class WEISurveyEndView(LoginRequiredMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context["club"] = WEIRegistration.objects.get(pk=self.kwargs["pk"]).wei + club = WEIRegistration.objects.get(pk=self.kwargs["pk"]).wei + context["club"] = club + + random_user = User.objects.filter(~Q(wei__wei__in=[club])).first() + + if random_user is None: + # This case occurs when all users are registered to the WEI. + # Don't worry, Pikachu never went to the WEI. + # This bug can arrive only in dev mode. + context["can_add_first_year_member"] = True + context["can_add_any_member"] = True + else: + # Check if the user has the right to create a registration of a random first year member. + empty_fy_registration = WEIRegistration( + wei=club, + user=random_user, + first_year=True, + birth_date="1970-01-01", + gender="No", + emergency_contact_name="No", + emergency_contact_phone="No", + ) + context["can_add_first_year_member"] = PermissionBackend \ + .check_perm(self.request, "wei.add_weiregistration", empty_fy_registration) + + # Check if the user has the right to create a registration of a random old member. + empty_old_registration = WEIRegistration( + wei=club, + user=User.objects.filter(~Q(wei__wei__in=[club])).first(), + first_year=False, + birth_date="1970-01-01", + gender="No", + emergency_contact_name="No", + emergency_contact_phone="No", + ) + context["can_add_any_member"] = PermissionBackend \ + .check_perm(self.request, "wei.add_weiregistration", empty_old_registration) + return context