diff --git a/pandora/item/models.py b/pandora/item/models.py index 721b25ca6..fc375676e 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -282,7 +282,10 @@ class Item(models.Model): data['releasedate'] = min(data.pop('release date')) if 'plot' in data: data['summary'] = data.pop('plot') - data['actor'] = [c[0] for c in data['cast']] + if isinstance(data['cast'][0], basestring): + data['actor'] = [data['cast'][0]] + else: + data['actor'] = [c[0] for c in data['cast']] self.external_data = data self.save() @@ -562,24 +565,23 @@ class Item(models.Model): if name not in base_keys: if field_type == 'title': value = utils.sort_title(canonicalTitle(self.get(name))) - value = unicodedata.normalize('NFKD', value) + value = utils.sort_string(value) setattr(s, '%s_desc'%name, value) if not value: value = 'zzzzzzzzzzzzzzzzzzzzzzzzz' setattr(s, name, value) elif field_type == 'person': value = sortNames(self.get(name, [])) - value = unicodedata.normalize('NFKD', value)[:255] + value = utils.sort_string(value)[:955] setattr(s, '%s_desc'%name, value) if not value: value = 'zzzzzzzzzzzzzzzzzzzzzzzzz' setattr(s, name, value) - elif field_type == 'text': - #FIXME: what use pural_key? + elif field_type == 'string': value = self.get(name, u'') if isinstance(value, list): value = u','.join(value) - value = unicodedata.normalize('NFKD', value) + value = utils.sort_string(value)[:955] setattr(s, '%s_desc'%name, value) if not value: value = 'zzzzzzzzzzzzzzzzzzzzzzzzz' @@ -896,15 +898,12 @@ attrs = { for key in site_config['sortKeys']: name = key['id'] 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['%s_desc'%name] = models.CharField(max_length=1000, db_index=True) elif field_type == 'year': attrs[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'): attrs[name] = models.BigIntegerField(blank=True, db_index=True) attrs['%s_desc'%name] = models.BigIntegerField(blank=True, db_index=True) diff --git a/pandora/item/utils.py b/pandora/item/utils.py index f1119cfd5..89aa21123 100644 --- a/pandora/item/utils.py +++ b/pandora/item/utils.py @@ -189,6 +189,11 @@ def parse_path(path): return r +def sort_string(string): + string = string.replace(u'Þ', 'Th') + return unicodedata.normalize('NFKD', string) + + def sort_title(title): #title title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title) @@ -196,9 +201,8 @@ def sort_title(title): #title = title.replace(u'Æ', 'Ae') if isinstance(title, str): title = unicode(title) - title = unicodedata.normalize('NFKD', title) + title = sort_string(title) #pad numbered titles title = re.sub('(\d+)', lambda x: '%010d' % int(x.group(0)), title) return title.strip() - diff --git a/pandora/templates/site.json b/pandora/templates/site.json index 456667a39..2e5407729 100644 --- a/pandora/templates/site.json +++ b/pandora/templates/site.json @@ -75,16 +75,16 @@ "sortKeys": [ {"id": "title", "title": "Title", "width": 180, "removable": false, "type": "title", "autocompleteSortKey": "votes"}, {"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": "language", "title": "Language", "width": 120, "type": "text"}, + {"id": "language", "title": "Language", "width": 120, "type": "string"}, {"id": "runtime", "title": "Runtime", "width": 60, "type": "integer"}, {"id": "writer", "title": "Writer", "width": 180, "type": "person"}, {"id": "producer", "title": "Producer", "width": 180, "type": "person"}, {"id": "cinematographer", "title": "Cinematographer", "width": 180, "type": "person"}, {"id": "editor", "title": "Editor", "width": 180, "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": "summary", "title": "Words in Summary", "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": "bitrate", "title": "Bitrate", "width": 90, "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": "modified", "title": "Date Modified", "width": 90, "type": "date"}, {"id": "popularity", "title": "Popularity", "type": "float"}