title refinement

This commit is contained in:
j 2011-10-11 21:05:11 +02:00
parent 04acc3c6f3
commit 2692300f3b
5 changed files with 19 additions and 10 deletions

View file

@ -619,7 +619,7 @@ class Item(models.Model):
if name not in base_keys: if name not in base_keys:
if sort_type == 'title': if sort_type == 'title':
value = get_title_sort(self.get(source, u'Untitled')) value = get_title_sort(self.get(source, u'Untitled'))
value = utils.sort_string(value)[:955] value = utils.sort_title(value)[:955]
set_value(s, name, value) set_value(s, name, value)
elif sort_type == 'person': elif sort_type == 'person':
value = sortNames(self.get(source, [])) value = sortNames(self.get(source, []))

View file

@ -201,14 +201,14 @@ def sort_string(string):
def sort_title(title): def sort_title(title):
#title
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', 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 = sort_string(title) title = sort_string(title)
#title
title = re.sub(u'[\'!¿¡,\.;\-"\:\*\[\]]', '', title)
return title.strip() return title.strip()
def get_positions(ids, pos): def get_positions(ids, pos):

View file

@ -15,9 +15,12 @@ import managers
def get_name_sort(name): def get_name_sort(name):
name = unicodedata.normalize('NFKD', name) name = unicodedata.normalize('NFKD', name).strip()
person, created = Person.objects.get_or_create(name=name) if name:
sortname = unicodedata.normalize('NFKD', person.sortname) person, created = Person.objects.get_or_create(name=name)
sortname = unicodedata.normalize('NFKD', person.sortname)
else:
sortname = u''
return sortname return sortname
class Person(models.Model): class Person(models.Model):

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
import unicodedata
from django.db.models import Q, Manager from django.db.models import Q, Manager
from ox.django.query import QuerySet from ox.django.query import QuerySet
import ox import ox
@ -41,6 +42,8 @@ def parseCondition(condition, user):
return q return q
if k == 'id': if k == 'id':
v = ox.from26(v) v = ox.from26(v)
elif isinstance(v, unicode):
v = unicodedata.normalize('NFKD', v)
if isinstance(v, bool): #featured and public flag if isinstance(v, bool): #featured and public flag
key = k key = k
elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', 'id'): elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', 'id'):

View file

@ -13,9 +13,12 @@ from item import utils
import managers import managers
def get_title_sort(title): def get_title_sort(title):
title = unicodedata.normalize('NFKD', title) title = unicodedata.normalize('NFKD', title).strip()
title, created = Title.objects.get_or_create(title=title) if title:
sorttitle = unicodedata.normalize('NFKD', title.sorttitle) title, created = Title.objects.get_or_create(title=title)
sorttitle = unicodedata.normalize('NFKD', title.sorttitle)
else:
sorttitle = u''
return sorttitle return sorttitle
class Title(models.Model): class Title(models.Model):
@ -35,7 +38,7 @@ class Title(models.Model):
if not self.sorttitle: if not self.sorttitle:
self.sorttitle = ox.get_sort_title(self.title) self.sorttitle = ox.get_sort_title(self.title)
self.sorttitle = unicodedata.normalize('NFKD', self.sorttitle) self.sorttitle = unicodedata.normalize('NFKD', self.sorttitle)
self.sortsorttitle = utils.sort_string(self.sorttitle) self.sortsorttitle = utils.sort_title(self.sorttitle)
super(Title, self).save(*args, **kwargs) super(Title, self).save(*args, **kwargs)
def get_or_create(model, title, imdbId=None): def get_or_create(model, title, imdbId=None):