forked from rc/aircox
!112 Co-authored-by: bkfox <thomas bkfox net> Reviewed-on: rc/aircox#113
This commit is contained in:
@ -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))
|
||||
|
@ -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."""
|
||||
|
@ -53,8 +53,10 @@ def page_post_save(sender, instance, created, *args, **kwargs):
|
||||
def program_post_save(sender, instance, created, *args, **kwargs):
|
||||
"""Clean-up later diffusions when a program becomes inactive."""
|
||||
if not instance.active:
|
||||
Diffusion.object.program(instance).after(tz.now()).delete()
|
||||
Episode.object.parent(instance).filter(diffusion__isnull=True).delete()
|
||||
Diffusion.objects.program(instance).after(tz.now()).delete()
|
||||
Episode.objects.parent(instance).filter(
|
||||
diffusion__isnull=True
|
||||
).delete()
|
||||
|
||||
cover = getattr(instance, "__initial_cover", None)
|
||||
if cover is None and instance.cover is not None:
|
||||
|
@ -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"),
|
||||
|
Reference in New Issue
Block a user