From 87584f74fb10cd9f4c5c6325738a587d20978e92 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 5 Jul 2011 16:28:22 +0200 Subject: [PATCH] move files to items without id --- pandora/archive/views.py | 19 +++++++++++-------- pandora/item/models.py | 29 ++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pandora/archive/views.py b/pandora/archive/views.py index a87b17bf..15a18e38 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -239,26 +239,29 @@ def moveFiles(request): ''' data = json.loads(request.POST['data']) if models.Item.objects.filter(itemId=data['itemId']).count() == 1: - item = models.Item.objects.get(itemId=data['itemId']) + i = models.Item.objects.get(itemId=data['itemId']) else: if len(data['itemId']) != 7: del data['itemId'] - item = get_item(data) + i = get_item(data) else: - item = get_item({'imdbId': data['itemId']}) + i = get_item({'imdbId': data['itemId']}) changed = [] for f in models.File.objects.filter(oshash__in=data['ids']): - if f.item.id != data['itemId'] and f.editable(request.user): + if f.item.id != i.itemId and f.editable(request.user): if f.item.itemId not in changed: changed.append(f.item.itemId) - if item.itemId not in changed: - changed.append(item.itemId) - f.item = item + if i.itemId not in changed: + changed.append(i.itemId) + f.item = i f.save() for itemId in changed: + c = models.Item.objects.get(itemId=itemId) + c.rendered = False + c.save() item.tasks.update_streams.delay(itemId) response = json_response(text='updated') - response['data']['itemId'] = item.itemId + response['data']['itemId'] = i.itemId return render_to_json_response(response) actions.register(moveFiles, cache=False) diff --git a/pandora/item/models.py b/pandora/item/models.py index 3ef6366d..4b1c572c 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -56,10 +56,24 @@ def get_item(info, user=None): item.save() tasks.update_external.delay(item.itemId) else: - q = Item.objects.filter(find__key='title', find__value=info['title']) - if q.count() > 1: - print "FIXME: check more than title here!!?" + q = Item.objects.all() + for key in ('title', 'director', 'year'): + if key in info and info[key]: + q = q.filter(find__key=key, find__value=info[key]) + if q.count() >= 1: item = q[0] + elif not 'oxdbId' in info: + item = Item() + item.data = { + 'title': info['title'], + 'director': info['director'], + 'year': info.get('year', '') + } + for key in ('episode_title', 'series_title', 'season', 'episode'): + if key in info and info[key]: + item.data[key] = info[key] + item.oxdbId = item.oxdb_id() + item.save() else: try: item = Item.objects.get(itemId=info['oxdbId']) @@ -219,9 +233,14 @@ class Item(models.Model): self.itemId = str(uuid.uuid1()) super(Item, self).save(*args, **kwargs) if not settings.USE_IMDB: - self.itemId = ox.to32(self.id) + self.itemId = ox.to32(self.id) self.oxdbId = self.oxdb_id() + + #id changed, what about existing item with new id? + if settings.USE_IMDB and len(self.itemId) != 7 and self.oxdbId != self.itemId: + self.itemId = self.oxdbId + #FIXME: move files to new id here if self.poster: self.poster_height = self.poster.height @@ -714,7 +733,7 @@ class Item(models.Model): self.make_local_posters() self.make_poster() self.make_icon() - self.rendered = True + self.rendered = files != {} self.save() '''