feat: test middleware; use zoneinfo; fix datetime warnings

This commit is contained in:
bkfox
2023-08-23 15:08:20 +02:00
parent 02a8bb7a4e
commit 43c2d552e4
11 changed files with 53 additions and 36 deletions

View File

@@ -39,8 +39,10 @@ class DiffusionQuerySet(RerunQuerySet):
def date(self, date=None, order=True):
"""Diffusions occuring date."""
date = date or datetime.date.today()
start = tz.datetime.combine(date, datetime.time())
end = tz.datetime.combine(date, datetime.time(23, 59, 59, 999))
start = tz.make_aware(tz.datetime.combine(date, datetime.time()))
end = tz.make_aware(
tz.datetime.combine(date, datetime.time(23, 59, 59, 999))
)
# start = tz.get_current_timezone().localize(start)
# end = tz.get_current_timezone().localize(end)
qs = self.filter(start__range=(start, end))

View File

@@ -1,6 +1,6 @@
import calendar
import zoneinfo
import pytz
from django.db import models
from django.utils import timezone as tz
from django.utils.functional import cached_property
@@ -49,9 +49,9 @@ class Schedule(Rerun):
)
timezone = models.CharField(
_("timezone"),
default=lambda: tz.get_current_timezone().zone,
default=lambda: tz.get_current_timezone().key,
max_length=100,
choices=[(x, x) for x in pytz.all_timezones],
choices=[(x, x) for x in zoneinfo.available_timezones()],
help_text=_("timezone used for the date"),
)
duration = models.TimeField(
@@ -82,9 +82,7 @@ class Schedule(Rerun):
@cached_property
def tz(self):
"""Pytz timezone of the schedule."""
import pytz
return pytz.timezone(self.timezone)
return zoneinfo.ZoneInfo(self.timezone)
@cached_property
def start(self):
@@ -110,7 +108,7 @@ class Schedule(Rerun):
"""Return a datetime set to schedule's time for the provided date,
handling timezone (based on schedule's timezone)."""
date = tz.datetime.combine(date, self.time)
return self.tz.normalize(self.tz.localize(date))
return date.replace(tzinfo=self.tz)
def dates_of_month(self, date):
"""Return normalized diffusion dates of provided date's month."""

View File

@@ -60,7 +60,7 @@ class Station(models.Model):
max_length=512,
null=True,
blank=True,
help_text=_("specify one url per line"),
help_text=_("specify one domain per line, without 'http://' prefix"),
)
audio_streams = models.TextField(
_("audio streams"),