#36: Aircox ne reconnait pas les fichiers uploadés #75
|
@ -45,7 +45,7 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
'type', 'duration', 'is_public', 'is_good_quality',
|
'type', 'duration', 'is_public', 'is_good_quality',
|
||||||
'is_downloadable', 'audio']
|
'is_downloadable', 'audio']
|
||||||
list_filter = ('type', 'is_good_quality', 'is_public')
|
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']
|
search_fields = ['name', 'program__title']
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
|
@ -53,7 +53,7 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
(None, {'fields': ['duration', 'is_public', 'is_downloadable',
|
(None, {'fields': ['duration', 'is_public', 'is_downloadable',
|
||||||
'is_good_quality', 'mtime']}),
|
'is_good_quality', 'mtime']}),
|
||||||
]
|
]
|
||||||
readonly_fields = ('file', 'duration',)
|
readonly_fields = ('file', 'duration', 'type')
|
||||||
inlines = [SoundTrackInline]
|
inlines = [SoundTrackInline]
|
||||||
|
|
||||||
def related(self, obj):
|
def related(self, obj):
|
||||||
|
@ -63,7 +63,8 @@ class SoundAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
related.short_description = _('Program / Episode')
|
related.short_description = _('Program / Episode')
|
||||||
|
|
||||||
def audio(self, obj):
|
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')
|
audio.short_description = _('Audio')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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<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<hour>[0-9]{2})h(?P<minute>[0-9]{2}))?'
|
||||||
'(_(?P<n>[0-9]+))?'
|
'(_(?P<n>[0-9]+))?'
|
||||||
'_?(?P<name>.*)$'
|
'_?[ -]*(?P<name>.*)$'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ class SoundFile:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sound_path(self):
|
def sound_path(self):
|
||||||
|
""" Relative path name """
|
||||||
return self.path.replace(conf.MEDIA_ROOT + '/', '')
|
return self.path.replace(conf.MEDIA_ROOT + '/', '')
|
||||||
|
|
||||||
def sync(self, sound=None, program=None, deleted=False, **kwargs):
|
def sync(self, sound=None, program=None, deleted=False, **kwargs):
|
||||||
|
@ -74,7 +75,7 @@ class SoundFile:
|
||||||
Update related sound model and save it.
|
Update related sound model and save it.
|
||||||
"""
|
"""
|
||||||
if deleted:
|
if deleted:
|
||||||
sound = Sound.objects.filter(file=self.path).first()
|
sound = Sound.objects.path(self.path).first()
|
||||||
if sound:
|
if sound:
|
||||||
sound.type = sound.TYPE_REMOVED
|
sound.type = sound.TYPE_REMOVED
|
||||||
sound.check_on_file()
|
sound.check_on_file()
|
||||||
|
@ -249,7 +250,7 @@ class MonitorHandler(PatternMatchingEventHandler):
|
||||||
logger.info('sound deleted: %s', event.src_path)
|
logger.info('sound deleted: %s', event.src_path)
|
||||||
def deleted(event):
|
def deleted(event):
|
||||||
SoundFile(event.src_path).sync(deleted=True)
|
SoundFile(event.src_path).sync(deleted=True)
|
||||||
self.pool.submit(deleted, event.src_path)
|
self.pool.submit(deleted, event)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -325,9 +326,9 @@ class Command(BaseCommand):
|
||||||
excerpts_handler = MonitorHandler(settings.AIRCOX_SOUND_EXCERPTS_SUBDIR, pool)
|
excerpts_handler = MonitorHandler(settings.AIRCOX_SOUND_EXCERPTS_SUBDIR, pool)
|
||||||
|
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(archives_handler, settings.AIRCOX_PROGRAMS_DIR,
|
observer.schedule(archives_handler, settings.AIRCOX_PROGRAMS_DIR_ABS,
|
||||||
recursive=True)
|
recursive=True)
|
||||||
observer.schedule(excerpts_handler, settings.AIRCOX_PROGRAMS_DIR,
|
observer.schedule(excerpts_handler, settings.AIRCOX_PROGRAMS_DIR_ABS,
|
||||||
recursive=True)
|
recursive=True)
|
||||||
observer.start()
|
observer.start()
|
||||||
|
|
||||||
|
|
|
@ -98,13 +98,10 @@ class Program(Page):
|
||||||
Return a Program from the given path. We assume the path has been
|
Return a Program from the given path. We assume the path has been
|
||||||
given in a previous time by this model (Program.path getter).
|
given in a previous time by this model (Program.path getter).
|
||||||
"""
|
"""
|
||||||
if path.startswith(conf.MEDIA_ROOT):
|
if path.startswith(settings.AIRCOX_PROGRAMS_DIR_ABS):
|
||||||
path = path.replace(conf.MEDIA_ROOT + '/', '')
|
path = path.replace(settings.AIRCOX_PROGRAMS_DIR_ABS, '')
|
||||||
path = path.replace(settings.AIRCOX_PROGRAMS_DIR, '')
|
|
||||||
|
|
||||||
while path[0] == '/':
|
while path[0] == '/':
|
||||||
path = path[1:]
|
path = path[1:]
|
||||||
|
|
||||||
path = path[:path.index('/')]
|
path = path[:path.index('/')]
|
||||||
return cl.objects.filter(slug=path.replace('_','-')).first()
|
return cl.objects.filter(slug=path.replace('_','-')).first()
|
||||||
|
|
||||||
|
|
|
@ -214,9 +214,9 @@ class Sound(models.Model):
|
||||||
def __check_name(self):
|
def __check_name(self):
|
||||||
if not self.name and self.file and self.file.name:
|
if not self.name and self.file and self.file.name:
|
||||||
# FIXME: later, remove date?
|
# FIXME: later, remove date?
|
||||||
self.name = os.path.basename(self.file.name)
|
name = os.path.basename(self.file.name)
|
||||||
self.name = os.path.splitext(self.name)[0]
|
name = os.path.splitext(name)[0]
|
||||||
self.name = self.name.replace('_', ' ')
|
self.name = name.replace('_', ' ').strip()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
|
@ -86,8 +86,9 @@ ensure('AIRCOX_DEFAULT_USER_GROUPS', {
|
||||||
})
|
})
|
||||||
|
|
||||||
# Directory for the programs data
|
# Directory for the programs data
|
||||||
# TODO: rename to PROGRAMS_ROOT
|
|
||||||
ensure('AIRCOX_PROGRAMS_DIR', 'programs')
|
ensure('AIRCOX_PROGRAMS_DIR', 'programs')
|
||||||
|
ensure('AIRCOX_PROGRAMS_DIR_ABS', os.path.join(settings.MEDIA_ROOT,
|
||||||
|
AIRCOX_PROGRAMS_DIR))
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
Loading…
Reference in New Issue
Block a user