1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-20 17:41:55 +02:00

🐛 WEI members must be members of the Kfet club *this year*

This commit is contained in:
Yohann D'ANELLO
2020-08-03 23:55:01 +02:00
parent ba067f050e
commit 20ce817b16
5 changed files with 89 additions and 106 deletions

View File

@ -531,7 +531,12 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
return super().form_invalid(form)
if club.parent_club is not None:
if not Membership.objects.filter(user=form.instance.user, club=club.parent_club).exists():
if not Membership.objects.filter(
user=form.instance.user,
club=club.parent_club,
date_start__lte=form.instance.date_start,
date_end__gte=form.instance.date_start,
).exists():
form.add_error('user', _('User is not a member of the parent club') + ' ' + club.parent_club.name)
return super().form_invalid(form)

View File

@ -728,8 +728,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
context["kfet_member"] = Membership.objects.filter(
club__name="Kfet",
user=registration.user,
date_start__lte=datetime.now().date(),
date_end__gte=datetime.now().date(),
date_start__gte=registration.wei.parent_club.membership_start,
).exists()
return context
@ -788,9 +787,15 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
form.add_error('bus', _("This user didn't give her/his caution check."))
return super().form_invalid(form)
if club.parent_club is not None:
if not Membership.objects.filter(user=form.instance.user, club=club.parent_club).exists():
form.add_error('user', _('User is not a member of the parent club') + ' ' + club.parent_club.name)
if club.parent_club is not None: # parent_club is never None: this is Kfet.
# We want that the user is member of the Kfet club *of this year*: the Kfet membership is included
# in the WEI registration.
if not Membership.objects.filter(
user=form.instance.user,
club=club.parent_club, # Kfet
date_start__gte=club.parent_club.membership_start,
).exists():
form.add_error('bus', _('User is not a member of the parent club') + ' ' + club.parent_club.name)
return super().form_invalid(form)
# Now, all is fine, the membership can be created.