update paths on item edit, enable editable fields in editFile, part is a string now

This commit is contained in:
j 2012-09-11 15:17:35 +02:00
parent 6916792f95
commit 3de99bb4b6
4 changed files with 21 additions and 27 deletions

View file

@ -39,7 +39,7 @@ class File(models.Model):
#editable #editable
extension = models.CharField(default="", max_length=255, null=True) extension = models.CharField(default="", max_length=255, null=True)
language = models.CharField(default="", max_length=8, null=True) language = models.CharField(default="", max_length=8, null=True)
part = models.IntegerField(null=True) part = models.CharField(default="", max_length=255, null=True)
part_title = models.CharField(default="", max_length=255, null=True) part_title = models.CharField(default="", max_length=255, null=True)
version = models.CharField(default="", max_length=255, null=True) version = models.CharField(default="", max_length=255, null=True)
@ -167,6 +167,8 @@ class File(models.Model):
if self.path: if self.path:
self.path = self.normalize_path() self.path = self.normalize_path()
self.sort_path = utils.sort_string(self.path) self.sort_path = utils.sort_string(self.path)
data = ox.movie.parse_path(self.path)
self.type = data['type'] or 'unknown'
self.is_audio = self.type == 'audio' self.is_audio = self.type == 'audio'
self.is_video = self.type == 'video' self.is_video = self.type == 'video'
self.is_subtitle = self.path.endswith('.srt') self.is_subtitle = self.path.endswith('.srt')
@ -245,7 +247,11 @@ class File(models.Model):
'framerate': self.framerate, 'framerate': self.framerate,
'id': self.oshash, 'id': self.oshash,
'instances': [i.json() for i in self.instances.all()], 'instances': [i.json() for i in self.instances.all()],
'extension': self.extension,
'language': self.language,
'part': self.part, 'part': self.part,
'partTitle': self.part_title,
'version': self.version,
'path': self.path, 'path': self.path,
'resolution': resolution, 'resolution': resolution,
'samplerate': self.samplerate, 'samplerate': self.samplerate,
@ -262,22 +268,6 @@ class File(models.Model):
del data[k] del data[k]
return data return data
def get_part(self):
if self.type not in ('audio', 'video'):
name = os.path.splitext(self.path)[0]
if self.language:
name = name[-(len(self.language)+1)]
qs = self.item.files.filter(Q(is_video=True)|Q(is_audio=True),
selected=True, path__startswith=name)
if qs.count()>0:
return qs[0].get_part()
if self.selected:
files = list(self.item.files.filter(type=self.type, language=self.language,
selected=self.selected).order_by('sort_path'))
if self in files:
return files.index(self) + 1
return None
def all_paths(self): def all_paths(self):
return [self.path] + [i.path for i in self.instances.all()] return [self.path] + [i.path for i in self.instances.all()]

View file

@ -402,10 +402,11 @@ def editFile(request):
#FIXME: is this to slow to run sync? #FIXME: is this to slow to run sync?
f.item.update_selected() f.item.update_selected()
f.item.update_wanted() f.item.update_wanted()
for key in ('part', 'language'): for key in ('extension', 'language', 'part', 'partTitle', 'version'):
if key in data: if key in data:
setattr(f, key, data[key]) setattr(f,
f.auto = False re.sub('([A-Z])', lambda m: '_%s' % m.groups()[0].lower(), key),
data[key])
update = True update = True
if update: if update:
f.save() f.save()

View file

@ -368,9 +368,9 @@ class Item(models.Model):
public_id = a.public_id.split('/')[1] public_id = a.public_id.split('/')[1]
a.public_id = "%s/%s" % (self.itemId, public_id) a.public_id = "%s/%s" % (self.itemId, public_id)
a.save() a.save()
tasks.update_file_paths.delay(self.itemId)
if update_poster: if update_poster:
return tasks.update_poster.delay(self.itemId) return tasks.update_poster.delay(self.itemId)
return None return None
def delete_files(self): def delete_files(self):
@ -952,10 +952,6 @@ class Item(models.Model):
if s.filter(selected=False).count() > 0: if s.filter(selected=False).count() > 0:
s.update(selected=True, wanted=False) s.update(selected=True, wanted=False)
update = True update = True
for f in s:
if f.get_part() != f.part:
f.save()
update = True
if update: if update:
self.rendered = False self.rendered = False
self.update_timeline() self.update_timeline()
@ -1152,7 +1148,7 @@ class Item(models.Model):
def poster_frames(self): def poster_frames(self):
frames = [] frames = []
offset = 0 offset = 0
for f in self.files.filter(selected=True, is_video=True).order_by('part'): for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
for ff in f.frames.all().order_by('position'): for ff in f.frames.all().order_by('position'):
frames.append({ frames.append({
'position': offset + ff.position, 'position': offset + ff.position,
@ -1225,7 +1221,7 @@ class Item(models.Model):
#loop over all videos #loop over all videos
for f in self.files.filter(Q(is_audio=True)|Q(is_video=True)) \ for f in self.files.filter(Q(is_audio=True)|Q(is_video=True)) \
.filter(selected=True).order_by('part'): .filter(selected=True).order_by('sort_path'):
subtitles_added = False subtitles_added = False
prefix = os.path.splitext(f.path)[0] prefix = os.path.splitext(f.path)[0]
if f.instances.all().count() > 0: if f.instances.all().count() > 0:

View file

@ -56,6 +56,13 @@ def update_poster(itemId):
icon=item.icon.name icon=item.icon.name
) )
@task(ignore_results=True, queue='default')
def update_file_paths(itemId):
item = models.Item.objects.get(itemId=itemId)
for f in item.files.all():
if f.normalize_path() != f.path:
f.save()
@task(ignore_results=True, queue='default') @task(ignore_results=True, queue='default')
def update_external(itemId): def update_external(itemId):
item = models.Item.objects.get(itemId=itemId) item = models.Item.objects.get(itemId=itemId)