← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/mediaitem-sorting into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/mediaitem-sorting into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/mediaitem-sorting/+merge/61786

Hello,

- Fixed custom slide sorting
- Tweaked songs sorting (The sorting (NOT the search) is now 5 times faster. However, difference is very small but it might feel snappier with very large databases. Anyway, do not take me by the word, maybe it is just 3 times faster.)

[1] http://wiki.python.org/moin/PythonSpeed#Use_the_best_algorithms_and_fastest_tools (Last point)
[2] http://www.velocityreviews.com/forums/t562832-sorting-objects-by-property-using-locale.htm
-- 
https://code.launchpad.net/~googol-hush/openlp/mediaitem-sorting/+merge/61786
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/mediaitem-sorting into lp:openlp.
=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
--- openlp/plugins/custom/lib/mediaitem.py	2011-05-19 04:48:10 +0000
+++ openlp/plugins/custom/lib/mediaitem.py	2011-05-20 15:28:46 +0000
@@ -25,6 +25,8 @@
 ###############################################################################
 
 import logging
+import locale
+import operator
 
 from PyQt4 import QtCore, QtGui
 from sqlalchemy.sql import or_, func
@@ -133,12 +135,15 @@
             self.onPreviewClick()
         self.onRemoteEditClear()
 
-    def loadList(self, list):
+    def loadList(self, custom_slides):
         self.listView.clear()
-        for customSlide in list:
-            custom_name = QtGui.QListWidgetItem(customSlide.title)
+        # Sort the customs by its title considering language specific
+        # characters.
+        custom_slides.sort(cmp=locale.strcoll, key=operator.attrgetter('title'))
+        for custom_slide in custom_slides:
+            custom_name = QtGui.QListWidgetItem(custom_slide.title)
             custom_name.setData(
-                QtCore.Qt.UserRole, QtCore.QVariant(customSlide.id))
+                QtCore.Qt.UserRole, QtCore.QVariant(custom_slide.id))
             self.listView.addItem(custom_name)
 
     def onNewClick(self):

=== modified file 'openlp/plugins/presentations/lib/mediaitem.py'
--- openlp/plugins/presentations/lib/mediaitem.py	2011-05-15 20:03:45 +0000
+++ openlp/plugins/presentations/lib/mediaitem.py	2011-05-20 15:28:46 +0000
@@ -149,20 +149,18 @@
         else:
             self.presentationWidget.hide()
 
-    def loadList(self, list, initialLoad=False):
+    def loadList(self, files, initialLoad=False):
         """
         Add presentations into the media manager
         This is called both on initial load of the plugin to populate with
         existing files, and when the user adds new files via the media manager
         """
         currlist = self.getFileList()
-        titles = []
-        for file in currlist:
-            titles.append(os.path.split(file)[1])
+        titles = [os.path.split(file)[1] for file in currlist]
         Receiver.send_message(u'cursor_busy')
         if not initialLoad:
-            self.parent.formparent.displayProgressBar(len(list))
-        for file in list:
+            self.parent.formparent.displayProgressBar(len(files))
+        for file in files:
             if not initialLoad:
                 self.parent.formparent.incrementProgressBar()
             if currlist.count(file) > 0:

=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2011-05-19 04:42:10 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2011-05-20 15:28:46 +0000
@@ -26,6 +26,7 @@
 
 import logging
 import locale
+import operator
 
 from PyQt4 import QtCore, QtGui
 from sqlalchemy.sql import or_
@@ -229,7 +230,8 @@
     def displayResultsSong(self, searchresults):
         log.debug(u'display results Song')
         self.listView.clear()
-        searchresults.sort(cmp=self.collateSongTitles)
+        # Sort the songs by its title considering language specific characters.
+        searchresults.sort(cmp=locale.strcoll, key=operator.attrgetter('title'))
         for song in searchresults:
             author_list = [author.display_name for author in song.authors]
             song_title = unicode(song.title)
@@ -472,13 +474,6 @@
             Receiver.send_message(u'service_item_update',
                 u'%s:%s' % (editId, item._uuid))
 
-    def collateSongTitles(self, song_1, song_2):
-        """
-        Locale aware collation of song titles
-        """
-        return locale.strcoll(unicode(song_1.title.lower()),
-             unicode(song_2.title.lower()))
-
     def search(self, string):
         """
         Search for some songs


Follow ups