fix sounds_monitor; fix django compatibility (v3.2)

This commit is contained in:
bkfox 2022-01-09 15:14:00 +01:00
parent c08e93d91f
commit 9efe19e052
7 changed files with 27 additions and 22 deletions

View File

@ -1,2 +1 @@
default_app_config = 'aircox.apps.AircoxConfig'

View File

@ -85,17 +85,20 @@ class SoundFile:
if created or sound.check_on_file():
logger.info('sound is new or have been modified -> %s', self.path)
self.read_path()
self.read_file_info()
sound.duration = utils.seconds_to_time(self.info.info.length)
sound.name = self.path_info.get('name')
self.read_file_info()
if self.info is not None:
sound.duration = utils.seconds_to_time(self.info.info.length)
# check for episode
if sound.episode is None and self.read_path():
self.find_episode(program)
self.sound = sound
sound.save()
self.find_playlist(sound)
if self.info is not None:
self.find_playlist(sound)
return sound
def read_path(self):
@ -117,7 +120,10 @@ class SoundFile:
def read_file_info(self):
""" Read file information and metadata. """
self.info = mutagen.File(self.path)
if os.path.exists(self.path):
self.info = mutagen.File(self.path)
else:
self.info = None
def find_episode(self, program):
"""
@ -285,17 +291,14 @@ class Command(BaseCommand):
# sounds in db & unchecked
sounds = Sound.objects.filter(path__startswith=subdir). \
exclude(pk__in=sounds)
self.check_sounds(sounds)
self.check_sounds(sounds, program=program)
@staticmethod
def check_sounds(qs):
"""
Only check for the sound existence or update
"""
def check_sounds(self, qs, **sync_kwargs):
""" Only check for the sound existence or update """
# check files
for sound in qs:
if sound.check_on_file():
sound.sync(sound=sound)
SoundFile(sound.path).sync(sound=sound, **sync_kwargs)
def monitor(self):
""" Run in monitor mode """

View File

@ -171,8 +171,8 @@ class Diffusion(BaseRerun):
type = models.SmallIntegerField(
verbose_name=_('type'), default=TYPE_ON_AIR, choices=TYPE_CHOICES,
)
start = models.DateTimeField(_('start'))
end = models.DateTimeField(_('end'))
start = models.DateTimeField(_('start'), db_index=True)
end = models.DateTimeField(_('end'), db_index=True)
# port = models.ForeignKey(
# 'self',
# verbose_name = _('port'),

View File

@ -66,9 +66,10 @@ class BasePage(models.Model):
)
parent = models.ForeignKey('self', models.CASCADE, blank=True, null=True,
related_name='child_set')
db_index=True, related_name='child_set')
title = models.CharField(max_length=100)
slug = models.SlugField(_('slug'), max_length=120, blank=True, unique=True)
slug = models.SlugField(_('slug'), max_length=120, blank=True, unique=True,
db_index=True)
status = models.PositiveSmallIntegerField(
_('status'), default=STATUS_DRAFT, choices=STATUS_CHOICES,
)
@ -214,6 +215,7 @@ class StaticPage(BasePage):
class Comment(models.Model):
page = models.ForeignKey(
Page, models.CASCADE, verbose_name=_('related page'),
db_index=True,
# TODO: allow_comment filter
)
nickname = models.CharField(_('nickname'), max_length=32)
@ -234,7 +236,7 @@ class NavItem(models.Model):
order = models.PositiveSmallIntegerField(_('order'))
text = models.CharField(_('title'), max_length=64)
url = models.CharField(_('url'), max_length=256, blank=True, null=True)
page = models.ForeignKey(StaticPage, models.CASCADE,
page = models.ForeignKey(StaticPage, models.CASCADE, db_index=True,
verbose_name=_('page'), blank=True, null=True)
class Meta:
verbose_name = _('Menu item')

View File

@ -169,14 +169,14 @@ class BaseRerun(models.Model):
datetime field or attribute implemented by subclass.
"""
program = models.ForeignKey(
Program, models.CASCADE,
Program, models.CASCADE, db_index=True,
verbose_name=_('related program'),
)
initial = models.ForeignKey(
'self', models.SET_NULL, related_name='rerun_set',
verbose_name=_('rerun of'),
limit_choices_to={'initial__isnull': True},
blank=True, null=True,
blank=True, null=True, db_index=True,
)
objects = BaseRerunQuerySet.as_manager()

View File

@ -83,10 +83,12 @@ class Sound(models.Model):
Program, models.CASCADE, blank=True, # NOT NULL
verbose_name=_('program'),
help_text=_('program related to it'),
db_index=True,
)
episode = models.ForeignKey(
Episode, models.SET_NULL, blank=True, null=True,
verbose_name=_('episode'),
db_index=True,
)
type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)
position = models.PositiveSmallIntegerField(
@ -173,7 +175,6 @@ class Sound(models.Model):
return
logger.info('sound %s: has been removed', self.path)
self.type = self.TYPE_REMOVED
return True
# not anymore removed

View File

@ -170,9 +170,9 @@ THUMBNAIL_PROCESSORS = (
# Enabled applications
INSTALLED_APPS = (
'aircox',
'aircox.apps.AircoxConfig',
'aircox.apps.AircoxAdminConfig',
'aircox_streamer',
'aircox_streamer.apps.AircoxStreamerConfig',
# Aircox dependencies
'rest_framework',