place/event matching task that could be used saving annotations

This commit is contained in:
j 2011-10-27 10:44:05 +02:00
parent 16d6c2c0fe
commit dd8aee522c
5 changed files with 42 additions and 9 deletions

View file

@ -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):
@ -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 = {

View 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

View file

@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, with_statement
import unicodedata
import string
from django.db import models
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import User
from django.db.models import Q
import ox
@ -16,6 +14,7 @@ from item.models import Item
from item import utils
from person.models import get_name_sort
from title.models import get_title_sort
import managers

View file

@ -4,18 +4,18 @@ from datetime import timedelta
from celery.decorators import task, periodic_task
import models
from models import Event
@periodic_task(run_every=timedelta(days=1), queue='encoding')
def update_all_matches(**kwargs):
ids = [e['id'] for e in models.Event.objects.all().values('id')]
ids = [e['id'] for e in Event.objects.all().values('id')]
for i in ids:
e = models.Event.objects.get(pk=i)
e = Event.objects.get(pk=i)
e.update_matches()
@task(ignore_resulsts=True, queue='default')
def update_matches(eventId):
event = models.Event.objects.get(pk=eventId)
event = Event.objects.get(pk=eventId)
event.update_matches()

View file

@ -18,3 +18,4 @@ def update_all_matches(**kwargs):
def update_matches(id):
place = models.Place.objects.get(pk=id)
place.update_matches()