[gnome-music/wip/mschraal/tageditor-13feb2020: 31/53] utils: Optional return of empty string for year



commit deae6f5d6b3ceb482f0c8a239a5624e7ddd6fccd
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jan 16 15:40:48 2020 +0100

    utils: Optional return of empty string for year

 gnomemusic/corealbum.py |  2 +-
 gnomemusic/utils.py     | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 9084cd82..7e0552a6 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -64,7 +64,7 @@ class CoreAlbum(GObject.GObject):
         self.props.composer = media.get_composer()
         self.props.title = utils.get_media_title(media)
         self.props.url = media.get_url()
-        self.props.year = utils.get_media_year(media)
+        self.props.year = utils.get_media_year(media, True)
 
     @GObject.Property(
         type=Gio.ListModel, default=None, flags=GObject.ParamFlags.READABLE)
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index 8090cf27..65f8c606 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -109,17 +109,20 @@ def get_media_title(item):
     return title
 
 
-def get_media_year(item):
+def get_media_year(item, fill_empty=False):
     """Returns the year when the media was created.
 
-    :param item: A Grilo Media object
-    :return: The creation year or '----' if not defined
+    :param Grl.Media item: A Grilo Media object
+    :param bool fill_empty: If True return '----' if date not defined
+    :return: The creation year if defined
     :rtype: string
     """
     date = item.get_creation_date()
 
     if not date:
-        return "----"
+        if fill_empty is True:
+            return "----"
+        return ""
 
     return str(date.get_year())
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]