entity sort name

This commit is contained in:
j 2014-12-16 17:44:05 +00:00
parent d5ae7245c2
commit 34506d5b99
2 changed files with 5 additions and 2 deletions

View file

@ -48,7 +48,7 @@ class Entity(models.Model):
if entity.get('sortType') == 'person' and self.name: if entity.get('sortType') == 'person' and self.name:
self.name_sort = get_name_sort(self.name)[:255].lower() self.name_sort = get_name_sort(self.name)[:255].lower()
else: else:
self.name_sort = ox.sort_string(self.name or u'')[:255].lower() self.name_sort = ox.sort_string(self.name or u'')[:255].lower() or None
self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||' self.name_find = '||' + self.name + '||'.join(self.alternativeNames) + '||'
super(Entity, self).save(*args, **kwargs) super(Entity, self).save(*args, **kwargs)
self.update_matches() self.update_matches()
@ -123,6 +123,7 @@ class Entity(models.Model):
'editable', 'editable',
'id', 'id',
'name', 'name',
'sortName',
'type', 'type',
'user', 'user',
] + self.data.keys() ] + self.data.keys()
@ -136,6 +137,8 @@ class Entity(models.Model):
response[key] = self.user and self.user.username response[key] = self.user and self.user.username
elif key in ('name', 'alternativeNames', 'type'): elif key in ('name', 'alternativeNames', 'type'):
response[key] = getattr(self, key) response[key] = getattr(self, key)
elif key == 'sortName':
response[key] = self.name_sort
elif key in self.data: elif key in self.data:
response[key] = self.data[key] response[key] = self.data[key]
return response return response

View file

@ -184,7 +184,7 @@ def _order_query(qs, sort, item=None):
def parse_query(data, user): def parse_query(data, user):
query = {} query = {}
query['range'] = [0, 100] query['range'] = [0, 100]
query['sort'] = [{'key':'name', 'operator':'+'}, {'key':'type', 'operator':'+'}] query['sort'] = [{'key':'name', 'operator':'+'}]
for key in ('keys', 'group', 'range', 'position', 'positions', 'sort'): for key in ('keys', 'group', 'range', 'position', 'positions', 'sort'):
if key in data: if key in data:
query[key] = data[key] query[key] = data[key]