From 8520c0668028d9ef379d1fcc83b6081a412064e8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Feb 2012 17:57:42 +0530 Subject: [PATCH 1/4] sync find/sort table saving annotations, fixes #401 --- pandora/annotation/models.py | 7 +++---- pandora/annotation/tasks.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 618759d1a..412cdc189 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -18,7 +18,7 @@ from changelog.models import Changelog from item.utils import sort_string import managers import utils -from tasks import update_matching_events, update_matching_places +from tasks import update_matching_events, update_matching_places, update_item def get_matches(obj, model, layer_type): @@ -160,9 +160,8 @@ class Annotation(models.Model): if layer.get('type') == 'event' or layer.get('hasEvents'): update_matching_events(self.id) - #update facets if needed - if filter(lambda f: f['id'] == self.layer, settings.CONFIG['filters']): - self.item.update_layer_facet(self.layer) + #update sort/find tables async + update_item.delay(self.id) def cleanup_undefined_relations(self): layer = self.get_layer() diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 6d568019c..3036e9165 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 +from django.conf import settings from celery.task import task import models @@ -44,3 +45,15 @@ def update_matching_places(id): if name.lower() in a.value.lower(): e.update_matches() break + +@task(ignore_resulsts=True, queue='default') +def update_item(id): + from item.models import Item + a = models.Annotation.objects.get(pk=id) + #update facets if needed + if filter(lambda f: f['id'] == a.layer, settings.CONFIG['filters']): + a.item.update_layer_facet(a.layer) + Item.objects.filter(id=a.item.id).update(modified=a.modified) + a.item.update_find() + a.item.update_sort() + a.item.update_facets() From b9129b10c79d2f43c4213423610df394a042a857 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Feb 2012 18:02:52 +0530 Subject: [PATCH 2/4] update in memory object too --- pandora/annotation/tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 3036e9165..0f395504f 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -54,6 +54,7 @@ def update_item(id): if filter(lambda f: f['id'] == a.layer, settings.CONFIG['filters']): a.item.update_layer_facet(a.layer) Item.objects.filter(id=a.item.id).update(modified=a.modified) + a.item.modified = a.modified a.item.update_find() a.item.update_sort() a.item.update_facets() From 2cf7c56115f8832d5433abdeee13e92dfaa3634f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Feb 2012 21:19:40 +0530 Subject: [PATCH 3/4] only request subtitles if a subtitles layer is defined, fixed #427 --- pandora/archive/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandora/archive/views.py b/pandora/archive/views.py index fa84ccf92..04b177516 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -104,10 +104,14 @@ def update(request): response['data']['data'] += [f.file.oshash for f in files.filter(file__is_audio=True, file__available=False, file__wanted=True)] - response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True, - file__available=False, - path__endswith='.srt')] + if filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']): + response['data']['file'] = [f.file.oshash + for f in files.filter(file__is_subtitle=True, + file__available=False, + path__endswith='.srt')] + else: + response['data']['file'] = [] return render_to_json_response(response) actions.register(update, cache=False) From 6bdbd729a72af22ddff0b96ac7e5f05c1619d5d8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Feb 2012 21:31:24 +0530 Subject: [PATCH 4/4] update item sort after changing person sort value, fixes #30 --- pandora/person/models.py | 10 +++++++++- pandora/person/tasks.py | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 pandora/person/tasks.py diff --git a/pandora/person/models.py b/pandora/person/models.py index 5bc755519..4bfb882ca 100644 --- a/pandora/person/models.py +++ b/pandora/person/models.py @@ -13,7 +13,7 @@ from item import utils import item.models import managers - +import tasks def get_name_sort(name): name = unicodedata.normalize('NFKD', name).strip() @@ -51,6 +51,9 @@ class Person(models.Model): self.sortsortname = utils.sort_string(self.sortname) self.numberofnames = len(self.name.split(' ')) super(Person, self).save(*args, **kwargs) + tasks.update_itemsort.delay(self.id) + + def update_itemsort(self): item.models.Facet.objects.filter( key__in=item.models.Item.person_keys + ['name'], value=self.name @@ -59,6 +62,11 @@ class Person(models.Model): ).update( sortvalue=self.sortname ) + for i in item.models.Item.objects.filter(facets__in=item.models.Facet.objects.filter( + key__in=item.models.Item.person_keys + ['name'], + value=self.name) + ).distinct(): + i.update_sort() def get_or_create(model, name, imdbId=None): if imdbId: diff --git a/pandora/person/tasks.py b/pandora/person/tasks.py new file mode 100644 index 000000000..a77fe2dda --- /dev/null +++ b/pandora/person/tasks.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +from celery.task import task + +import models + + +@task(ignore_resulsts=True, queue='default') +def update_itemsort(id): + p = models.Person.objects.get(pk=id) + p.update_itemsort()