forked from 0x2620/pandora
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 archive import extract
|
||||||
from clip.models import Clip
|
from clip.models import Clip
|
||||||
|
|
||||||
|
from item.utils import sort_string
|
||||||
import managers
|
import managers
|
||||||
import utils
|
import utils
|
||||||
from tasks import update_matching_events, update_matching_places
|
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)
|
layer = models.CharField(max_length=255, db_index=True)
|
||||||
value = models.TextField()
|
value = models.TextField()
|
||||||
|
sortvalue = models.CharField(max_length=1000, null=True, blank=True, db_index=True)
|
||||||
|
|
||||||
def editable(self, user):
|
def editable(self, user):
|
||||||
if user.is_authenticated():
|
if user.is_authenticated():
|
||||||
|
@ -57,6 +58,9 @@ class Annotation(models.Model):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
set_public_id = not self.id or not self.public_id
|
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
|
#no clip or update clip
|
||||||
def get_layer(id):
|
def get_layer(id):
|
||||||
|
|
|
@ -35,14 +35,14 @@ def order_query(qs, sort):
|
||||||
if operator != '-':
|
if operator != '-':
|
||||||
operator = ''
|
operator = ''
|
||||||
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
clip_keys = ('public_id', 'start', 'end', 'hue', 'saturation', 'lightness', 'volume',
|
||||||
'annotations__value', 'videoRatio',
|
'annotations__sortvalue', 'videoRatio',
|
||||||
'director', 'title')
|
'director', 'title')
|
||||||
key = {
|
key = {
|
||||||
'id': 'public_id',
|
'id': 'public_id',
|
||||||
'in': 'start',
|
'in': 'start',
|
||||||
'out': 'end',
|
'out': 'end',
|
||||||
'position': 'start',
|
'position': 'start',
|
||||||
'text': 'annotations__value',
|
'text': 'annotations__sortvalue',
|
||||||
'videoRatio': 'aspect_ratio',
|
'videoRatio': 'aspect_ratio',
|
||||||
}.get(e['key'], e['key'])
|
}.get(e['key'], e['key'])
|
||||||
if key.startswith('clip:'):
|
if key.startswith('clip:'):
|
||||||
|
|
|
@ -21,7 +21,8 @@ def plural_key(term):
|
||||||
|
|
||||||
|
|
||||||
def sort_string(string):
|
def sort_string(string):
|
||||||
string = string.replace(u'Þ', 'Th')
|
string = string.replace(u'Æ', 'AE').replace(u'Ø', 'O').replace(u'Þ', 'Th')
|
||||||
|
|
||||||
#pad numbered titles
|
#pad numbered titles
|
||||||
string = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), string)
|
string = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), string)
|
||||||
return unicodedata.normalize('NFKD', string)
|
return unicodedata.normalize('NFKD', string)
|
||||||
|
|
|
@ -48,7 +48,6 @@ class Person(models.Model):
|
||||||
if not self.sortname:
|
if not self.sortname:
|
||||||
self.sortname = ox.get_sort_name(self.name)
|
self.sortname = ox.get_sort_name(self.name)
|
||||||
self.sortname = unicodedata.normalize('NFKD', self.sortname)
|
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.sortsortname = utils.sort_string(self.sortname)
|
||||||
self.numberofnames = len(self.name.split(' '))
|
self.numberofnames = len(self.name.split(' '))
|
||||||
super(Person, self).save(*args, **kwargs)
|
super(Person, self).save(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue