forked from rc/aircox
WIP - Sound.file instead of Sound.path; fix issues with player; program.path is now relative
This commit is contained in:
@ -7,6 +7,7 @@ import os
|
||||
import shutil
|
||||
|
||||
import pytz
|
||||
from django.conf import settings as conf
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models import F, Q
|
||||
@ -73,14 +74,17 @@ class Program(Page):
|
||||
self.slug.replace('-', '_'))
|
||||
|
||||
@property
|
||||
def archives_path(self):
|
||||
return os.path.join(self.path, settings.AIRCOX_SOUND_ARCHIVES_SUBDIR)
|
||||
def abspath(self):
|
||||
""" Return absolute path to program's dir """
|
||||
return os.path.join(conf.MEDIA_ROOT, self.path)
|
||||
|
||||
@property
|
||||
def excerpts_path(self):
|
||||
return os.path.join(
|
||||
self.path, settings.AIRCOX_SOUND_ARCHIVES_SUBDIR
|
||||
)
|
||||
def archives_path(self, abs=False):
|
||||
return os.path.join(abs and self.abspath or self.path,
|
||||
settings.AIRCOX_SOUND_ARCHIVES_SUBDIR)
|
||||
|
||||
def excerpts_path(self, abs=False):
|
||||
return os.path.join(abs and self.abspath or self.path,
|
||||
settings.AIRCOX_SOUND_ARCHIVES_SUBDIR)
|
||||
|
||||
def __init__(self, *kargs, **kwargs):
|
||||
super().__init__(*kargs, **kwargs)
|
||||
@ -94,6 +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(conf.MEDIA_ROOT):
|
||||
path = path.replace(conf.MEDIA_ROOT + '/', '')
|
||||
path = path.replace(settings.AIRCOX_PROGRAMS_DIR, '')
|
||||
|
||||
while path[0] == '/':
|
||||
@ -107,10 +113,9 @@ class Program(Page):
|
||||
Make sur the program's dir exists (and optionally subdir). Return True
|
||||
if the dir (or subdir) exists.
|
||||
"""
|
||||
path = os.path.join(self.path, subdir) if subdir else \
|
||||
self.path
|
||||
path = os.path.join(self.abspath, subdir) if subdir else \
|
||||
self.abspath
|
||||
os.makedirs(path, exist_ok=True)
|
||||
|
||||
return os.path.exists(path)
|
||||
|
||||
class Meta:
|
||||
@ -127,14 +132,15 @@ class Program(Page):
|
||||
|
||||
# TODO: move in signals
|
||||
path_ = getattr(self, '__initial_path', None)
|
||||
abspath = os.path.join(conf.MEDIA_ROOT, path_)
|
||||
if path_ is not None and path_ != self.path and \
|
||||
os.path.exists(path_) and not os.path.exists(self.path):
|
||||
os.path.exists(abspath) and not os.path.exists(self.abspath):
|
||||
logger.info('program #%s\'s dir changed to %s - update it.',
|
||||
self.id, self.title)
|
||||
|
||||
shutil.move(path_, self.path)
|
||||
shutil.move(abspath, self.abspath)
|
||||
Sound.objects.filter(path__startswith=path_) \
|
||||
.update(path=Concat('path', Substr(F('path'), len(path_))))
|
||||
.update(file=Concat('file', Substr(F('file'), len(path_))))
|
||||
|
||||
|
||||
class ProgramChildQuerySet(PageQuerySet):
|
||||
|
Reference in New Issue
Block a user