forked from 0x2620/pandora
sort cleanup
This commit is contained in:
parent
a14999110c
commit
f82a18587f
3 changed files with 19 additions and 16 deletions
|
@ -282,6 +282,9 @@ class Item(models.Model):
|
||||||
data['releasedate'] = min(data.pop('release date'))
|
data['releasedate'] = min(data.pop('release date'))
|
||||||
if 'plot' in data:
|
if 'plot' in data:
|
||||||
data['summary'] = data.pop('plot')
|
data['summary'] = data.pop('plot')
|
||||||
|
if isinstance(data['cast'][0], basestring):
|
||||||
|
data['actor'] = [data['cast'][0]]
|
||||||
|
else:
|
||||||
data['actor'] = [c[0] for c in data['cast']]
|
data['actor'] = [c[0] for c in data['cast']]
|
||||||
self.external_data = data
|
self.external_data = data
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -562,24 +565,23 @@ class Item(models.Model):
|
||||||
if name not in base_keys:
|
if name not in base_keys:
|
||||||
if field_type == 'title':
|
if field_type == 'title':
|
||||||
value = utils.sort_title(canonicalTitle(self.get(name)))
|
value = utils.sort_title(canonicalTitle(self.get(name)))
|
||||||
value = unicodedata.normalize('NFKD', value)
|
value = utils.sort_string(value)
|
||||||
setattr(s, '%s_desc'%name, value)
|
setattr(s, '%s_desc'%name, value)
|
||||||
if not value:
|
if not value:
|
||||||
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
||||||
setattr(s, name, value)
|
setattr(s, name, value)
|
||||||
elif field_type == 'person':
|
elif field_type == 'person':
|
||||||
value = sortNames(self.get(name, []))
|
value = sortNames(self.get(name, []))
|
||||||
value = unicodedata.normalize('NFKD', value)[:255]
|
value = utils.sort_string(value)[:955]
|
||||||
setattr(s, '%s_desc'%name, value)
|
setattr(s, '%s_desc'%name, value)
|
||||||
if not value:
|
if not value:
|
||||||
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
||||||
setattr(s, name, value)
|
setattr(s, name, value)
|
||||||
elif field_type == 'text':
|
elif field_type == 'string':
|
||||||
#FIXME: what use pural_key?
|
|
||||||
value = self.get(name, u'')
|
value = self.get(name, u'')
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = u','.join(value)
|
value = u','.join(value)
|
||||||
value = unicodedata.normalize('NFKD', value)
|
value = utils.sort_string(value)[:955]
|
||||||
setattr(s, '%s_desc'%name, value)
|
setattr(s, '%s_desc'%name, value)
|
||||||
if not value:
|
if not value:
|
||||||
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
value = 'zzzzzzzzzzzzzzzzzzzzzzzzz'
|
||||||
|
@ -896,15 +898,12 @@ attrs = {
|
||||||
for key in site_config['sortKeys']:
|
for key in site_config['sortKeys']:
|
||||||
name = key['id']
|
name = key['id']
|
||||||
field_type = key['type']
|
field_type = key['type']
|
||||||
if field_type in ('string', 'title'):
|
if field_type in ('string', 'title', 'person'):
|
||||||
attrs[name] = models.CharField(max_length=1000, db_index=True)
|
attrs[name] = models.CharField(max_length=1000, db_index=True)
|
||||||
attrs['%s_desc'%name] = models.CharField(max_length=1000, db_index=True)
|
attrs['%s_desc'%name] = models.CharField(max_length=1000, db_index=True)
|
||||||
elif field_type == 'year':
|
elif field_type == 'year':
|
||||||
attrs[name] = models.CharField(max_length=4, db_index=True)
|
attrs[name] = models.CharField(max_length=4, db_index=True)
|
||||||
attrs['%s_desc'%name] = models.CharField(max_length=4, db_index=True)
|
attrs['%s_desc'%name] = models.CharField(max_length=4, db_index=True)
|
||||||
elif field_type in ('text', 'person'):
|
|
||||||
attrs[name] = models.TextField(blank=True, db_index=True)
|
|
||||||
attrs['%s_desc'%name] = models.TextField(blank=True, db_index=True)
|
|
||||||
elif field_type in ('integer', 'words', 'length'):
|
elif field_type in ('integer', 'words', 'length'):
|
||||||
attrs[name] = models.BigIntegerField(blank=True, db_index=True)
|
attrs[name] = models.BigIntegerField(blank=True, db_index=True)
|
||||||
attrs['%s_desc'%name] = models.BigIntegerField(blank=True, db_index=True)
|
attrs['%s_desc'%name] = models.BigIntegerField(blank=True, db_index=True)
|
||||||
|
|
|
@ -189,6 +189,11 @@ def parse_path(path):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
def sort_string(string):
|
||||||
|
string = string.replace(u'Þ', 'Th')
|
||||||
|
return unicodedata.normalize('NFKD', string)
|
||||||
|
|
||||||
|
|
||||||
def sort_title(title):
|
def sort_title(title):
|
||||||
#title
|
#title
|
||||||
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
|
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
|
||||||
|
@ -196,9 +201,8 @@ def sort_title(title):
|
||||||
#title = title.replace(u'Æ', 'Ae')
|
#title = title.replace(u'Æ', 'Ae')
|
||||||
if isinstance(title, str):
|
if isinstance(title, str):
|
||||||
title = unicode(title)
|
title = unicode(title)
|
||||||
title = unicodedata.normalize('NFKD', title)
|
title = sort_string(title)
|
||||||
|
|
||||||
#pad numbered titles
|
#pad numbered titles
|
||||||
title = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), title)
|
title = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), title)
|
||||||
return title.strip()
|
return title.strip()
|
||||||
|
|
||||||
|
|
|
@ -75,16 +75,16 @@
|
||||||
"sortKeys": [
|
"sortKeys": [
|
||||||
{"id": "title", "title": "Title", "width": 180, "removable": false, "type": "title", "autocompleteSortKey": "votes"},
|
{"id": "title", "title": "Title", "width": 180, "removable": false, "type": "title", "autocompleteSortKey": "votes"},
|
||||||
{"id": "director", "title": "Director", "width": 180, "removable": false, "type": "person"},
|
{"id": "director", "title": "Director", "width": 180, "removable": false, "type": "person"},
|
||||||
{"id": "country", "title": "Country", "width": 120, "type": "text"},
|
{"id": "country", "title": "Country", "width": 120, "type": "string"},
|
||||||
{"id": "year", "title": "Year", "width": 60, "type": "year"},
|
{"id": "year", "title": "Year", "width": 60, "type": "year"},
|
||||||
{"id": "language", "title": "Language", "width": 120, "type": "text"},
|
{"id": "language", "title": "Language", "width": 120, "type": "string"},
|
||||||
{"id": "runtime", "title": "Runtime", "width": 60, "type": "integer"},
|
{"id": "runtime", "title": "Runtime", "width": 60, "type": "integer"},
|
||||||
{"id": "writer", "title": "Writer", "width": 180, "type": "person"},
|
{"id": "writer", "title": "Writer", "width": 180, "type": "person"},
|
||||||
{"id": "producer", "title": "Producer", "width": 180, "type": "person"},
|
{"id": "producer", "title": "Producer", "width": 180, "type": "person"},
|
||||||
{"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"},
|
{"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"},
|
||||||
{"id": "editor", "title": "Editor", "width": 180, "type": "person"},
|
{"id": "editor", "title": "Editor", "width": 180, "type": "person"},
|
||||||
{"id": "actor", "title": "Number of Actors", "width": 60, "type": "person"},
|
{"id": "actor", "title": "Number of Actors", "width": 60, "type": "person"},
|
||||||
{"id": "genre", "title": "Genre", "width": 120, "type": "text"},
|
{"id": "genre", "title": "Genre", "width": 120, "type": "string"},
|
||||||
{"id": "keyword", "title": "Number of Keywords", "width": 60, "type": "integer"},
|
{"id": "keyword", "title": "Number of Keywords", "width": 60, "type": "integer"},
|
||||||
{"id": "summary", "title": "Words in Summary", "width": 60, "type": "words"},
|
{"id": "summary", "title": "Words in Summary", "width": 60, "type": "words"},
|
||||||
{"id": "trivia", "title": "Words in Trivia", "width": 60, "type": "words"},
|
{"id": "trivia", "title": "Words in Trivia", "width": 60, "type": "words"},
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
{"id": "size", "title": "Size", "width": 90, "type": "integer"},
|
{"id": "size", "title": "Size", "width": 90, "type": "integer"},
|
||||||
{"id": "bitrate", "title": "Bitrate", "width": 90, "type": "integer"},
|
{"id": "bitrate", "title": "Bitrate", "width": 90, "type": "integer"},
|
||||||
{"id": "files", "title": "Files", "width": 60, "type": "integer"},
|
{"id": "files", "title": "Files", "width": 60, "type": "integer"},
|
||||||
{"id": "filename", "title": "Filename", "width": 180, "type": "text"},
|
{"id": "filename", "title": "Filename", "width": 180, "type": "string"},
|
||||||
{"id": "published", "title": "Date Published", "width": 90, "type": "date"},
|
{"id": "published", "title": "Date Published", "width": 90, "type": "date"},
|
||||||
{"id": "modified", "title": "Date Modified", "width": 90, "type": "date"},
|
{"id": "modified", "title": "Date Modified", "width": 90, "type": "date"},
|
||||||
{"id": "popularity", "title": "Popularity", "type": "float"}
|
{"id": "popularity", "title": "Popularity", "type": "float"}
|
||||||
|
|
Loading…
Reference in a new issue