From 4d06bacfc407ab5622ea07ac18706ea83fc82769 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 2 Jan 2012 23:05:10 +0530 Subject: [PATCH] update place/event matches on change --- pandora/annotation/models.py | 9 ++++++--- pandora/annotation/tasks.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 1ef3648d..d4a80946 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -87,9 +87,12 @@ class Annotation(models.Model): self.layer: False }).update(**{self.layer: True}) - #how expensive is this? - #update_matching_events.delay(self.value) - #update_matching_places.delay(self.value) + if filter(lambda l: l['type'] == 'place' or l.get('hasPlaces'), + settings.CONFIG['layers']): + update_matching_places.delay(self.id) + if filter(lambda l: l['type'] == 'event' or l.get('hasEvents'), + settings.CONFIG['layers']): + update_matching_events.delay(self.id) def json(self, layer=False, keys=None): j = { diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index b8bf31a2..8a58d29c 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -2,26 +2,33 @@ # vi:si:et:sw=4:sts=4:ts=4 from celery.task import task +import models @task(ignore_resulsts=True, queue='default') -def update_matching_events(value): +def update_matching_events(id): from event.models import Event + annotation = models.Annotation.objects.get(pk=id) + for e in annotation.events.all(): + e.update_matches() ids = [e['id'] for e in Event.objects.all().values('id')] for i in ids: e = Event.objects.get(pk=i) for name in [e.name] + list(e.alternativeNames): - if name in value: + if name in annotation.value: e.update_matches() break @task(ignore_resulsts=True, queue='default') -def update_matching_places(value): +def update_matching_places(id): from place.models import Place + annotation = models.Annotation.objects.get(pk=id) + for p in annotation.places.all(): + p.update_matches() ids = [e['id'] for e in Place.objects.all().values('id')] for i in ids: e = Place.objects.get(pk=i) for name in [e.name] + list(e.alternativeNames): - if name in value: + if name in annotation.value: e.update_matches() break