forked from openlp/openlp
Bug #687638: use locale aware comparison for songs by default.
This commit is contained in:
parent
7b608a948a
commit
2cc18a8fb4
@ -490,11 +490,11 @@ def format_time(text, local_time):
|
|||||||
|
|
||||||
def locale_compare(string1, string2):
|
def locale_compare(string1, string2):
|
||||||
"""
|
"""
|
||||||
Compares two strings according to the current QLocale settings.
|
Compares two strings according to the current locale settings.
|
||||||
|
|
||||||
As any other compare function, returns a negative, or a positive value,
|
As any other compare function, returns a negative, or a positive value,
|
||||||
or 0, depending on whether string1 collates before or after string2 or
|
or 0, depending on whether string1 collates before or after string2 or
|
||||||
is equal to it.
|
is equal to it. Comparison is case insensitive.
|
||||||
"""
|
"""
|
||||||
# Function locale.strcol() from standard Python library does not work
|
# Function locale.strcol() from standard Python library does not work
|
||||||
# properly on Windows and probably somewhere else.
|
# properly on Windows and probably somewhere else.
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
The :mod:`songexportform` module provides the wizard for exporting songs to the
|
The :mod:`songexportform` module provides the wizard for exporting songs to the
|
||||||
OpenLyrics format.
|
OpenLyrics format.
|
||||||
"""
|
"""
|
||||||
import locale
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
@ -252,7 +251,7 @@ class SongExportForm(OpenLPWizard):
|
|||||||
# Load the list of songs.
|
# Load the list of songs.
|
||||||
Receiver.send_message(u'cursor_busy')
|
Receiver.send_message(u'cursor_busy')
|
||||||
songs = self.plugin.manager.get_all_objects(Song)
|
songs = self.plugin.manager.get_all_objects(Song)
|
||||||
songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower())
|
songs.sort()
|
||||||
for song in songs:
|
for song in songs:
|
||||||
# No need to export temporary songs.
|
# No need to export temporary songs.
|
||||||
if song.temporary:
|
if song.temporary:
|
||||||
|
@ -35,6 +35,7 @@ from sqlalchemy.orm import mapper, relation
|
|||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
from openlp.core.lib.db import BaseModel, init_db
|
from openlp.core.lib.db import BaseModel, init_db
|
||||||
|
from openlp.core.utils import locale_compare
|
||||||
|
|
||||||
class Author(BaseModel):
|
class Author(BaseModel):
|
||||||
"""
|
"""
|
||||||
@ -63,7 +64,14 @@ class Song(BaseModel):
|
|||||||
"""
|
"""
|
||||||
Song model
|
Song model
|
||||||
"""
|
"""
|
||||||
pass
|
# By default sort the songs by its title considering language specific
|
||||||
|
# characters.
|
||||||
|
def __lt__(self, other):
|
||||||
|
r = locale_compare(self.title, other.title)
|
||||||
|
return True if r < 0 else False
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return 0 == locale_compare(self.title, other.title)
|
||||||
|
|
||||||
|
|
||||||
class Topic(BaseModel):
|
class Topic(BaseModel):
|
||||||
|
@ -39,7 +39,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
|
|||||||
check_directory_exists
|
check_directory_exists
|
||||||
from openlp.core.lib.ui import UiStrings, create_widget_action
|
from openlp.core.lib.ui import UiStrings, create_widget_action
|
||||||
from openlp.core.lib.settings import Settings
|
from openlp.core.lib.settings import Settings
|
||||||
from openlp.core.utils import AppLocation, locale_compare
|
from openlp.core.utils import AppLocation
|
||||||
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||||
SongImportForm, SongExportForm
|
SongImportForm, SongExportForm
|
||||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
|
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
|
||||||
@ -259,10 +259,7 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
log.debug(u'display results Song')
|
log.debug(u'display results Song')
|
||||||
self.saveAutoSelectId()
|
self.saveAutoSelectId()
|
||||||
self.listView.clear()
|
self.listView.clear()
|
||||||
# Sort the songs by its title considering language specific characters.
|
searchresults.sort()
|
||||||
# lower() is needed for windows!
|
|
||||||
searchresults.sort(
|
|
||||||
cmp=locale_compare, key=lambda song: song.title)
|
|
||||||
for song in searchresults:
|
for song in searchresults:
|
||||||
# Do not display temporary songs
|
# Do not display temporary songs
|
||||||
if song.temporary:
|
if song.temporary:
|
||||||
|
Loading…
Reference in New Issue
Block a user