remove nulability of Program, rename Sound->SoundStats, update admin display
This commit is contained in:
		@ -1,6 +1,6 @@
 | 
				
			|||||||
from django.contrib import admin
 | 
					from django.contrib import admin
 | 
				
			||||||
from django.utils.safestring import mark_safe
 | 
					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
 | 
					from adminsortable2.admin import SortableInlineAdminMixin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,6 +29,7 @@ class SoundInline(admin.TabularInline):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def audio(self, obj):
 | 
					    def audio(self, obj):
 | 
				
			||||||
        return mark_safe('<audio src="{}" controls></audio>'.format(obj.url()))
 | 
					        return mark_safe('<audio src="{}" controls></audio>'.format(obj.url()))
 | 
				
			||||||
 | 
					    audio.short_descripton = _('Audio')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_queryset(self, request):
 | 
					    def get_queryset(self, request):
 | 
				
			||||||
        return super().get_queryset(request).available()
 | 
					        return super().get_queryset(request).available()
 | 
				
			||||||
@ -36,13 +37,10 @@ class SoundInline(admin.TabularInline):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@admin.register(Sound)
 | 
					@admin.register(Sound)
 | 
				
			||||||
class SoundAdmin(admin.ModelAdmin):
 | 
					class SoundAdmin(admin.ModelAdmin):
 | 
				
			||||||
    def filename(self, obj):
 | 
					 | 
				
			||||||
        return '/'.join(obj.path.split('/')[-2:])
 | 
					 | 
				
			||||||
    filename.short_description=_('file')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fields = None
 | 
					    fields = None
 | 
				
			||||||
    list_display = ['id', 'name', 'program', 'type', 'duration',
 | 
					    list_display = ['id', 'name', 'related',
 | 
				
			||||||
                    'is_public', 'is_good_quality', 'episode', 'filename']
 | 
					                    'type', 'duration', 'is_public', 'is_good_quality',
 | 
				
			||||||
 | 
					                    'audio']
 | 
				
			||||||
    list_filter = ('type', 'is_good_quality', 'is_public')
 | 
					    list_filter = ('type', 'is_good_quality', 'is_public')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    search_fields = ['name', 'program__title']
 | 
					    search_fields = ['name', 'program__title']
 | 
				
			||||||
@ -53,6 +51,16 @@ class SoundAdmin(admin.ModelAdmin):
 | 
				
			|||||||
    readonly_fields = ('path', 'duration',)
 | 
					    readonly_fields = ('path', 'duration',)
 | 
				
			||||||
    inlines = [SoundTrackInline]
 | 
					    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)
 | 
					@admin.register(Track)
 | 
				
			||||||
class TrackAdmin(admin.ModelAdmin):
 | 
					class TrackAdmin(admin.ModelAdmin):
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,5 @@
 | 
				
			|||||||
#! /usr/bin/env python3
 | 
					#! /usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO:
 | 
					 | 
				
			||||||
# - quality check
 | 
					 | 
				
			||||||
# - Sound model => program field as not null
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
Monitor sound files; For each program, check for:
 | 
					Monitor sound files; For each program, check for:
 | 
				
			||||||
- new files;
 | 
					- new files;
 | 
				
			||||||
 | 
				
			|||||||
@ -60,7 +60,7 @@ class Stats:
 | 
				
			|||||||
        self.parse(str(out, encoding='utf-8'))
 | 
					        self.parse(str(out, encoding='utf-8'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Sound:
 | 
					class SoundStats:
 | 
				
			||||||
    path = None             # file path
 | 
					    path = None             # file path
 | 
				
			||||||
    sample_length = 120     # default sample length in seconds
 | 
					    sample_length = 120     # default sample length in seconds
 | 
				
			||||||
    stats = None            # list of samples statistics
 | 
					    stats = None            # list of samples statistics
 | 
				
			||||||
@ -155,7 +155,7 @@ class Command (BaseCommand):
 | 
				
			|||||||
            raise CommandError('no attribute specified')
 | 
					            raise CommandError('no attribute specified')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # sound analyse and checks
 | 
					        # 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')]
 | 
					                       for path in options.get('files')]
 | 
				
			||||||
        self.bad = []
 | 
					        self.bad = []
 | 
				
			||||||
        self.good = []
 | 
					        self.good = []
 | 
				
			||||||
 | 
				
			|||||||
@ -80,8 +80,7 @@ class Sound(models.Model):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    name = models.CharField(_('name'), max_length=64)
 | 
					    name = models.CharField(_('name'), max_length=64)
 | 
				
			||||||
    program = models.ForeignKey(
 | 
					    program = models.ForeignKey(
 | 
				
			||||||
        # FIXME: not nullable?
 | 
					        Program, models.CASCADE,
 | 
				
			||||||
        Program, models.SET_NULL, blank=True, null=True,
 | 
					 | 
				
			||||||
        verbose_name=_('program'),
 | 
					        verbose_name=_('program'),
 | 
				
			||||||
        help_text=_('program related to it'),
 | 
					        help_text=_('program related to it'),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,6 @@ Context:
 | 
				
			|||||||
    {% if page.category %}
 | 
					    {% if page.category %}
 | 
				
			||||||
    {{ page.category.title }} //
 | 
					    {{ page.category.title }} //
 | 
				
			||||||
    {% endif %}
 | 
					    {% endif %}
 | 
				
			||||||
    {{ page.pub_date }}
 | 
					 | 
				
			||||||
</span>
 | 
					</span>
 | 
				
			||||||
{% endblock %}
 | 
					{% endblock %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user