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 archive import extract
|
||||||
from clip.models import Clip
|
from clip.models import Clip
|
||||||
|
|
||||||
import utils
|
|
||||||
import managers
|
import managers
|
||||||
|
import utils
|
||||||
|
from tasks import update_matching_events, update_matching_places
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_layers(layers):
|
def load_layers(layers):
|
||||||
|
@ -125,6 +128,9 @@ class Annotation(models.Model):
|
||||||
super(Annotation, self).save(*args, **kwargs)
|
super(Annotation, self).save(*args, **kwargs)
|
||||||
if set_public_id:
|
if set_public_id:
|
||||||
self.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):
|
def json(self, layer=False, keys=None):
|
||||||
j = {
|
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
|
|
@ -1,11 +1,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
from __future__ import division, with_statement
|
from __future__ import division, with_statement
|
||||||
import unicodedata
|
|
||||||
import string
|
|
||||||
|
|
||||||
from django.db import models
|
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
|
from django.db.models import Q
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
@ -16,6 +14,7 @@ from item.models import Item
|
||||||
from item import utils
|
from item import utils
|
||||||
from person.models import get_name_sort
|
from person.models import get_name_sort
|
||||||
from title.models import get_title_sort
|
from title.models import get_title_sort
|
||||||
|
|
||||||
import managers
|
import managers
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,18 @@ from datetime import timedelta
|
||||||
|
|
||||||
from celery.decorators import task, periodic_task
|
from celery.decorators import task, periodic_task
|
||||||
|
|
||||||
import models
|
from models import Event
|
||||||
|
|
||||||
|
|
||||||
@periodic_task(run_every=timedelta(days=1), queue='encoding')
|
@periodic_task(run_every=timedelta(days=1), queue='encoding')
|
||||||
def update_all_matches(**kwargs):
|
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:
|
for i in ids:
|
||||||
e = models.Event.objects.get(pk=i)
|
e = Event.objects.get(pk=i)
|
||||||
e.update_matches()
|
e.update_matches()
|
||||||
|
|
||||||
@task(ignore_resulsts=True, queue='default')
|
@task(ignore_resulsts=True, queue='default')
|
||||||
def update_matches(eventId):
|
def update_matches(eventId):
|
||||||
event = models.Event.objects.get(pk=eventId)
|
event = Event.objects.get(pk=eventId)
|
||||||
event.update_matches()
|
event.update_matches()
|
||||||
|
|
||||||
|
|
|
@ -18,3 +18,4 @@ def update_all_matches(**kwargs):
|
||||||
def update_matches(id):
|
def update_matches(id):
|
||||||
place = models.Place.objects.get(pk=id)
|
place = models.Place.objects.get(pk=id)
|
||||||
place.update_matches()
|
place.update_matches()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue