fix string in natural sort and move db

This commit is contained in:
Tim Bentley 2016-03-31 17:14:28 +01:00
parent b74221daff
commit 3693cf331d
5 changed files with 9 additions and 7 deletions

View File

@ -523,13 +523,15 @@ def get_locale_key(string):
def get_natural_key(string):
"""
Generate a key for locale aware natural string sorting.
:param string: string to be sorted by
Returns a list of string compare keys and integers.
"""
key = DIGITS_OR_NONDIGITS.findall(string)
key = [int(part) if part.isdigit() else get_locale_key(part) for part in key]
# Python 3 does not support comparison of different types anymore. So make sure, that we do not compare str
# and int.
if string[0].isdigit():
if string and string[0].isdigit():
return [b''] + key
return key

View File

@ -28,8 +28,8 @@ import logging
from sqlalchemy import Table, Column, ForeignKey, types
from sqlalchemy.sql.expression import func, false, null, text
from openlp.core.common.db import drop_columns
from openlp.core.lib.db import get_upgrade_op
from openlp.core.utils.db import drop_columns
log = logging.getLogger(__name__)
__version__ = 5

View File

View File

@ -22,17 +22,17 @@
"""
Package to test the openlp.core.utils.db package.
"""
from tempfile import mkdtemp
from unittest import TestCase
import gc
import os
import shutil
import sqlalchemy
import time
from tempfile import mkdtemp
from unittest import TestCase
from openlp.core.utils.db import drop_column, drop_columns
import sqlalchemy
from openlp.core.common.db import drop_column, drop_columns
from openlp.core.lib.db import init_db, get_upgrade_op
from tests.utils.constants import TEST_RESOURCES_PATH