From dd8aee522c81e4144aebec425b3aabda3074d458 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 27 Oct 2011 10:44:05 +0200 Subject: [PATCH] place/event matching task that could be used saving annotations --- pandora/annotation/models.py | 10 ++++++++-- pandora/annotation/tasks.py | 27 +++++++++++++++++++++++++++ pandora/event/models.py | 5 ++--- pandora/event/tasks.py | 8 ++++---- pandora/place/tasks.py | 1 + 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 pandora/annotation/tasks.py diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index b6d8cce5..d9372b56 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -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 = { diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py new file mode 100644 index 00000000..0a7c28e5 --- /dev/null +++ b/pandora/annotation/tasks.py @@ -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 diff --git a/pandora/event/models.py b/pandora/event/models.py index 3c02c186..ca4ebc0c 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -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 diff --git a/pandora/event/tasks.py b/pandora/event/tasks.py index b38a257b..bc1fbd0d 100644 --- a/pandora/event/tasks.py +++ b/pandora/event/tasks.py @@ -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() diff --git a/pandora/place/tasks.py b/pandora/place/tasks.py index dc23ea7f..7f27e380 100644 --- a/pandora/place/tasks.py +++ b/pandora/place/tasks.py @@ -18,3 +18,4 @@ def update_all_matches(**kwargs): def update_matches(id): place = models.Place.objects.get(pk=id) place.update_matches() +