add sortvalue to annotations to get better sort by text results
This commit is contained in:
parent
a960a7bd18
commit
7eeb6dc107
4 changed files with 9 additions and 5 deletions
|
@ -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):
|
||||
|
|
|
@ -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:'):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue