mirror of https://gitlab.crans.org/bde/nk20
Fix memberships with clubs without memberships (we always need treasurers...)
This commit is contained in:
parent
535c493bc7
commit
92ab5ee3af
|
@ -128,6 +128,9 @@ class Club(models.Model):
|
|||
This function is called each time the club detail view is displayed.
|
||||
Update the year of the membership dates.
|
||||
"""
|
||||
if not self.membership_start:
|
||||
return
|
||||
|
||||
today = datetime.date.today()
|
||||
|
||||
if (today - self.membership_start).days >= 365:
|
||||
|
@ -237,7 +240,7 @@ class Membership(models.Model):
|
|||
if self.club.membership_duration is not None:
|
||||
self.date_end = self.date_start + datetime.timedelta(days=self.club.membership_duration)
|
||||
else:
|
||||
self.date_end = self.date_start + datetime.timedelta(days=0x7FFFFFFF)
|
||||
self.date_end = self.date_start + datetime.timedelta(days=424242)
|
||||
if self.club.membership_end is not None and self.date_end > self.club.membership_end:
|
||||
self.date_end = self.club.membership_end
|
||||
|
||||
|
|
|
@ -374,12 +374,12 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
|
|||
form.add_error('user', _('User is already a member of the club'))
|
||||
return super().form_invalid(form)
|
||||
|
||||
if form.instance.date_start < form.instance.club.membership_start:
|
||||
if form.instance.club.membership_start and form.instance.date_start < form.instance.club.membership_start:
|
||||
form.add_error('user', _("The membership must start after {:%m-%d-%Y}.")
|
||||
.format(form.instance.club.membership_start))
|
||||
return super().form_invalid(form)
|
||||
|
||||
if form.instance.date_start > form.instance.club.membership_end:
|
||||
if form.instance.club.membership_end and form.instance.date_start > form.instance.club.membership_end:
|
||||
form.add_error('user', _("The membership must begin before {:%m-%d-%Y}.")
|
||||
.format(form.instance.club.membership_start))
|
||||
return super().form_invalid(form)
|
||||
|
@ -406,12 +406,12 @@ class ClubManageRolesView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
|||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
if form.instance.date_start < form.instance.club.membership_start:
|
||||
if form.instance.club.membership_start and form.instance.date_start < form.instance.club.membership_start:
|
||||
form.add_error('user', _("The membership must start after {:%m-%d-%Y}.")
|
||||
.format(form.instance.club.membership_start))
|
||||
return super().form_invalid(form)
|
||||
|
||||
if form.instance.date_start > form.instance.club.membership_end:
|
||||
if form.instance.club.membership_end and form.instance.date_start > form.instance.club.membership_end:
|
||||
form.add_error('user', _("The membership must begin before {:%m-%d-%Y}.")
|
||||
.format(form.instance.club.membership_start))
|
||||
return super().form_invalid(form)
|
||||
|
|
Loading…
Reference in New Issue