From 361cf88bb214080550e6bb37fc82c391049910ec Mon Sep 17 00:00:00 2001 From: bkfox Date: Wed, 16 Sep 2020 15:12:05 +0200 Subject: [PATCH] fix stuff; sound inline in admin --- aircox/admin/sound.py | 16 ++++--- .../commands/sounds_quality_check.py | 6 +++ aircox/models/sound.py | 42 ++++--------------- aircox/settings.py | 12 ------ aircox/templates/aircox/widgets/player.html | 6 +-- .../aircox/widgets/podcast_item.html | 2 + aircox/views/episode.py | 6 +-- assets/public/player.vue | 10 ++--- 8 files changed, 36 insertions(+), 64 deletions(-) diff --git a/aircox/admin/sound.py b/aircox/admin/sound.py index 2d39545..10184e3 100644 --- a/aircox/admin/sound.py +++ b/aircox/admin/sound.py @@ -1,5 +1,6 @@ from django.contrib import admin -from django.utils.translation import gettext as _, gettext_lazy +from django.utils.safestring import mark_safe +from django.utils.translation import gettext as _ from adminsortable2.admin import SortableInlineAdminMixin @@ -21,9 +22,13 @@ class SoundTrackInline(TrackInline): class SoundInline(admin.TabularInline): model = Sound - fields = ['type', 'path', 'embed', 'duration', 'is_public'] - readonly_fields = ['type', 'path', 'duration'] + fields = ['type', 'name', 'audio', 'duration', 'is_good_quality', 'is_public'] + readonly_fields = ['type', 'audio', 'duration', 'is_good_quality'] extra = 0 + max_num = 0 + + def audio(self, obj): + return mark_safe(''.format(obj.url())) def get_queryset(self, request): return super().get_queryset(request).available() @@ -40,11 +45,10 @@ class SoundAdmin(admin.ModelAdmin): 'is_public', 'is_good_quality', 'episode', 'filename'] list_filter = ('type', 'is_good_quality', 'is_public') - search_fields = ['name', 'program'] + search_fields = ['name', 'program__title'] fieldsets = [ (None, {'fields': ['name', 'path', 'type', 'program', 'episode']}), - (None, {'fields': ['embed', 'duration', 'is_public', 'mtime']}), - (None, {'fields': ['is_good_quality']}) + (None, {'fields': ['duration', 'is_public', 'is_good_quality', 'mtime']}), ] readonly_fields = ('path', 'duration',) inlines = [SoundTrackInline] diff --git a/aircox/management/commands/sounds_quality_check.py b/aircox/management/commands/sounds_quality_check.py index b2469b0..774c5e9 100755 --- a/aircox/management/commands/sounds_quality_check.py +++ b/aircox/management/commands/sounds_quality_check.py @@ -60,6 +60,12 @@ class Stats: self.parse(str(out, encoding='utf-8')) +#class SoundFile: +# path = None +# sample_rate = None +# length = None + + class Sound: path = None # file path sample_length = 120 # default sample length in seconds diff --git a/aircox/models/sound.py b/aircox/models/sound.py index d437c15..3c5885c 100644 --- a/aircox/models/sound.py +++ b/aircox/models/sound.py @@ -37,9 +37,9 @@ class SoundQuerySet(models.QuerySet): def available(self): return self.exclude(type=Sound.TYPE_REMOVED) - def podcasts(self): + def public(self): """ Return sounds available as podcasts """ - return self.filter(Q(embed__isnull=False) | Q(is_public=True)) + return self.filter(is_public=True) def archive(self): """ Return sounds that are archives """ @@ -103,11 +103,11 @@ class Sound(models.Model): recursive=True, max_length=255, blank=True, null=True, unique=True, ) - embed = models.TextField( - _('embed'), - blank=True, null=True, - help_text=_('HTML code to embed a sound from an external plateform'), - ) + #embed = models.TextField( + # _('embed'), + # blank=True, null=True, + # help_text=_('HTML code to embed a sound from an external plateform'), + #) duration = models.TimeField( _('duration'), blank=True, null=True, @@ -156,19 +156,12 @@ class Sound(models.Model): return tz.make_aware(mtime, tz.get_current_timezone()) def url(self): - """ - Return an url to the stream - """ - # path = self._meta.get_field('path').path + """ Return an url to the stream. """ path = self.path.replace(main_settings.MEDIA_ROOT, '', 1) - #path = self.path.replace(path, '', 1) - return main_settings.MEDIA_URL + '/' + path def file_exists(self): - """ - Return true if the file still exists - """ + """ Return true if the file still exists. """ return os.path.exists(self.path) @@ -241,23 +234,6 @@ class Sound(models.Model): return changed - def check_perms(self): - """ - Check file permissions and update it if the sound is public - """ - - if not settings.AIRCOX_SOUND_AUTO_CHMOD or \ - self.removed or not os.path.exists(self.path): - - return - - flags = settings.AIRCOX_SOUND_CHMOD_FLAGS[self.is_public] - try: - os.chmod(self.path, flags) - except PermissionError as err: - logger.error('cannot set permissions {} to file {}: {}'.format( - self.flags[self.is_public], self.path, err)) - def __check_name(self): if not self.name and self.path: # FIXME: later, remove date? diff --git a/aircox/settings.py b/aircox/settings.py index 3fc44e2..8ca0ceb 100755 --- a/aircox/settings.py +++ b/aircox/settings.py @@ -1,5 +1,4 @@ import os -import stat from django.conf import settings @@ -38,8 +37,6 @@ from django.conf import settings # sounds_default_dir = os.path.join(settings.MEDIA_ROOT, 'programs/defaults') # sound_archive_dir = 'archives' # sound_excerpt_dir = 'excerpts' -# sound_auto_chmod = True -# sound_chmod_flags = (stat.S_IRWXU, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH) # sound_quality = { # 'attribute': 'RMS lev dB', # 'range': (-18.0, -8.0), @@ -116,15 +113,6 @@ ensure('AIRCOX_SOUND_ARCHIVES_SUBDIR', 'archives') # Sub directory used for the excerpts of the episode ensure('AIRCOX_SOUND_EXCERPTS_SUBDIR', 'excerpts') -# Change sound perms based on 'public' attribute if True -ensure('AIRCOX_SOUND_AUTO_CHMOD', True) -# Chmod bits flags as a tuple for (not public, public). Use os.chmod -# and stat.* -ensure( - 'AIRCOX_SOUND_CHMOD_FLAGS', - (stat.S_IRWXU, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH) -) - # Quality attributes passed to sound_quality_check from sounds_monitor ensure('AIRCOX_SOUND_QUALITY', { 'attribute': 'RMS lev dB', diff --git a/aircox/templates/aircox/widgets/player.html b/aircox/templates/aircox/widgets/player.html index 1e45dc0..856512f 100644 --- a/aircox/templates/aircox/widgets/player.html +++ b/aircox/templates/aircox/widgets/player.html @@ -28,7 +28,7 @@ The audio player diff --git a/aircox/templates/aircox/widgets/podcast_item.html b/aircox/templates/aircox/widgets/podcast_item.html index 7543f81..44a3fde 100644 --- a/aircox/templates/aircox/widgets/podcast_item.html +++ b/aircox/templates/aircox/widgets/podcast_item.html @@ -3,9 +3,11 @@ List item for a podcast. {% endcomment %}
+ {# comment #} {% if object.embed %} {{ object.embed|safe }} {% else %} + {# endcomment #}
diff --git a/aircox/views/episode.py b/aircox/views/episode.py index 96dbc51..74c6363 100644 --- a/aircox/views/episode.py +++ b/aircox/views/episode.py @@ -2,7 +2,6 @@ from collections import OrderedDict import datetime from django.views.generic import ListView -from django.utils.translation import gettext as _ from ..models import Diffusion, Episode, Program, StaticPage, Sound from .base import BaseView @@ -17,14 +16,11 @@ __all__ = ['EpisodeDetailView', 'EpisodeListView', 'DiffusionListView'] class EpisodeDetailView(ProgramPageDetailView): model = Episode - def get_podcasts(self, diffusion): - return Sound.objects.diffusion(diffusion).podcasts() - def get_context_data(self, **kwargs): if not 'tracks' in kwargs: kwargs['tracks'] = self.object.track_set.order_by('position') if not 'podcasts' in kwargs: - kwargs['podcasts'] = self.object.sound_set.podcasts() + kwargs['podcasts'] = self.object.sound_set.public() return super().get_context_data(**kwargs) diff --git a/assets/public/player.vue b/assets/public/player.vue index 5fcacdb..23c8179 100644 --- a/assets/public/player.vue +++ b/assets/public/player.vue @@ -38,7 +38,8 @@ export default { data() { return { state: State.paused, - liveInfo: new LiveInfo(this.liveInfoUrl, this.liveInfoTimeout), + liveInfo: this.liveInfoUrl ? new LiveInfo(this.liveInfoUrl, this.liveInfoTimeout) + : null, } }, @@ -55,7 +56,7 @@ export default { loading() { return this.state == State.loading; }, onAir() { - return this.liveInfo.items && this.liveInfo.items[0]; + return this.liveInfo && this.liveInfo.items && this.liveInfo.items[0]; }, buttonStyle() { @@ -83,7 +84,6 @@ export default { }, toggle() { - console.log('tooogle', this.paused, '-', this.$refs.audio.src) if(this.paused) this.play() else @@ -97,11 +97,11 @@ export default { }, mounted() { - this.liveInfo.refresh() + this.liveInfo && this.liveInfo.refresh() }, destroyed() { - this.liveInfo.drop() + this.liveInfo && this.liveInfo.drop() }, }