From 5a17d034c43c5fc6c5017b4a109ebe8d4daddcea Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 21 Sep 2020 15:33:10 +0200 Subject: [PATCH] remove nulability of Program, rename Sound->SoundStats, update admin display --- aircox/admin/sound.py | 22 +++++++++++++------ aircox/management/commands/sounds_monitor.py | 4 ---- .../commands/sounds_quality_check.py | 4 ++-- aircox/models/sound.py | 3 +-- aircox/templates/aircox/page_detail.html | 1 - 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/aircox/admin/sound.py b/aircox/admin/sound.py index 10184e3..ad46336 100644 --- a/aircox/admin/sound.py +++ b/aircox/admin/sound.py @@ -1,6 +1,6 @@ from django.contrib import admin from django.utils.safestring import mark_safe -from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as _ from adminsortable2.admin import SortableInlineAdminMixin @@ -29,6 +29,7 @@ class SoundInline(admin.TabularInline): def audio(self, obj): return mark_safe(''.format(obj.url())) + audio.short_descripton = _('Audio') def get_queryset(self, request): return super().get_queryset(request).available() @@ -36,13 +37,10 @@ class SoundInline(admin.TabularInline): @admin.register(Sound) class SoundAdmin(admin.ModelAdmin): - def filename(self, obj): - return '/'.join(obj.path.split('/')[-2:]) - filename.short_description=_('file') - fields = None - list_display = ['id', 'name', 'program', 'type', 'duration', - 'is_public', 'is_good_quality', 'episode', 'filename'] + list_display = ['id', 'name', 'related', + 'type', 'duration', 'is_public', 'is_good_quality', + 'audio'] list_filter = ('type', 'is_good_quality', 'is_public') search_fields = ['name', 'program__title'] @@ -53,6 +51,16 @@ class SoundAdmin(admin.ModelAdmin): readonly_fields = ('path', 'duration',) inlines = [SoundTrackInline] + def related(self, obj): + # TODO: link to episode or program edit + return obj.episode.title if obj.episode else\ + obj.program.title if obj.program else '' + related.short_description = _('Program / Episode') + + def audio(self, obj): + return mark_safe(''.format(obj.url())) + audio.short_descripton = _('Audio') + @admin.register(Track) class TrackAdmin(admin.ModelAdmin): diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index 3263ebf..42c6d8f 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -1,9 +1,5 @@ #! /usr/bin/env python3 -# TODO: -# - quality check -# - Sound model => program field as not null - """ Monitor sound files; For each program, check for: - new files; diff --git a/aircox/management/commands/sounds_quality_check.py b/aircox/management/commands/sounds_quality_check.py index b2469b0..529f35a 100755 --- a/aircox/management/commands/sounds_quality_check.py +++ b/aircox/management/commands/sounds_quality_check.py @@ -60,7 +60,7 @@ class Stats: self.parse(str(out, encoding='utf-8')) -class Sound: +class SoundStats: path = None # file path sample_length = 120 # default sample length in seconds stats = None # list of samples statistics @@ -155,7 +155,7 @@ class Command (BaseCommand): raise CommandError('no attribute specified') # sound analyse and checks - self.sounds = [Sound(path, options.get('sample_length')) + self.sounds = [SoundStats(path, options.get('sample_length')) for path in options.get('files')] self.bad = [] self.good = [] diff --git a/aircox/models/sound.py b/aircox/models/sound.py index e7ea873..2d8cd07 100644 --- a/aircox/models/sound.py +++ b/aircox/models/sound.py @@ -80,8 +80,7 @@ class Sound(models.Model): name = models.CharField(_('name'), max_length=64) program = models.ForeignKey( - # FIXME: not nullable? - Program, models.SET_NULL, blank=True, null=True, + Program, models.CASCADE, verbose_name=_('program'), help_text=_('program related to it'), ) diff --git a/aircox/templates/aircox/page_detail.html b/aircox/templates/aircox/page_detail.html index 5d90ac0..e51ec7b 100644 --- a/aircox/templates/aircox/page_detail.html +++ b/aircox/templates/aircox/page_detail.html @@ -13,7 +13,6 @@ Context: {% if page.category %} {{ page.category.title }} // {% endif %} - {{ page.pub_date }} {% endblock %}