From 9efe19e052494bb17e99256f13e1aafb2fd0a788 Mon Sep 17 00:00:00 2001 From: bkfox Date: Sun, 9 Jan 2022 15:14:00 +0100 Subject: [PATCH] fix sounds_monitor; fix django compatibility (v3.2) --- aircox/__init__.py | 1 - aircox/management/commands/sounds_monitor.py | 25 +++++++++++--------- aircox/models/episode.py | 4 ++-- aircox/models/page.py | 8 ++++--- aircox/models/program.py | 4 ++-- aircox/models/sound.py | 3 ++- instance/sample_settings.py | 4 ++-- 7 files changed, 27 insertions(+), 22 deletions(-) diff --git a/aircox/__init__.py b/aircox/__init__.py index 0b70342..8b13789 100755 --- a/aircox/__init__.py +++ b/aircox/__init__.py @@ -1,2 +1 @@ -default_app_config = 'aircox.apps.AircoxConfig' diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index 42c6d8f..757aeb5 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -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 """ diff --git a/aircox/models/episode.py b/aircox/models/episode.py index 8c45812..5749447 100644 --- a/aircox/models/episode.py +++ b/aircox/models/episode.py @@ -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'), diff --git a/aircox/models/page.py b/aircox/models/page.py index 71df901..19b4a82 100644 --- a/aircox/models/page.py +++ b/aircox/models/page.py @@ -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') diff --git a/aircox/models/program.py b/aircox/models/program.py index 4a739e3..0931c3a 100644 --- a/aircox/models/program.py +++ b/aircox/models/program.py @@ -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() diff --git a/aircox/models/sound.py b/aircox/models/sound.py index 8747273..9246b93 100644 --- a/aircox/models/sound.py +++ b/aircox/models/sound.py @@ -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 diff --git a/instance/sample_settings.py b/instance/sample_settings.py index 1141b39..13d2fc9 100755 --- a/instance/sample_settings.py +++ b/instance/sample_settings.py @@ -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',