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