Feat: packaging (#127)

- Add configuration files for packaging
- Precommit now uses ruff

Co-authored-by: bkfox <thomas bkfox net>
Reviewed-on: rc/aircox#127
This commit is contained in:
Thomas Kairos
2023-10-11 10:58:34 +02:00
parent 5ea092dba6
commit f7a61fe6c0
82 changed files with 332 additions and 935 deletions

View File

@ -19,11 +19,7 @@ __all__ = ("Diffusion", "DiffusionQuerySet")
class DiffusionQuerySet(RerunQuerySet):
def episode(self, episode=None, id=None):
"""Diffusions for this episode."""
return (
self.filter(episode=episode)
if id is None
else self.filter(episode__id=id)
)
return self.filter(episode=episode) if id is None else self.filter(episode__id=id)
def on_air(self):
"""On air diffusions."""
@ -40,9 +36,7 @@ class DiffusionQuerySet(RerunQuerySet):
"""Diffusions occuring date."""
date = date or datetime.date.today()
start = tz.make_aware(tz.datetime.combine(date, datetime.time()))
end = tz.make_aware(
tz.datetime.combine(date, datetime.time(23, 59, 59, 999))
)
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))
@ -50,11 +44,7 @@ class DiffusionQuerySet(RerunQuerySet):
def at(self, date, order=True):
"""Return diffusions at specified date or datetime."""
return (
self.now(date, order)
if isinstance(date, tz.datetime)
else self.date(date, order)
)
return self.now(date, order) if isinstance(date, tz.datetime) else self.date(date, order)
def after(self, date=None):
"""Return a queryset of diffusions that happen after the given date
@ -142,9 +132,7 @@ class Diffusion(Rerun):
class Meta:
verbose_name = _("Diffusion")
verbose_name_plural = _("Diffusions")
permissions = (
("programming", _("edit the diffusions' planification")),
)
permissions = (("programming", _("edit the diffusions' planification")),)
def __str__(self):
str_ = "{episode} - {date}".format(
@ -202,19 +190,12 @@ class Diffusion(Rerun):
def is_now(self):
"""True if diffusion is currently running."""
now = tz.now()
return (
self.type == self.TYPE_ON_AIR
and self.start <= now
and self.end >= now
)
return self.type == self.TYPE_ON_AIR and self.start <= now and self.end >= now
@property
def is_live(self):
"""True if Diffusion is live (False if there are sounds files)."""
return (
self.type == self.TYPE_ON_AIR
and not self.episode.sound_set.archive().count()
)
return self.type == self.TYPE_ON_AIR and not self.episode.sound_set.archive().count()
def get_playlist(self, **types):
"""Returns sounds as a playlist (list of *local* archive file path).
@ -224,9 +205,7 @@ class Diffusion(Rerun):
from .sound import Sound
return list(
self.get_sounds(**types)
.filter(path__isnull=False, type=Sound.TYPE_ARCHIVE)
.values_list("path", flat=True)
self.get_sounds(**types).filter(path__isnull=False, type=Sound.TYPE_ARCHIVE).values_list("path", flat=True)
)
def get_sounds(self, **types):
@ -238,9 +217,7 @@ class Diffusion(Rerun):
from .sound import Sound
sounds = (self.initial or self).sound_set.order_by("type", "path")
_in = [
getattr(Sound.Type, name) for name, value in types.items() if value
]
_in = [getattr(Sound.Type, name) for name, value in types.items() if value]
return sounds.filter(type__in=_in)
@ -262,8 +239,7 @@ class Diffusion(Rerun):
# .filter(conflict_with=True)
return (
Diffusion.objects.filter(
Q(start__lt=self.start, end__gt=self.start)
| Q(start__gt=self.start, start__lt=self.end)
Q(start__lt=self.start, end__gt=self.start) | Q(start__gt=self.start, start__lt=self.end)
)
.exclude(pk=self.pk)
.distinct()