small fixes and tests
This commit is contained in:
@ -80,7 +80,13 @@ class EpisodeAdmin (NameableAdmin):
|
|||||||
|
|
||||||
@admin.register(Diffusion)
|
@admin.register(Diffusion)
|
||||||
class DiffusionAdmin (admin.ModelAdmin):
|
class DiffusionAdmin (admin.ModelAdmin):
|
||||||
list_display = ('id', 'type', 'date', 'episode', 'program', 'stream')
|
def archives (self, obj):
|
||||||
|
sounds = obj.episode and \
|
||||||
|
(os.path.basename(sound.path) for sound in obj.episode.sounds.all()
|
||||||
|
if sound.type == Sound.Type['archive'] )
|
||||||
|
return ', '.join(sounds) if sounds else ''
|
||||||
|
|
||||||
|
list_display = ('id', 'type', 'date', 'archives', 'episode', 'program', 'stream')
|
||||||
list_filter = ('type', 'date', 'program', 'stream')
|
list_filter = ('type', 'date', 'program', 'stream')
|
||||||
list_editable = ('type', 'date')
|
list_editable = ('type', 'date')
|
||||||
|
|
||||||
|
@ -65,31 +65,32 @@ class Command (BaseCommand):
|
|||||||
|
|
||||||
def add_arguments (self, parser):
|
def add_arguments (self, parser):
|
||||||
parser.formatter_class=RawTextHelpFormatter
|
parser.formatter_class=RawTextHelpFormatter
|
||||||
|
|
||||||
now = tz.datetime.today()
|
now = tz.datetime.today()
|
||||||
|
|
||||||
group = parser.add_argument_group('action')
|
group = parser.add_argument_group('action')
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
'--update', action='store_true',
|
'--update', action='store_true',
|
||||||
help = 'generate (unconfirmed) diffusions for the given month. '
|
help='generate (unconfirmed) diffusions for the given month. '
|
||||||
'These diffusions must be confirmed manually by changing '
|
'These diffusions must be confirmed manually by changing '
|
||||||
'their type to "normal"')
|
'their type to "normal"')
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
'--clean', action='store_true',
|
'--clean', action='store_true',
|
||||||
help = 'remove unconfirmed diffusions older than the given month')
|
help='remove unconfirmed diffusions older than the given month')
|
||||||
|
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
'--check', action='store_true',
|
'--check', action='store_true',
|
||||||
help = 'check future unconfirmed diffusions from the given date '
|
help='check future unconfirmed diffusions from the given date '
|
||||||
'agains\'t schedules and remove it if that do not match any '
|
'agains\'t schedules and remove it if that do not match any '
|
||||||
'schedule')
|
'schedule')
|
||||||
|
|
||||||
group = parser.add_argument_group(
|
group = parser.add_argument_group(
|
||||||
'date')
|
'date')
|
||||||
group.add_argument('--year', type=int, default=now.year,
|
group.add_argument(
|
||||||
help='used by update, default is today\'s year')
|
'--year', type=int, default=now.year,
|
||||||
group.add_argument('--month', type=int, default=now.month,
|
help='used by update, default is today\'s year')
|
||||||
help='used by update, default is today\'s month')
|
group.add_argument(
|
||||||
|
'--month', type=int, default=now.month,
|
||||||
|
help='used by update, default is today\'s month')
|
||||||
|
|
||||||
def handle (self, *args, **options):
|
def handle (self, *args, **options):
|
||||||
date = tz.datetime(year = options.get('year'),
|
date = tz.datetime(year = options.get('year'),
|
||||||
|
@ -48,7 +48,8 @@ class Command (BaseCommand):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s', '--scan', action='store_true',
|
'-s', '--scan', action='store_true',
|
||||||
help='Scan programs directories for changes'
|
help='Scan programs directories for changes, plus check for a '
|
||||||
|
' matching episode on sounds that have not been yet assigned'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ class Command (BaseCommand):
|
|||||||
self.report(program, path, 'no diffusion found for the given date')
|
self.report(program, path, 'no diffusion found for the given date')
|
||||||
return
|
return
|
||||||
diffusion = diffusion[0]
|
diffusion = diffusion[0]
|
||||||
|
print(diffusion, sound_info)
|
||||||
return diffusion.episode or None
|
return diffusion.episode or None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -163,7 +165,7 @@ class Command (BaseCommand):
|
|||||||
episode.sounds.add(sound)
|
episode.sounds.add(sound)
|
||||||
episode.save()
|
episode.save()
|
||||||
|
|
||||||
self.check_sounds(Sound.objects.filter(path__startswith == subdir))
|
self.check_sounds(Sound.objects.filter(path__startswith = subdir))
|
||||||
|
|
||||||
def check_quality (self, check = False):
|
def check_quality (self, check = False):
|
||||||
"""
|
"""
|
||||||
@ -179,7 +181,6 @@ class Command (BaseCommand):
|
|||||||
else:
|
else:
|
||||||
files = [ sound.path for sound in sounds.filter(removed = False) ]
|
files = [ sound.path for sound in sounds.filter(removed = False) ]
|
||||||
|
|
||||||
|
|
||||||
print('start quality check...')
|
print('start quality check...')
|
||||||
cmd = quality_check.Command()
|
cmd = quality_check.Command()
|
||||||
cmd.handle( files = files,
|
cmd.handle( files = files,
|
||||||
|
@ -34,8 +34,8 @@ class Nameable (models.Model):
|
|||||||
return slugify(self.name)
|
return slugify(self.name)
|
||||||
|
|
||||||
def __str__ (self):
|
def __str__ (self):
|
||||||
if self.pk:
|
#if self.pk:
|
||||||
return '#{} {}'.format(self.pk, self.name)
|
# return '#{} {}'.format(self.pk, self.name)
|
||||||
return '{}'.format(self.name)
|
return '{}'.format(self.name)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -391,7 +391,7 @@ class Diffusion (models.Model):
|
|||||||
verbose_name_plural = _('Diffusions')
|
verbose_name_plural = _('Diffusions')
|
||||||
|
|
||||||
|
|
||||||
class Stream (models.Model):
|
class Stream (Nameable):
|
||||||
Type = {
|
Type = {
|
||||||
'random': 0x00, # selection using random function
|
'random': 0x00, # selection using random function
|
||||||
'schedule': 0x01, # selection using schedule
|
'schedule': 0x01, # selection using schedule
|
||||||
@ -399,11 +399,6 @@ class Stream (models.Model):
|
|||||||
for key, value in Type.items():
|
for key, value in Type.items():
|
||||||
ugettext_lazy(key)
|
ugettext_lazy(key)
|
||||||
|
|
||||||
name = models.CharField(
|
|
||||||
_('name'),
|
|
||||||
max_length = 32,
|
|
||||||
blank = True, null = True,
|
|
||||||
)
|
|
||||||
public = models.BooleanField(
|
public = models.BooleanField(
|
||||||
_('public'),
|
_('public'),
|
||||||
default = True,
|
default = True,
|
||||||
@ -435,9 +430,6 @@ class Stream (models.Model):
|
|||||||
# - random lists
|
# - random lists
|
||||||
# - scheduled lists
|
# - scheduled lists
|
||||||
|
|
||||||
def __str__ (self):
|
|
||||||
return '#{} {}'.format(self.priority, self.name)
|
|
||||||
|
|
||||||
|
|
||||||
class Program (Nameable):
|
class Program (Nameable):
|
||||||
stream = models.ForeignKey(
|
stream = models.ForeignKey(
|
||||||
|
Reference in New Issue
Block a user