[gnome-music] ORDER BY statements generated by order_by_statement function, nested if statements to ignore multipl
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] ORDER BY statements generated by order_by_statement function, nested if statements to ignore multipl
- Date: Tue, 4 Nov 2014 22:00:27 +0000 (UTC)
commit 93555cf45dc69e618a540dd49e033a5e1c1d8587
Author: Maia McCormick <maia mcc gmail com>
Date: Wed Oct 15 20:26:53 2014 -0400
ORDER BY statements generated by order_by_statement function, nested if statements to ignore multiple
articles, _('the') for translatability
https://bugzilla.gnome.org/show_bug.cgi?id=729378
gnomemusic/query.py | 40 ++++++++++++++++++++++++++++++----------
1 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index e1845e4..eb8b4cd 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -25,6 +25,7 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
+from gettext import gettext as _
from gi.repository import GLib, Tracker
import os
import logging
@@ -46,6 +47,25 @@ class Query():
@staticmethod
+ def order_by_statement(attr):
+ """Returns a SPARQL ORDER BY statement sorting by the given attribute, ignoring
+ articles as defined in _("the"). 'Attr' should be given without parentheses,
+ e.g., "attr='?author'"."""
+ return_statement = "fn:lower-case(%(attribute)s)" % {'attribute' : attr }
+ # TRANSLATORS: _("the") should be a space-separated list of all-lowercase articles
+ # (such as 'the') that should be ignored when alphabetizing artists/albums. This
+ # list should include 'the' regardless of language. If some articles occur more
+ # frequently than others, most common should appear first, least common last.
+ for article in reversed(_("the").split(" ")):
+ return_statement = '''IF(fn:starts-with(fn:lower-case(%(attribute)s), "%(article)s"),
+ fn:substring(fn:lower-case(%(attribute)s), %(substr_start)s),
+ %(nested_if)s)''' % {'attribute' : attr,
+ 'article' : article+" ",
+ 'substr_start' : str(len(article)+2),
+ 'nested_if' : return_statement }
+ return return_statement
+
+ @staticmethod
def all_albums():
return Query.albums('?album a nmm:MusicAlbum .')
@@ -217,15 +237,15 @@ class Query():
}
)
}
- ORDER BY IF(fn:starts-with(fn:lower-case(?title), "the "),
- fn:substring(fn:lower-case(?title), 5), fn:lower-case(?title))
- IF(fn:starts-with(fn:lower-case(?author), "the "),
- fn:substring(fn:lower-case(?author), 5), fn:lower-case(?author))
+ ORDER BY %(album_order)s
+ %(artist_order)s
?albumyear
'''.replace('\n', ' ').strip() % {
'where_clause': where_clause.replace('\n', ' ').strip(),
'music_dir': Query.MUSIC_URI,
- 'download_dir': Query.DOWNLOAD_URI
+ 'download_dir': Query.DOWNLOAD_URI,
+ 'album_order' : Query.order_by_statement("?title"),
+ 'artist_order' : Query.order_by_statement("?author")
}
return query
@@ -370,15 +390,15 @@ class Query():
}
)
}
- ORDER BY IF(fn:starts-with(fn:lower-case(?author), "the "),
- fn:substring(fn:lower-case(?author), 5), fn:lower-case(?author))
+ ORDER BY %(artist_order)s
?albumyear
- IF(fn:starts-with(fn:lower-case(nie:title(?album)), "the "),
- fn:substring(fn:lower-case(nie:title(?album)), 5), fn:lower-case(nie:title(?album)))
+ %(album_order)s
'''.replace('\n', ' ').strip() % {
'where_clause': where_clause.replace('\n', ' ').strip(),
'music_dir': Query.MUSIC_URI,
- 'download_dir': Query.DOWNLOAD_URI
+ 'download_dir': Query.DOWNLOAD_URI,
+ 'artist_order': Query.order_by_statement("?author"),
+ 'album_order' : Query.order_by_statement("nie:title(?album)")
}
return query
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]