forked from rc/aircox
remove nulability of Program, rename Sound->SoundStats, update admin display
This commit is contained in:
parent
e3151ba0bb
commit
5a17d034c4
|
@ -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('<audio src="{}" controls></audio>'.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('<audio src="{}" controls></audio>'.format(obj.url()))
|
||||
audio.short_descripton = _('Audio')
|
||||
|
||||
|
||||
@admin.register(Track)
|
||||
class TrackAdmin(admin.ModelAdmin):
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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'),
|
||||
)
|
||||
|
|
|
@ -13,7 +13,6 @@ Context:
|
|||
{% if page.category %}
|
||||
{{ page.category.title }} //
|
||||
{% endif %}
|
||||
{{ page.pub_date }}
|
||||
</span>
|
||||
{% endblock %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user