From 041a272c4de6b8b3eadc502dcc2497ad1b7510e8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 3 Feb 2012 12:13:15 +0530 Subject: [PATCH] update matching places/events --- pandora/annotation/tasks.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index 30a7c85b..f939fdf5 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -8,39 +8,43 @@ import models @task(ignore_resulsts=True, queue='default') def update_matching_events(id): from event.models import Event - annotation = models.Annotation.objects.get(pk=id) - for e in annotation.events.filter(defined=False): + a = models.Annotation.objects.get(pk=id) + ''' + for e in a.events.filter(defined=False): if e.annotations.exclude(id=id).count() == 0: e.delete() - if annotation.get_layer().get('type') == 'event' \ - and annotation.events.count() == 0: - annotation.events.add(Event.get_or_create(annotation.value)) - for e in annotation.events.all(): + ''' + for e in a.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.lower() in annotation.value.lower(): + if name.lower() in a.value.lower(): e.update_matches() break + if a.get_layer().get('type') == 'event' \ + and a.events.count() == 0: + a.events.add(Event.get_or_create(a.value)) @task(ignore_resulsts=True, queue='default') def update_matching_places(id): from place.models import Place - annotation = models.Annotation.objects.get(pk=id) - for p in annotation.places.filter(defined=False): + a = models.Annotation.objects.get(pk=id) + ''' + for p in a.places.filter(defined=False): if p.annotations.exclude(id=id).count() == 0: p.delete() - if annotation.get_layer().get('type') == 'place' \ - and annotation.places.count() == 0: - annotation.places.add(Place.get_or_create(annotation.value)) - for p in annotation.places.all(): + ''' + for p in a.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.lower() in annotation.value.lower(): + if name.lower() in a.value.lower(): e.update_matches() break + if a.get_layer().get('type') == 'place' \ + and a.places.count() == 0: + a.places.add(Place.get_or_create(a.value))