names & conditional display of audio in admin

This commit is contained in:
bkfox 2022-10-10 19:25:48 +02:00
parent e873ff71e8
commit 80cd5baa18
3 changed files with 8 additions and 7 deletions

View File

@ -45,7 +45,7 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
'type', 'duration', 'is_public', 'is_good_quality',
'is_downloadable', 'audio']
list_filter = ('type', 'is_good_quality', 'is_public')
list_editable = ['name', 'type', 'is_public', 'is_downloadable']
list_editable = ['name', 'is_public', 'is_downloadable']
search_fields = ['name', 'program__title']
fieldsets = [
@ -53,7 +53,7 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
(None, {'fields': ['duration', 'is_public', 'is_downloadable',
'is_good_quality', 'mtime']}),
]
readonly_fields = ('file', 'duration',)
readonly_fields = ('file', 'duration', 'type')
inlines = [SoundTrackInline]
def related(self, obj):
@ -63,7 +63,8 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
related.short_description = _('Program / Episode')
def audio(self, obj):
return mark_safe('<audio src="{}" controls></audio>'.format(obj.file.url))
return mark_safe('<audio src="{}" controls></audio>'.format(obj.file.url)) \
if obj.type != Sound.TYPE_REMOVED else ''
audio.short_description = _('Audio')

View File

@ -52,7 +52,7 @@ sound_path_re = re.compile(
'^(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})'
'(_(?P<hour>[0-9]{2})h(?P<minute>[0-9]{2}))?'
'(_(?P<n>[0-9]+))?'
'_?(?P<name>.*)$'
'_?[ -]*(?P<name>.*)$'
)

View File

@ -214,9 +214,9 @@ class Sound(models.Model):
def __check_name(self):
if not self.name and self.file and self.file.name:
# FIXME: later, remove date?
self.name = os.path.basename(self.file.name)
self.name = os.path.splitext(self.name)[0]
self.name = self.name.replace('_', ' ')
name = os.path.basename(self.file.name)
name = os.path.splitext(name)[0]
self.name = name.replace('_', ' ').strip()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)