update matching places/events

This commit is contained in:
j 2012-02-03 12:13:15 +05:30
parent 5ff0ff93f0
commit 041a272c4d
1 changed files with 18 additions and 14 deletions

View File

@ -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))