From 05a3b9c95db4b3f19d8723b2c56dcb57abc49941 Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 10 Oct 2022 18:23:19 +0200 Subject: [PATCH 1/4] path bug --- aircox/models/program.py | 7 ++----- aircox/settings.py | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/aircox/models/program.py b/aircox/models/program.py index 90845f0..e55967d 100644 --- a/aircox/models/program.py +++ b/aircox/models/program.py @@ -98,13 +98,10 @@ class Program(Page): Return a Program from the given path. We assume the path has been given in a previous time by this model (Program.path getter). """ - if path.startswith(conf.MEDIA_ROOT): - path = path.replace(conf.MEDIA_ROOT + '/', '') - path = path.replace(settings.AIRCOX_PROGRAMS_DIR, '') - + if path.startswith(settings.AIRCOX_PROGRAMS_DIR): + path = path.replace(settings.AIRCOX_PROGRAMS_DIR + '/', '') while path[0] == '/': path = path[1:] - path = path[:path.index('/')] return cl.objects.filter(slug=path.replace('_','-')).first() diff --git a/aircox/settings.py b/aircox/settings.py index fb54742..6d8d504 100755 --- a/aircox/settings.py +++ b/aircox/settings.py @@ -86,8 +86,7 @@ ensure('AIRCOX_DEFAULT_USER_GROUPS', { }) # Directory for the programs data -# TODO: rename to PROGRAMS_ROOT -ensure('AIRCOX_PROGRAMS_DIR', 'programs') +ensure('AIRCOX_PROGRAMS_DIR', os.path.join(settings.MEDIA_ROOT, 'programs')) ######################################################################## -- 2.30.2 From 1fed61f47f8bd6ed472124988426ec61a00f8c6a Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 10 Oct 2022 19:08:51 +0200 Subject: [PATCH 2/4] fix sound path query bugs --- aircox/management/commands/sounds_monitor.py | 8 ++++---- aircox/models/program.py | 4 ++-- aircox/settings.py | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index cf50ee0..9a86f72 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -74,7 +74,7 @@ class SoundFile: Update related sound model and save it. """ if deleted: - sound = Sound.objects.filter(file=self.path).first() + sound = Sound.objects.path(self.path).first() if sound: sound.type = sound.TYPE_REMOVED sound.check_on_file() @@ -249,7 +249,7 @@ class MonitorHandler(PatternMatchingEventHandler): logger.info('sound deleted: %s', event.src_path) def deleted(event): SoundFile(event.src_path).sync(deleted=True) - self.pool.submit(deleted, event.src_path) + self.pool.submit(deleted, event) class Command(BaseCommand): @@ -325,9 +325,9 @@ class Command(BaseCommand): excerpts_handler = MonitorHandler(settings.AIRCOX_SOUND_EXCERPTS_SUBDIR, pool) observer = Observer() - observer.schedule(archives_handler, settings.AIRCOX_PROGRAMS_DIR, + observer.schedule(archives_handler, settings.AIRCOX_PROGRAMS_DIR_ABS, recursive=True) - observer.schedule(excerpts_handler, settings.AIRCOX_PROGRAMS_DIR, + observer.schedule(excerpts_handler, settings.AIRCOX_PROGRAMS_DIR_ABS, recursive=True) observer.start() diff --git a/aircox/models/program.py b/aircox/models/program.py index e55967d..42eef57 100644 --- a/aircox/models/program.py +++ b/aircox/models/program.py @@ -98,8 +98,8 @@ class Program(Page): Return a Program from the given path. We assume the path has been given in a previous time by this model (Program.path getter). """ - if path.startswith(settings.AIRCOX_PROGRAMS_DIR): - path = path.replace(settings.AIRCOX_PROGRAMS_DIR + '/', '') + if path.startswith(settings.AIRCOX_PROGRAMS_DIR_ABS): + path = path.replace(settings.AIRCOX_PROGRAMS_DIR_ABS, '') while path[0] == '/': path = path[1:] path = path[:path.index('/')] diff --git a/aircox/settings.py b/aircox/settings.py index 6d8d504..56b3377 100755 --- a/aircox/settings.py +++ b/aircox/settings.py @@ -86,7 +86,9 @@ ensure('AIRCOX_DEFAULT_USER_GROUPS', { }) # Directory for the programs data -ensure('AIRCOX_PROGRAMS_DIR', os.path.join(settings.MEDIA_ROOT, 'programs')) +ensure('AIRCOX_PROGRAMS_DIR', 'programs') +ensure('AIRCOX_PROGRAMS_DIR_ABS', os.path.join(settings.MEDIA_ROOT, + AIRCOX_PROGRAMS_DIR)) ######################################################################## -- 2.30.2 From e873ff71e8c2e885e49bbcf57bdf95a9f9f11586 Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 10 Oct 2022 19:11:40 +0200 Subject: [PATCH 3/4] doc --- aircox/management/commands/sounds_monitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index 9a86f72..8e8cf87 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -67,6 +67,7 @@ class SoundFile: @property def sound_path(self): + """ Relative path name """ return self.path.replace(conf.MEDIA_ROOT + '/', '') def sync(self, sound=None, program=None, deleted=False, **kwargs): -- 2.30.2 From 80cd5baa184a5cc8cd1d9e05c792dcf374d46da7 Mon Sep 17 00:00:00 2001 From: bkfox Date: Mon, 10 Oct 2022 19:25:48 +0200 Subject: [PATCH 4/4] names & conditional display of audio in admin --- aircox/admin/sound.py | 7 ++++--- aircox/management/commands/sounds_monitor.py | 2 +- aircox/models/sound.py | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/aircox/admin/sound.py b/aircox/admin/sound.py index 3dc35b5..259d480 100644 --- a/aircox/admin/sound.py +++ b/aircox/admin/sound.py @@ -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(''.format(obj.file.url)) + return mark_safe(''.format(obj.file.url)) \ + if obj.type != Sound.TYPE_REMOVED else '' audio.short_description = _('Audio') diff --git a/aircox/management/commands/sounds_monitor.py b/aircox/management/commands/sounds_monitor.py index 8e8cf87..66a975b 100755 --- a/aircox/management/commands/sounds_monitor.py +++ b/aircox/management/commands/sounds_monitor.py @@ -52,7 +52,7 @@ sound_path_re = re.compile( '^(?P[0-9]{4})(?P[0-9]{2})(?P[0-9]{2})' '(_(?P[0-9]{2})h(?P[0-9]{2}))?' '(_(?P[0-9]+))?' - '_?(?P.*)$' + '_?[ -]*(?P.*)$' ) diff --git a/aircox/models/sound.py b/aircox/models/sound.py index b3b19b4..c0185fc 100644 --- a/aircox/models/sound.py +++ b/aircox/models/sound.py @@ -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) -- 2.30.2