From 441cb9892af6a357f3875340bf87078a8028dade Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 21 Feb 2015 15:35:01 +0530 Subject: [PATCH] allow updates of file metadata for files with info --- pandora/archive/models.py | 31 ++++++++++++++++--------------- pandora/archive/tasks.py | 5 ++--- pandora/archive/views.py | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index a3a89fa5..90fa6d31 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -208,21 +208,22 @@ class File(models.Model): return p[0]['normalizedPath'] def update_info(self, info, user): - #populate name sort with director if unknown - if info.get('director') and info.get('directorSort'): - for name, sortname in zip(info['director'], info['directorSort']): - get_name_sort(name, sortname) - #add all files in one folder to same item - if self.instances.all().count(): - if info.get('isEpisode'): - prefix = os.path.splitext(self.instances.all()[0].path)[0] - else: - prefix = os.path.dirname(self.instances.all()[0].path) + '/' - qs = item.models.Item.objects.filter(files__instances__path__startswith=prefix) - if qs.exists(): - self.item = qs[0] - if not self.item: - self.item = item.models.get_item(info, user) + if not self.info: + #populate name sort with director if unknown + if info.get('director') and info.get('directorSort'): + for name, sortname in zip(info['director'], info['directorSort']): + get_name_sort(name, sortname) + #add all files in one folder to same item + if self.instances.all().count(): + if info.get('isEpisode'): + prefix = os.path.splitext(self.instances.all()[0].path)[0] + else: + prefix = os.path.dirname(self.instances.all()[0].path) + '/' + qs = item.models.Item.objects.filter(files__instances__path__startswith=prefix) + if qs.exists(): + self.item = qs[0] + if not self.item: + self.item = item.models.get_item(info, user) for key in self.AV_INFO + self.PATH_INFO: if key in info: self.info[key] = info[key] diff --git a/pandora/archive/tasks.py b/pandora/archive/tasks.py index 3dff1fcb..2adefb36 100644 --- a/pandora/archive/tasks.py +++ b/pandora/archive/tasks.py @@ -85,9 +85,8 @@ def update_info(user, info): user = models.User.objects.get(username=user) files = models.File.objects.filter(oshash__in=info.keys()) for f in files: - if not f.info: - f.update_info(info[f.oshash], user) - f.save() + f.update_info(info[f.oshash], user) + f.save() for i in Item.objects.filter(files__in=files).distinct(): i.update_selected() i.update_wanted() diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 7fb8a22d..4666b346 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -8,7 +8,7 @@ from django import forms from django.shortcuts import get_object_or_404, redirect, render_to_response from django.template import RequestContext from django.conf import settings -from django.db.models import Count +from django.db.models import Count, Q import ox from ox.utils import json @@ -95,7 +95,7 @@ def update(request, data): files = all_files.filter(file__available=False) if volume: files = files.filter(volume=volume) - response['data']['info'] = [f.file.oshash for f in all_files.filter(file__info='{}')] + response['data']['info'] = [f.file.oshash for f in all_files.filter(Q(file__info='{}')|Q(file__size=0))] response['data']['data'] = [f.file.oshash for f in files.filter(file__is_video=True, file__available=False, file__wanted=True)]