rename
This commit is contained in:
parent
590c7c45ac
commit
d13f2f094c
4 changed files with 33 additions and 36 deletions
|
@ -13,12 +13,12 @@ import managers
|
|||
|
||||
def get_name_sort(name):
|
||||
person, created = Person.objects.get_or_create(name=name)
|
||||
name_sort = unicodedata.normalize('NFKD', person.name_sort)
|
||||
return name_sort
|
||||
sortname = unicodedata.normalize('NFKD', person.sortname)
|
||||
return sortname
|
||||
|
||||
class Person(models.Model):
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
name_sort = models.CharField(max_length=200)
|
||||
sortname = models.CharField(max_length=200)
|
||||
edited = models.BooleanField(default=False)
|
||||
numberofnames = models.IntegerField(default=0)
|
||||
|
||||
|
@ -34,9 +34,9 @@ class Person(models.Model):
|
|||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.name_sort:
|
||||
self.name_sort = ox.get_sort_name(self.name)
|
||||
self.name_sort = unicodedata.normalize('NFKD', self.name_sort)
|
||||
if not self.sortname:
|
||||
self.sortname = ox.get_sort_name(self.name)
|
||||
self.sortname = unicodedata.normalize('NFKD', self.sortname)
|
||||
self.numberofnames = len(self.name.split(' '))
|
||||
super(Person, self).save(*args, **kwargs)
|
||||
|
||||
|
@ -62,7 +62,7 @@ class Person(models.Model):
|
|||
j = {
|
||||
'id': self.get_id(),
|
||||
'name': self.name,
|
||||
'sortName': self.name_sort,
|
||||
'sortname': self.sortname,
|
||||
'numberofnames': self.numberofnames,
|
||||
}
|
||||
if keys:
|
||||
|
@ -74,10 +74,10 @@ class Person(models.Model):
|
|||
|
||||
def update_sort_name():
|
||||
for p in Person.objects.all():
|
||||
_name_sort = ox.get_sort_name(p.name)
|
||||
_name_sort = unicodedata.normalize('NFKD', _name_sort)
|
||||
if (not p.edited and _name_sort != p.name_sort) or \
|
||||
(p.edited and _name_sort == p.name_sort):
|
||||
p.name_sort = _name_sort
|
||||
_sortname = ox.get_sort_name(p.name)
|
||||
_sortname = unicodedata.normalize('NFKD', _sortname)
|
||||
if (not p.edited and _sortname != p.sortname) or \
|
||||
(p.edited and _sortname == p.sortname):
|
||||
p.sortname = _sortname
|
||||
p.edited = False
|
||||
p.save()
|
||||
|
|
|
@ -20,15 +20,15 @@ def editName(request):
|
|||
'''
|
||||
param data {
|
||||
'id': nameid,
|
||||
'sortName': ...
|
||||
'sortname': ...
|
||||
}
|
||||
can contain any of the allowed keys for name
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
person = get_object_or_404_json(models.Person, pk=ox.from26(data['id']))
|
||||
response = json_response()
|
||||
if 'sortName' in data:
|
||||
person.name_sort = utils.sort_string(data['sortName'])
|
||||
if 'sortname' in data:
|
||||
person.sortname = utils.sort_string(data['sortname'])
|
||||
person.edited = True
|
||||
person.save()
|
||||
response['data'] = person.json()
|
||||
|
@ -55,8 +55,6 @@ def order_query(qs, sort):
|
|||
if operator != '-':
|
||||
operator = ''
|
||||
key = {
|
||||
'name': 'name_sort',
|
||||
'sortName': 'name_sort',
|
||||
}.get(e['key'], e['key'])
|
||||
order = '%s%s' % (operator, key)
|
||||
order_by.append(order)
|
||||
|
@ -89,7 +87,7 @@ def findNames(request):
|
|||
name, numberofnames
|
||||
|
||||
possible keys:
|
||||
name, sortName, numberofnames
|
||||
name, sortname, numberofnames
|
||||
|
||||
return {
|
||||
status: {
|
||||
|
|
|
@ -12,12 +12,12 @@ import managers
|
|||
|
||||
def get_title_sort(title):
|
||||
title, created = Title.objects.get_or_create(title=title)
|
||||
title_sort = unicodedata.normalize('NFKD', title.title_sort)
|
||||
return title_sort
|
||||
sorttitle = unicodedata.normalize('NFKD', title.sorttitle)
|
||||
return sorttitle
|
||||
|
||||
class Title(models.Model):
|
||||
title = models.CharField(max_length=1000, unique=True)
|
||||
title_sort = models.CharField(max_length=1000)
|
||||
sorttitle = models.CharField(max_length=1000)
|
||||
edited = models.BooleanField(default=False)
|
||||
|
||||
imdbId = models.CharField(max_length=7, blank=True)
|
||||
|
@ -28,9 +28,9 @@ class Title(models.Model):
|
|||
return self.title
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.title_sort:
|
||||
self.title_sort = ox.get_sort_title(self.title)
|
||||
self.title_sort = unicodedata.normalize('NFKD', self.title_sort)
|
||||
if not self.sorttitle:
|
||||
self.sorttitle = ox.get_sort_title(self.title)
|
||||
self.sorttitle = unicodedata.normalize('NFKD', self.sorttitle)
|
||||
super(Title, self).save(*args, **kwargs)
|
||||
|
||||
def get_or_create(model, title, imdbId=None):
|
||||
|
@ -55,7 +55,7 @@ class Title(models.Model):
|
|||
j = {
|
||||
'id': self.get_id(),
|
||||
'title': self.title,
|
||||
'sortTitle': self.title_sort,
|
||||
'sorttitle': self.sorttitle,
|
||||
}
|
||||
if keys:
|
||||
for key in j.keys():
|
||||
|
@ -65,10 +65,10 @@ class Title(models.Model):
|
|||
|
||||
def update_sort_title():
|
||||
for t in Title.objects.all():
|
||||
_title_sort = ox.get_sort_title(t.title)
|
||||
_title_sort = unicodedata.normalize('NFKD', _title_sort)
|
||||
if (not t.edited and _title_sort != t.title_sort) or \
|
||||
(t.edited and _title_sort == t.title_sort):
|
||||
t.title_sort = _title_sort
|
||||
_sorttitle = ox.get_sort_title(t.title)
|
||||
_sorttitle = unicodedata.normalize('NFKD', _sorttitle)
|
||||
if (not t.edited and _sorttitle != t.sorttitle) or \
|
||||
(t.edited and _sorttitle == t.sorttitle):
|
||||
t.sorttitle = _sorttitle
|
||||
t.edited = False
|
||||
t.save()
|
||||
|
|
|
@ -21,16 +21,16 @@ def editTitle(request):
|
|||
'''
|
||||
param data {
|
||||
'id': titleid,
|
||||
'sortTitle': ...
|
||||
'sorttitle': ...
|
||||
}
|
||||
can contain any of the allowed keys for title
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
title = get_object_or_404_json(models.Title, pk=ox.from26(data['id']))
|
||||
response = json_response()
|
||||
if 'sortTitle' in data:
|
||||
title.title_sort = data['sortTitle']
|
||||
title.title_sort = unicodedata.normalize('NFKD', title.title_sort)
|
||||
if 'sorttitle' in data:
|
||||
title.sorttitle = data['sorttitle']
|
||||
title.sorttitle = unicodedata.normalize('NFKD', title.sorttitle)
|
||||
title.edited = True
|
||||
title.save()
|
||||
response['data'] = title.json()
|
||||
|
@ -57,7 +57,6 @@ def order_query(qs, sort):
|
|||
if operator != '-':
|
||||
operator = ''
|
||||
key = {
|
||||
'sortTitle': 'title_sort',
|
||||
}.get(e['key'], e['key'])
|
||||
order = '%s%s' % (operator, key)
|
||||
order_by.append(order)
|
||||
|
@ -90,7 +89,7 @@ def findTitles(request):
|
|||
title, numberoftitles
|
||||
|
||||
possible keys:
|
||||
title, sortTitle, numberoftitles
|
||||
title, sorttitle, numberoftitles
|
||||
|
||||
return {
|
||||
status: {
|
||||
|
|
Loading…
Reference in a new issue