fix sounds_monitor; fix django compatibility (v3.2)
This commit is contained in:
		@ -1,2 +1 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
default_app_config = 'aircox.apps.AircoxConfig'
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -85,17 +85,20 @@ class SoundFile:
 | 
				
			|||||||
        if created or sound.check_on_file():
 | 
					        if created or sound.check_on_file():
 | 
				
			||||||
            logger.info('sound is new or have been modified -> %s', self.path)
 | 
					            logger.info('sound is new or have been modified -> %s', self.path)
 | 
				
			||||||
            self.read_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')
 | 
					            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
 | 
					        # check for episode
 | 
				
			||||||
        if sound.episode is None and self.read_path():
 | 
					        if sound.episode is None and self.read_path():
 | 
				
			||||||
            self.find_episode(program)
 | 
					            self.find_episode(program)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.sound = sound
 | 
					        self.sound = sound
 | 
				
			||||||
        sound.save()
 | 
					        sound.save()
 | 
				
			||||||
        self.find_playlist(sound)
 | 
					        if self.info is not None:
 | 
				
			||||||
 | 
					            self.find_playlist(sound)
 | 
				
			||||||
        return sound
 | 
					        return sound
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def read_path(self):
 | 
					    def read_path(self):
 | 
				
			||||||
@ -117,7 +120,10 @@ class SoundFile:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def read_file_info(self):
 | 
					    def read_file_info(self):
 | 
				
			||||||
        """ Read file information and metadata. """
 | 
					        """ 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):
 | 
					    def find_episode(self, program):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@ -285,17 +291,14 @@ class Command(BaseCommand):
 | 
				
			|||||||
        # sounds in db & unchecked
 | 
					        # sounds in db & unchecked
 | 
				
			||||||
        sounds = Sound.objects.filter(path__startswith=subdir). \
 | 
					        sounds = Sound.objects.filter(path__startswith=subdir). \
 | 
				
			||||||
            exclude(pk__in=sounds)
 | 
					            exclude(pk__in=sounds)
 | 
				
			||||||
        self.check_sounds(sounds)
 | 
					        self.check_sounds(sounds, program=program)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    def check_sounds(self, qs, **sync_kwargs):
 | 
				
			||||||
    def check_sounds(qs):
 | 
					        """ Only check for the sound existence or update """
 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        Only check for the sound existence or update
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        # check files
 | 
					        # check files
 | 
				
			||||||
        for sound in qs:
 | 
					        for sound in qs:
 | 
				
			||||||
            if sound.check_on_file():
 | 
					            if sound.check_on_file():
 | 
				
			||||||
                sound.sync(sound=sound)
 | 
					                SoundFile(sound.path).sync(sound=sound, **sync_kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def monitor(self):
 | 
					    def monitor(self):
 | 
				
			||||||
        """ Run in monitor mode """
 | 
					        """ Run in monitor mode """
 | 
				
			||||||
 | 
				
			|||||||
@ -171,8 +171,8 @@ class Diffusion(BaseRerun):
 | 
				
			|||||||
    type = models.SmallIntegerField(
 | 
					    type = models.SmallIntegerField(
 | 
				
			||||||
        verbose_name=_('type'), default=TYPE_ON_AIR, choices=TYPE_CHOICES,
 | 
					        verbose_name=_('type'), default=TYPE_ON_AIR, choices=TYPE_CHOICES,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    start = models.DateTimeField(_('start'))
 | 
					    start = models.DateTimeField(_('start'), db_index=True)
 | 
				
			||||||
    end = models.DateTimeField(_('end'))
 | 
					    end = models.DateTimeField(_('end'), db_index=True)
 | 
				
			||||||
    # port = models.ForeignKey(
 | 
					    # port = models.ForeignKey(
 | 
				
			||||||
    #    'self',
 | 
					    #    'self',
 | 
				
			||||||
    #    verbose_name = _('port'),
 | 
					    #    verbose_name = _('port'),
 | 
				
			||||||
 | 
				
			|||||||
@ -66,9 +66,10 @@ class BasePage(models.Model):
 | 
				
			|||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    parent = models.ForeignKey('self', models.CASCADE, blank=True, null=True,
 | 
					    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)
 | 
					    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 = models.PositiveSmallIntegerField(
 | 
				
			||||||
        _('status'), default=STATUS_DRAFT, choices=STATUS_CHOICES,
 | 
					        _('status'), default=STATUS_DRAFT, choices=STATUS_CHOICES,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
@ -214,6 +215,7 @@ class StaticPage(BasePage):
 | 
				
			|||||||
class Comment(models.Model):
 | 
					class Comment(models.Model):
 | 
				
			||||||
    page = models.ForeignKey(
 | 
					    page = models.ForeignKey(
 | 
				
			||||||
        Page, models.CASCADE, verbose_name=_('related page'),
 | 
					        Page, models.CASCADE, verbose_name=_('related page'),
 | 
				
			||||||
 | 
					        db_index=True,
 | 
				
			||||||
        # TODO: allow_comment filter
 | 
					        # TODO: allow_comment filter
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    nickname = models.CharField(_('nickname'), max_length=32)
 | 
					    nickname = models.CharField(_('nickname'), max_length=32)
 | 
				
			||||||
@ -234,7 +236,7 @@ class NavItem(models.Model):
 | 
				
			|||||||
    order = models.PositiveSmallIntegerField(_('order'))
 | 
					    order = models.PositiveSmallIntegerField(_('order'))
 | 
				
			||||||
    text = models.CharField(_('title'), max_length=64)
 | 
					    text = models.CharField(_('title'), max_length=64)
 | 
				
			||||||
    url = models.CharField(_('url'), max_length=256, blank=True, null=True)
 | 
					    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)
 | 
					                             verbose_name=_('page'), blank=True, null=True)
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        verbose_name = _('Menu item')
 | 
					        verbose_name = _('Menu item')
 | 
				
			||||||
 | 
				
			|||||||
@ -169,14 +169,14 @@ class BaseRerun(models.Model):
 | 
				
			|||||||
    datetime field or attribute implemented by subclass.
 | 
					    datetime field or attribute implemented by subclass.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    program = models.ForeignKey(
 | 
					    program = models.ForeignKey(
 | 
				
			||||||
        Program, models.CASCADE,
 | 
					        Program, models.CASCADE, db_index=True,
 | 
				
			||||||
        verbose_name=_('related program'),
 | 
					        verbose_name=_('related program'),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    initial = models.ForeignKey(
 | 
					    initial = models.ForeignKey(
 | 
				
			||||||
        'self', models.SET_NULL, related_name='rerun_set',
 | 
					        'self', models.SET_NULL, related_name='rerun_set',
 | 
				
			||||||
        verbose_name=_('rerun of'),
 | 
					        verbose_name=_('rerun of'),
 | 
				
			||||||
        limit_choices_to={'initial__isnull': True},
 | 
					        limit_choices_to={'initial__isnull': True},
 | 
				
			||||||
        blank=True, null=True,
 | 
					        blank=True, null=True, db_index=True,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    objects = BaseRerunQuerySet.as_manager()
 | 
					    objects = BaseRerunQuerySet.as_manager()
 | 
				
			||||||
 | 
				
			|||||||
@ -83,10 +83,12 @@ class Sound(models.Model):
 | 
				
			|||||||
        Program, models.CASCADE, blank=True, # NOT NULL
 | 
					        Program, models.CASCADE, blank=True, # NOT NULL
 | 
				
			||||||
        verbose_name=_('program'),
 | 
					        verbose_name=_('program'),
 | 
				
			||||||
        help_text=_('program related to it'),
 | 
					        help_text=_('program related to it'),
 | 
				
			||||||
 | 
					        db_index=True,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    episode = models.ForeignKey(
 | 
					    episode = models.ForeignKey(
 | 
				
			||||||
        Episode, models.SET_NULL, blank=True, null=True,
 | 
					        Episode, models.SET_NULL, blank=True, null=True,
 | 
				
			||||||
        verbose_name=_('episode'),
 | 
					        verbose_name=_('episode'),
 | 
				
			||||||
 | 
					        db_index=True,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)
 | 
					    type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)
 | 
				
			||||||
    position = models.PositiveSmallIntegerField(
 | 
					    position = models.PositiveSmallIntegerField(
 | 
				
			||||||
@ -173,7 +175,6 @@ class Sound(models.Model):
 | 
				
			|||||||
                return
 | 
					                return
 | 
				
			||||||
            logger.info('sound %s: has been removed', self.path)
 | 
					            logger.info('sound %s: has been removed', self.path)
 | 
				
			||||||
            self.type = self.TYPE_REMOVED
 | 
					            self.type = self.TYPE_REMOVED
 | 
				
			||||||
 | 
					 | 
				
			||||||
            return True
 | 
					            return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # not anymore removed
 | 
					        # not anymore removed
 | 
				
			||||||
 | 
				
			|||||||
@ -170,9 +170,9 @@ THUMBNAIL_PROCESSORS = (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Enabled applications
 | 
					# Enabled applications
 | 
				
			||||||
INSTALLED_APPS = (
 | 
					INSTALLED_APPS = (
 | 
				
			||||||
    'aircox',
 | 
					    'aircox.apps.AircoxConfig',
 | 
				
			||||||
    'aircox.apps.AircoxAdminConfig',
 | 
					    'aircox.apps.AircoxAdminConfig',
 | 
				
			||||||
    'aircox_streamer',
 | 
					    'aircox_streamer.apps.AircoxStreamerConfig',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Aircox dependencies
 | 
					    # Aircox dependencies
 | 
				
			||||||
    'rest_framework',
 | 
					    'rest_framework',
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user