fix localdate issues

This commit is contained in:
thomas girod
2024-10-03 00:21:16 +02:00
committed by Bartuccio Antoine
parent 271d57051e
commit 0eaa20e09d
9 changed files with 31 additions and 27 deletions

View File

@ -35,6 +35,7 @@ from django.db.models import Q
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.timezone import localdate
from django.utils.translation import gettext_lazy as _
from core.models import Group, MetaGroup, Notification, Page, RealGroup, SithFile, User
@ -269,7 +270,7 @@ class Club(models.Model):
class MembershipQuerySet(models.QuerySet):
def ongoing(self) -> Self:
"""Filter all memberships which are not finished yet."""
return self.filter(Q(end_date=None) | Q(end_date__gt=timezone.now().date()))
return self.filter(Q(end_date=None) | Q(end_date__gt=localdate()))
def board(self) -> Self:
"""Filter all memberships where the user is/was in the board.

View File

@ -19,7 +19,7 @@ from django.core.cache import cache
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
from django.utils.timezone import localtime, now
from django.utils.timezone import localdate, localtime, now
from django.utils.translation import gettext as _
from club.forms import MailingForm
@ -109,7 +109,7 @@ class TestMembershipQuerySet(TestClub):
def test_ongoing_with_membership_ending_today(self):
"""Test that a membership ending the present day is considered as ended."""
today = timezone.now().date()
today = localdate()
self.richard.memberships.filter(club=self.club).update(end_date=today)
current_members = list(self.club.members.ongoing().order_by("id"))
expected = [