← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~j-corwin/openlp/bug-1085921 into lp:openlp/2.0

 

Jonathan Corwin has proposed merging lp:~j-corwin/openlp/bug-1085921 into lp:openlp/2.0.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1085921 in OpenLP: "Locale aware sorting has broken the song export form"
  https://bugs.launchpad.net/openlp/+bug/1085921

For more details, see:
https://code.launchpad.net/~j-corwin/openlp/bug-1085921/+merge/138868

Fix the song export. (2.0)
-- 
https://code.launchpad.net/~j-corwin/openlp/bug-1085921/+merge/138868
Your team OpenLP Core is requested to review the proposed merge of lp:~j-corwin/openlp/bug-1085921 into lp:openlp/2.0.
=== modified file 'openlp/plugins/songs/forms/songexportform.py'
--- openlp/plugins/songs/forms/songexportform.py	2012-11-11 21:16:14 +0000
+++ openlp/plugins/songs/forms/songexportform.py	2012-12-08 21:33:22 +0000
@@ -34,11 +34,11 @@
 
 from PyQt4 import QtCore, QtGui
 
-from openlp.core.lib import build_icon, Receiver, SettingsManager, translate, \
+from openlp.core.lib import build_icon, Receiver, translate, \
     create_separated_list
 from openlp.core.lib.ui import UiStrings, critical_error_message_box
 from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
-from openlp.core.utils import locale_direct_compare
+from openlp.plugins.songs.lib import natcmp
 from openlp.plugins.songs.lib.db import Song
 from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
 
@@ -253,8 +253,7 @@
         # Load the list of songs.
         Receiver.send_message(u'cursor_busy')
         songs = self.plugin.manager.get_all_objects(Song)
-        songs.sort(
-            cmp=locale_direct_compare, key=lambda song: song.sort_string)
+        songs.sort(cmp=natcmp, key=lambda song: song.sort_key)
         for song in songs:
             # No need to export temporary songs.
             if song.temporary:

=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py	2012-11-11 21:16:14 +0000
+++ openlp/plugins/songs/lib/__init__.py	2012-12-08 21:33:22 +0000
@@ -28,10 +28,10 @@
 ###############################################################################
 import re
 
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
 
 from openlp.core.lib import translate
-from openlp.core.utils import CONTROL_CHARS
+from openlp.core.utils import CONTROL_CHARS, locale_direct_compare
 from db import Author
 from ui import SongStrings
 
@@ -594,6 +594,40 @@
     text = u''.join(out)
     return text, default_encoding
 
+def natcmp(a, b):
+    """
+    Natural string comparison which mimics the behaviour of Python's internal
+    cmp function.
+    """
+    if len(a) <= len(b):
+        for i, key in enumerate(a):
+            if isinstance(key, int) and isinstance(b[i], int):
+                result = cmp(key, b[i])
+            elif isinstance(key, int) and not isinstance(b[i], int):
+                result = locale_direct_compare(QtCore.QString(str(key)), b[i])
+            elif not isinstance(key, int) and isinstance(b[i], int):
+                result = locale_direct_compare(key, QtCore.QString(str(b[i])))
+            else:
+                result = locale_direct_compare(key, b[i])
+            if result != 0:
+                return result
+        if len(a) == len(b):
+            return 0
+        else:
+            return -1
+    else:
+        for i, key in enumerate(b):
+            if isinstance(a[i], int) and isinstance(key, int):
+                result = cmp(a[i], key)
+            elif isinstance(a[i], int) and not isinstance(key, int):
+                result = locale_direct_compare(QtCore.QString(str(a[i])), key)
+            elif not isinstance(a[i], int) and isinstance(key, int):
+                result = locale_direct_compare(a[i], QtCore.QString(str(key)))
+            else:
+                result = locale_direct_compare(a[i], key)
+            if result != 0:
+                return result
+        return 1
 
 from xml import OpenLyrics, SongXML
 from songstab import SongsTab

=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2012-11-21 18:45:37 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2012-12-08 21:33:22 +0000
@@ -40,54 +40,17 @@
     check_directory_exists
 from openlp.core.lib.ui import UiStrings, create_widget_action
 from openlp.core.lib.settings import Settings
-from openlp.core.utils import AppLocation, locale_direct_compare
+from openlp.core.utils import AppLocation
 from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
     SongImportForm, SongExportForm
 from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
-    clean_string
+    clean_string, natcmp
 from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile
 from openlp.plugins.songs.lib.ui import SongStrings
 
 log = logging.getLogger(__name__)
 
 
-def natcmp(a, b):
-    """
-    Natural string comparison which mimics the behaviour of Python's internal
-    cmp function.
-    """
-    log.debug('a: %s; b: %s', a, b)
-    if len(a) <= len(b):
-        for i, key in enumerate(a):
-            if isinstance(key, int) and isinstance(b[i], int):
-                result = cmp(key, b[i])
-            elif isinstance(key, int) and not isinstance(b[i], int):
-                result = locale_direct_compare(QtCore.QString(str(key)), b[i])
-            elif not isinstance(key, int) and isinstance(b[i], int):
-                result = locale_direct_compare(key, QtCore.QString(str(b[i])))
-            else:
-                result = locale_direct_compare(key, b[i])
-            if result != 0:
-                return result
-        if len(a) == len(b):
-            return 0
-        else:
-            return -1
-    else:
-        for i, key in enumerate(b):
-            if isinstance(a[i], int) and isinstance(key, int):
-                result = cmp(a[i], key)
-            elif isinstance(a[i], int) and not isinstance(key, int):
-                result = locale_direct_compare(QtCore.QString(str(a[i])), key)
-            elif not isinstance(a[i], int) and isinstance(key, int):
-                result = locale_direct_compare(a[i], QtCore.QString(str(key)))
-            else:
-                result = locale_direct_compare(a[i], key)
-            if result != 0:
-                return result
-        return 1
-
-
 class SongSearch(object):
     """
     An enumeration for song search methods.


Follow ups