add annotationLanguages

This commit is contained in:
j 2014-07-18 14:28:09 +00:00
parent 139348b0d3
commit 12fa7edb53
2 changed files with 18 additions and 0 deletions

View file

@ -107,3 +107,5 @@ def update_item(id):
a.item.update_find() a.item.update_find()
a.item.update_sort() a.item.update_sort()
a.item.update_facets() a.item.update_facets()
if a.item.update_languages():
a.item.save()

View file

@ -4,6 +4,7 @@ from __future__ import division, with_statement
import json import json
import os import os
import re
import shutil import shutil
import subprocess import subprocess
import tempfile import tempfile
@ -402,6 +403,7 @@ class Item(models.Model):
self.poster_height = 128 self.poster_height = 128
self.poster_width = 80 self.poster_width = 80
self.update_sort() self.update_sort()
self.update_languages()
self.json = self.get_json() self.json = self.get_json()
self.json['modified'] = datetime.now() self.json['modified'] = datetime.now()
super(Item, self).save(*args, **kwargs) super(Item, self).save(*args, **kwargs)
@ -719,6 +721,20 @@ class Item(models.Model):
Search related functions 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 update_find(self):
def save(key, value): def save(key, value):