place/event matching task that could be used saving annotations
This commit is contained in:
parent
16d6c2c0fe
commit
dd8aee522c
5 changed files with 42 additions and 9 deletions
|
|
@ -9,8 +9,11 @@ import ox
|
|||
from archive import extract
|
||||
from clip.models import Clip
|
||||
|
||||
import utils
|
||||
|
||||
import managers
|
||||
import utils
|
||||
from tasks import update_matching_events, update_matching_places
|
||||
|
||||
|
||||
|
||||
def load_layers(layers):
|
||||
|
|
@ -104,7 +107,7 @@ class Annotation(models.Model):
|
|||
return utils.html_parser(self.value)
|
||||
else:
|
||||
return self.value
|
||||
|
||||
|
||||
def set_public_id(self):
|
||||
public_id = Annotation.objects.filter(item=self.item, id__lt=self.id).count()
|
||||
self.public_id = "%s/%s" % (self.item.itemId, ox.to26(public_id))
|
||||
|
|
@ -125,6 +128,9 @@ class Annotation(models.Model):
|
|||
super(Annotation, self).save(*args, **kwargs)
|
||||
if set_public_id:
|
||||
self.set_public_id()
|
||||
#how expensive is this?
|
||||
#update_matching_events.delay(self.value)
|
||||
#update_matching_places.delay(self.value)
|
||||
|
||||
def json(self, layer=False, keys=None):
|
||||
j = {
|
||||
|
|
|
|||
27
pandora/annotation/tasks.py
Normal file
27
pandora/annotation/tasks.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from celery.decorators import task
|
||||
|
||||
|
||||
|
||||
@task(ignore_resulsts=True, queue='default')
|
||||
def update_matching_events(value):
|
||||
from event.models import Event
|
||||
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:
|
||||
e.update_matches()
|
||||
break
|
||||
|
||||
@task(ignore_resulsts=True, queue='default')
|
||||
def update_matching_places(value):
|
||||
from place.models import Place
|
||||
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:
|
||||
e.update_matches()
|
||||
break
|
||||
Loading…
Add table
Add a link
Reference in a new issue