From 92ab5ee3af0633f70f52c0212052a9f41d50a978 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 1 Apr 2020 04:34:42 +0200 Subject: [PATCH] Fix memberships with clubs without memberships (we always need treasurers...) --- apps/member/models.py | 5 ++++- apps/member/views.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/member/models.py b/apps/member/models.py index be4fe7e9..c2f27473 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -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 diff --git a/apps/member/views.py b/apps/member/views.py index 226cafab..243ff265 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -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)