From 12fa7edb5317d252827b11896f256fd228458ff4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 18 Jul 2014 14:28:09 +0000 Subject: [PATCH] add annotationLanguages --- pandora/annotation/tasks.py | 2 ++ pandora/item/models.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/pandora/annotation/tasks.py b/pandora/annotation/tasks.py index c6c1f205..32111573 100644 --- a/pandora/annotation/tasks.py +++ b/pandora/annotation/tasks.py @@ -107,3 +107,5 @@ def update_item(id): a.item.update_find() a.item.update_sort() a.item.update_facets() + if a.item.update_languages(): + a.item.save() diff --git a/pandora/item/models.py b/pandora/item/models.py index ccb94590..89b33090 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -4,6 +4,7 @@ from __future__ import division, with_statement import json import os +import re import shutil import subprocess import tempfile @@ -402,6 +403,7 @@ class Item(models.Model): self.poster_height = 128 self.poster_width = 80 self.update_sort() + self.update_languages() self.json = self.get_json() self.json['modified'] = datetime.now() super(Item, self).save(*args, **kwargs) @@ -719,6 +721,20 @@ class Item(models.Model): Search related functions ''' + def update_languages(self): + languages = {} + for layer in settings.CONFIG['layers']: + l = layer['id'] + ll = [] + if self.annotations.filter(layer=l).count(): + ll.append(settings.CONFIG['language']) + for a in self.annotations.filter(layer=l, value__contains='lang="'): + ll += re.compile('lang="(.*?)"').findall(a.value) + languages[l] = sorted(set(ll)) + changed = languages != self.data.get('annotationLanguages') + self.data['annotationLanguages'] = languages + return changed + def update_find(self): def save(key, value):