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

@ -33,6 +33,7 @@ from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import connection
from django.utils import timezone
from django.utils.timezone import localdate
from PIL import Image
from accounting.models import (
@ -914,7 +915,7 @@ Welcome to the wiki page!
Membership(
user=comunity,
club=bar_club,
start_date=self.now,
start_date=localdate(),
role=settings.SITH_CLUB_ROLES_ID["Board member"],
).save()
# Adding user tutu
@ -1274,28 +1275,28 @@ Welcome to the wiki page!
club=troll,
role=9,
description="Padawan Troll",
start_date=self.now - timedelta(days=17),
start_date=localdate() - timedelta(days=17),
).save()
Membership(
user=krophil,
club=troll,
role=10,
description="Maitre Troll",
start_date=self.now - timedelta(days=200),
start_date=localdate() - timedelta(days=200),
).save()
Membership(
user=skia,
club=troll,
role=2,
description="Grand Ancien Troll",
start_date=self.now - timedelta(days=400),
end_date=self.now - timedelta(days=86),
start_date=localdate() - timedelta(days=400),
end_date=localdate() - timedelta(days=86),
).save()
Membership(
user=richard,
club=troll,
role=2,
description="",
start_date=self.now - timedelta(days=200),
end_date=self.now - timedelta(days=100),
start_date=localdate() - timedelta(days=200),
end_date=localdate() - timedelta(days=100),
).save()

View File

@ -9,7 +9,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from django.db.models import Count, Exists, F, Min, OuterRef, Subquery, Sum
from django.db.models.functions import Coalesce
from django.utils.timezone import make_aware, now
from django.utils.timezone import localdate, make_aware, now
from faker import Faker
from club.models import Club, Membership
@ -125,7 +125,7 @@ class Command(BaseCommand):
account_id=f"{9900 + i}{self.faker.random_lowercase_letter()}",
)
)
while sub.subscription_end < now().date() and random.random() > 0.7:
while sub.subscription_end < localdate() and random.random() > 0.7:
# 70% chances to subscribe again
# (expect if it would make the subscription start after tomorrow)
sub = prepare_subscription(
@ -331,7 +331,7 @@ class Command(BaseCommand):
seller=random.choice(sellers),
customer=customer,
date=make_aware(
self.faker.date_time_between(customer.since, now().date())
self.faker.date_time_between(customer.since, localdate())
),
)
)
@ -347,7 +347,7 @@ class Command(BaseCommand):
operator=random.choice(sellers),
customer=customer,
date=make_aware(
self.faker.date_time_between(customer.since, now().date())
self.faker.date_time_between(customer.since, localdate())
),
is_validated=True,
)
@ -368,7 +368,7 @@ class Command(BaseCommand):
active_period_start = self.faker.past_date("-10y")
active_period_end = self.faker.date_between(
active_period_start,
min(now().date(), active_period_start + relativedelta(years=5)),
min(localdate(), active_period_start + relativedelta(years=5)),
)
for _ in range(nb_perms):
counter = (

View File

@ -23,7 +23,7 @@ import PIL
from django.conf import settings
from django.core.files.base import ContentFile
from django.http import HttpRequest
from django.utils import timezone
from django.utils.timezone import localdate
from PIL import ExifTags
from PIL.Image import Image, Resampling
@ -45,7 +45,7 @@ def get_start_of_semester(today: Optional[date] = None) -> date:
the date of the start of the semester
"""
if today is None:
today = timezone.now().date()
today = localdate()
autumn = date(today.year, *settings.SITH_SEMESTER_START_AUTUMN)
spring = date(today.year, *settings.SITH_SEMESTER_START_SPRING)
@ -73,7 +73,7 @@ def get_semester_code(d: Optional[date] = None) -> str:
the semester code corresponding to the given date
"""
if d is None:
d = timezone.now().date()
d = localdate()
start = get_start_of_semester(d)