index all instance paths too, add getPath

This commit is contained in:
j 2012-08-22 00:18:00 +02:00
parent faf9865f87
commit da9dd942b2
3 changed files with 42 additions and 11 deletions

View File

@ -77,9 +77,9 @@ class File(models.Model):
def set_state(self):
self.path = self.create_path()
if not os.path.splitext(self.path)[-1] in (
'.srt', '.rar', '.sub', '.idx', '.txt', '.jpg', '.png', '.nfo') \
and self.info:
if not self.path.split('.')[-1] in (
'srt', 'rar', 'sub', 'idx', 'txt', 'jpg', 'png', 'nfo'
) and self.info:
for key in ('duration', 'size'):
setattr(self, key, self.info.get(key, 0))
@ -126,9 +126,9 @@ class File(models.Model):
self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration)
else:
self.is_video = os.path.splitext(self.path)[-1].lower() in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov', '.webm', '.mp4', '.mpg', '.wmv', '.mts', '.flv')
self.is_audio = os.path.splitext(self.path)[-1].lower() in ('.mp3', '.wav', '.ogg', '.flac', '.oga', '.wma')
self.is_subtitle = os.path.splitext(self.path)[-1].lower() in ('.srt', )
self.is_video = self.path.split('.')[-1].lower() in ox.movie.EXTENSIONS['video']
self.is_audio = self.path.split('.')[-1].lower() in ox.movie.EXTENSIONS['audio']
self.is_audio = self.path.split('.')[-1].lower() == 'srt'
if self.path.endswith('.srt'):
self.is_subtitle = True
@ -139,8 +139,8 @@ class File(models.Model):
self.type = self.get_type()
if self.instances.count()>0:
info = ox.parse_movie_path(self.path)
self.language = info['language']
info = ox.movie.parse_path(self.path)
self.language = info['language'] or ''
self.part = self.get_part()
if self.type not in ('audio', 'video'):
@ -271,9 +271,12 @@ class File(models.Model):
def create_path(self):
instance = self.get_instance()
if instance:
return instance.path
return ox.movie.parse_path(instance.path)['path']
return self.path
def all_paths(self):
return [self.path] + [i.path for i in self.instances.all()]
def delete_frames(self):
frames = os.path.join(settings.MEDIA_ROOT, self.get_path('frames'))
if os.path.exists(frames):

View File

@ -429,6 +429,28 @@ def removeFiles(request):
return render_to_json_response(response)
actions.register(removeFiles, cache=False)
def getPath(request):
'''
change file / item link
param data {
ids: [hash of file]
}
return {
status: {'code': int, 'text': string},
data: {
path: {
id: path
}
}
}
'''
data = json.loads(request.POST['data'])
response = json_response({'path': {}})
for f in models.File.objects.filter(oshash__in=data['ids']):
response['data']['path'][f.oshash] = f.path
return render_to_json_response(response)
actions.register(getPath, cache=True)
def lookup_file(request, oshash):
oshash = oshash.replace('/', '')

View File

@ -595,8 +595,7 @@ class Item(models.Model):
elif i == 'rightslevel':
save(i, self.level)
elif i == 'filename':
save(i,
'\n'.join([f.path for f in self.files.all()]))
save(i, '\n'.join(i.all_paths()))
elif i == 'user':
if self.user:
save(i, self.user.username)
@ -905,6 +904,13 @@ class Item(models.Model):
return os.path.join(settings.MEDIA_ROOT, videos[0].path(''))
return os.path.join(settings.MEDIA_ROOT, self.path())
def all_paths(self):
return list(set([
item for sublist in
[f.all_paths() for f in self.files.all()]
for item in sublist
]))
def get_files(self, user):
files = self.files.all().select_related()
if user.get_profile().get_level() != 'admin':