From 17fb224a1d48d94deafbee5d839ad0e2cbd50ba7 Mon Sep 17 00:00:00 2001
From: inso <insomniak.fr@gmaiL.com>
Date: Wed, 24 Aug 2016 20:46:43 +0200
Subject: [PATCH] Fix bug #524

---
 src/sakia/core/community.py              |  5 ++---
 src/sakia/core/money/relative_to_past.py | 15 ++++++++-------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/sakia/core/community.py b/src/sakia/core/community.py
index e9fcdd9d..285b7ef7 100644
--- a/src/sakia/core/community.py
+++ b/src/sakia/core/community.py
@@ -169,9 +169,8 @@ class Community(QObject):
             else:
                 return None
         except errors.DuniterError as e:
-            if e.ucode == errors.BLOCK_NOT_FOUND:
-                logging.debug(str(e))
-                return None
+            logging.debug(str(e))
+            return None
         except NoPeerAvailable as e:
             logging.debug(str(e))
             return None
diff --git a/src/sakia/core/money/relative_to_past.py b/src/sakia/core/money/relative_to_past.py
index b92e5dc1..83229eb2 100644
--- a/src/sakia/core/money/relative_to_past.py
+++ b/src/sakia/core/money/relative_to_past.py
@@ -96,6 +96,13 @@ class RelativeToPast(BaseReferential):
         from . import Relative
         value = await self.differential()
         block = await self.community.get_ud_block(0, self._block_number)
+        if block:
+            date = QLocale.toString(
+                        QLocale(),
+                        QDateTime.fromTime_t(block['medianTime']).date(),
+                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat))
+        else:
+            date = "###"
         prefix = ""
         if international_system and value != 0:
             localized_value, prefix = Relative.to_si(value, self.app.preferences['digits_after_comma'])
@@ -104,13 +111,7 @@ class RelativeToPast(BaseReferential):
 
         if units or international_system:
             return QCoreApplication.translate("RelativeToPast", RelativeToPast._REF_STR_)\
-                .format(localized_value,
-                    prefix,
-                    QLocale.toString(
-                        QLocale(),
-                        QDateTime.fromTime_t(block['medianTime']).date(),
-                        QLocale.dateFormat(QLocale(), QLocale.ShortFormat)
-                    ),
+                .format(localized_value,prefix,date,
                     self.community.short_currency if units else "")
         else:
             return localized_value
-- 
GitLab