update matching places/events

This commit is contained in:
j 2012-02-03 12:13:15 +05:30
parent 5ff0ff93f0
commit 041a272c4d

View file

@ -8,39 +8,43 @@ import models
@task(ignore_resulsts=True, queue='default') @task(ignore_resulsts=True, queue='default')
def update_matching_events(id): def update_matching_events(id):
from event.models import Event from event.models import Event
annotation = models.Annotation.objects.get(pk=id) a = models.Annotation.objects.get(pk=id)
for e in annotation.events.filter(defined=False): '''
for e in a.events.filter(defined=False):
if e.annotations.exclude(id=id).count() == 0: if e.annotations.exclude(id=id).count() == 0:
e.delete() e.delete()
if annotation.get_layer().get('type') == 'event' \ '''
and annotation.events.count() == 0: for e in a.events.all():
annotation.events.add(Event.get_or_create(annotation.value))
for e in annotation.events.all():
e.update_matches() e.update_matches()
ids = [e['id'] for e in Event.objects.all().values('id')] ids = [e['id'] for e in Event.objects.all().values('id')]
for i in ids: for i in ids:
e = Event.objects.get(pk=i) e = Event.objects.get(pk=i)
for name in [e.name] + list(e.alternativeNames): 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() e.update_matches()
break 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') @task(ignore_resulsts=True, queue='default')
def update_matching_places(id): def update_matching_places(id):
from place.models import Place from place.models import Place
annotation = models.Annotation.objects.get(pk=id) a = models.Annotation.objects.get(pk=id)
for p in annotation.places.filter(defined=False): '''
for p in a.places.filter(defined=False):
if p.annotations.exclude(id=id).count() == 0: if p.annotations.exclude(id=id).count() == 0:
p.delete() p.delete()
if annotation.get_layer().get('type') == 'place' \ '''
and annotation.places.count() == 0: for p in a.places.all():
annotation.places.add(Place.get_or_create(annotation.value))
for p in annotation.places.all():
p.update_matches() p.update_matches()
ids = [e['id'] for e in Place.objects.all().values('id')] ids = [e['id'] for e in Place.objects.all().values('id')]
for i in ids: for i in ids:
e = Place.objects.get(pk=i) e = Place.objects.get(pk=i)
for name in [e.name] + list(e.alternativeNames): 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() e.update_matches()
break break
if a.get_layer().get('type') == 'place' \
and a.places.count() == 0:
a.places.add(Place.get_or_create(a.value))