From 7eeb6dc1078a0587076b583f949a091eef267906 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 3 Nov 2011 12:31:46 +0100 Subject: [PATCH] add sortvalue to annotations to get better sort by text results --- pandora/annotation/models.py | 6 +++++- pandora/clip/views.py | 4 ++-- pandora/item/utils.py | 3 ++- pandora/person/models.py | 1 - 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index bcf215ce8..8a7d687e5 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -10,7 +10,7 @@ import ox from archive import extract from clip.models import Clip - +from item.utils import sort_string import managers import utils from tasks import update_matching_events, update_matching_places @@ -34,6 +34,7 @@ class Annotation(models.Model): layer = models.CharField(max_length=255, db_index=True) value = models.TextField() + sortvalue = models.CharField(max_length=1000, null=True, blank=True, db_index=True) def editable(self, user): if user.is_authenticated(): @@ -57,6 +58,9 @@ class Annotation(models.Model): def save(self, *args, **kwargs): set_public_id = not self.id or not self.public_id + self.sortvalue = None + if self.value.strip(): + self.sortvalue = sort_string(self.value)[:1000] #no clip or update clip def get_layer(id): diff --git a/pandora/clip/views.py b/pandora/clip/views.py index f0b8516b2..39f27d69c 100644 --- a/pandora/clip/views.py +++ b/pandora/clip/views.py @@ -35,14 +35,14 @@ def order_query(qs, sort): if operator != '-': operator = '' clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume', - 'annotations__value', 'videoRatio', + 'annotations__sortvalue', 'videoRatio', 'director', 'title') key = { 'id': 'public_id', 'in': 'start', 'out': 'end', 'position': 'start', - 'text': 'annotations__value', + 'text': 'annotations__sortvalue', 'videoRatio': 'aspect_ratio', }.get(e['key'], e['key']) if key.startswith('clip:'): diff --git a/pandora/item/utils.py b/pandora/item/utils.py index 6c89914a5..fd7ae32ca 100644 --- a/pandora/item/utils.py +++ b/pandora/item/utils.py @@ -21,7 +21,8 @@ def plural_key(term): def sort_string(string): - string = string.replace(u'Þ', 'Th') + string = string.replace(u'Æ', 'AE').replace(u'Ø', 'O').replace(u'Þ', 'Th') + #pad numbered titles string = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), string) return unicodedata.normalize('NFKD', string) diff --git a/pandora/person/models.py b/pandora/person/models.py index 23b425be4..275c6f28a 100644 --- a/pandora/person/models.py +++ b/pandora/person/models.py @@ -48,7 +48,6 @@ class Person(models.Model): if not self.sortname: self.sortname = ox.get_sort_name(self.name) self.sortname = unicodedata.normalize('NFKD', self.sortname) - self.sortname = self.sortname.replace(u'Æ', 'AE').replace(u'Ø', 'O').replace(u'Þ', 'P') self.sortsortname = utils.sort_string(self.sortname) self.numberofnames = len(self.name.split(' ')) super(Person, self).save(*args, **kwargs)