From de5e0c958e06fc98950591a831b7dd64c09868b7 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 6 Aug 2020 14:11:55 +0200 Subject: [PATCH] Fix some activity errors --- apps/activity/forms.py | 6 ++++-- apps/activity/models.py | 4 ++-- apps/activity/views.py | 2 +- apps/member/views.py | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/activity/forms.py b/apps/activity/forms.py index dced014a..c41769a9 100644 --- a/apps/activity/forms.py +++ b/apps/activity/forms.py @@ -1,9 +1,11 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from datetime import timedelta, datetime + +from datetime import timedelta from django import forms from django.contrib.contenttypes.models import ContentType +from django.utils import timezone from django.utils.translation import gettext_lazy as _ from member.models import Club from note.models import NoteUser, Note @@ -41,7 +43,7 @@ class GuestForm(forms.ModelForm): def clean(self): cleaned_data = super().clean() - if self.activity.date_start > datetime.now(): + if self.activity.date_start > timezone.now(): self.add_error("inviter", _("You can't invite someone once the activity is started.")) if not self.activity.valid: diff --git a/apps/activity/models.py b/apps/activity/models.py index 3ad0aa29..c43e9258 100644 --- a/apps/activity/models.py +++ b/apps/activity/models.py @@ -1,7 +1,7 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from datetime import timedelta, datetime +from datetime import timedelta from threading import Thread from django.conf import settings @@ -236,7 +236,7 @@ class Guest(models.Model): one_year = timedelta(days=365) if not force_insert: - if self.activity.date_start > datetime.now(): + if self.activity.date_start > timezone.now(): raise ValidationError(_("You can't invite someone once the activity is started.")) if not self.activity.valid: diff --git a/apps/activity/views.py b/apps/activity/views.py index 370e6040..25565f2c 100644 --- a/apps/activity/views.py +++ b/apps/activity/views.py @@ -125,7 +125,7 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView): .filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view"))\ .order_by('last_name', 'first_name').distinct() - if "search" in self.request.GET: + if "search" in self.request.GET and self.request.GET["search"]: pattern = self.request.GET["search"] if pattern[0] != "^": pattern = "^" + pattern diff --git a/apps/member/views.py b/apps/member/views.py index 46f56816..73fb4d90 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -484,7 +484,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): additional_fee_renewal = 0 while c.parent_club is not None: c = c.parent_club - if not Membership.objects.filter( + if c.membership_start and not Membership.objects.filter( club=c, user=user, date_start__gte=c.membership_start, @@ -562,7 +562,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): fee = 0 c = club - while c is not None: + while c is not None and c.membership_start: if not Membership.objects.filter( club=c, user=user,