fix sort for empty strings, fixes #167

This commit is contained in:
j 2016-01-20 12:16:46 +05:30
parent 18e15fbaf0
commit 9e7dcf75a8
3 changed files with 24 additions and 27 deletions

View file

@ -187,6 +187,8 @@ class Item(db.Model):
value = ox.sort_string(value).lower() value = ox.sort_string(value).lower()
elif isinstance(value, list): #empty list elif isinstance(value, list): #empty list
value = None value = None
if not value and sort_type != 'boolean':
value = None
if getattr(s, key['id']) != value: if getattr(s, key['id']) != value:
setattr(s, key['id'], value) setattr(s, key['id'], value)
update = True update = True

View file

@ -101,4 +101,4 @@ USER_AGENT = 'OpenMediaLibrary/%s' % VERSION
DEBUG_HTTP = server.get('debug_http', False) DEBUG_HTTP = server.get('debug_http', False)
DB_VERSION = 5 DB_VERSION = 6

View file

@ -295,16 +295,14 @@ class Update(Thread):
db_version = settings.server.get('db_version', 0) db_version = settings.server.get('db_version', 0)
if db_version < settings.DB_VERSION: if db_version < settings.DB_VERSION:
self.status('Updating...') self.status('Updating...')
if db_version < 1:
db_version = migrate_1()
if db_version < 2:
db_version = migrate_2()
if db_version < 3: if db_version < 3:
db_version = migrate_3() db_version = migrate_3()
if db_version < 4: if db_version < 4:
db_version = migrate_4() db_version = migrate_4()
if db_version < 5: if db_version < 5:
db_version = migrate_5() db_version = migrate_5()
if db_version < 6:
db_version = migrate_6()
settings.server['db_version'] = settings.DB_VERSION settings.server['db_version'] = settings.DB_VERSION
def run(self): def run(self):
@ -317,28 +315,6 @@ class Update(Thread):
restart_oml() restart_oml()
def migrate_1():
with db.session() as session:
import item.models
for s in item.models.Sort.query.filter_by(author=''):
s.item.update_sort()
session.commit()
return 1
def migrate_2():
with db.session() as session:
import item.models
for s in item.models.Sort.query.filter_by(author=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(publisher=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(language=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(place=''):
s.item.update_sort()
session.commit()
return 2
def migrate_3(): def migrate_3():
with db.session(): with db.session():
import item.models import item.models
@ -412,3 +388,22 @@ def migrate_5():
for i in item.models.Item.query: for i in item.models.Item.query:
i.sync_metadata() i.sync_metadata()
return 5 return 5
def migrate_6():
with db.session() as session:
import item.models
for s in item.models.Sort.query.filter_by(author=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(publisher=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(language=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(place=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(isbn=''):
s.item.update_sort()
for s in item.models.Sort.query.filter_by(date=''):
s.item.update_sort()
session.commit()
return 6