From fff3f2a0d883019a20ee9a4b59a848b70f8bace9 Mon Sep 17 00:00:00 2001 From: SimonSAMPERE <41120579+SimonSAMPERE@users.noreply.github.com> Date: Thu, 3 Oct 2019 17:36:40 +0200 Subject: [PATCH] better "no shares feeding the plugin" case handling --- modules/api/shares.py | 75 ++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/modules/api/shares.py b/modules/api/shares.py index 8bf0e43b..a63ffec3 100644 --- a/modules/api/shares.py +++ b/modules/api/shares.py @@ -45,43 +45,46 @@ def send_share_info(self, shares: list): logger.debug("Application properties provided by the Isogeo API.") content = shares - text = "" # opening html content - # Isogeo application authenticated in the plugin - app = content[0].get("applications")[0] - text += self.tr( - "

This plugin is authenticated as " "{} and " - ).format( - app.get("url", "https://isogeo.gitbooks.io/app-plugin-qgis/content"), - app.get("name", "Isogeo plugin for QGIS"), - ) - # shares feeding the application - if len(content) == 1: - text += self.tr(" powered by 1 share:


") - else: - text += self.tr(" powered by {} shares:


").format(len(content)) - # shares details - for share in content: - # share variables - creator_name = share.get("_creator").get("contact").get("name") - creator_email = share.get("_creator").get("contact").get("email") - creator_id = share.get("_creator").get("_tag")[6:] - share_url = "https://app.isogeo.com/groups/{}/admin/shares/{}".format( - creator_id, share.get("_id") - ) - # formatting text - text += "

{}

".format( - share_url, share.get("name") - ) - text += self.tr("

Updated: {}

").format( - plg_tools.handle_date(share.get("_modified")) + if len(content) > 0: + text = "" # opening html content + # Isogeo application authenticated in the plugin + app = content[0].get("applications")[0] + text += self.tr( + "

This plugin is authenticated as " "{} and " + ).format( + app.get("url", "https://isogeo.gitbooks.io/app-plugin-qgis/content"), + app.get("name", "Isogeo plugin for QGIS"), ) - text += self.tr("

Contact: {} - {}

").format( - creator_name, creator_email - ) - text += "


" - text += "" - self.shares_ready.emit(text) - + # shares feeding the application + if len(content) == 1: + text += self.tr(" powered by 1 share:


") + else: + text += self.tr(" powered by {} shares:


").format(len(content)) + # shares details + for share in content: + # share variables + creator_name = share.get("_creator").get("contact").get("name") + creator_email = share.get("_creator").get("contact").get("email") + creator_id = share.get("_creator").get("_tag")[6:] + share_url = "https://app.isogeo.com/groups/{}/admin/shares/{}".format( + creator_id, share.get("_id") + ) + # formatting text + text += "

{}

".format( + share_url, share.get("name") + ) + text += self.tr("

Updated: {}

").format( + plg_tools.handle_date(share.get("_modified")) + ) + text += self.tr("

Contact: {} - {}

").format( + creator_name, creator_email + ) + text += "


" + text += "" + self.shares_ready.emit(text) + else: + logger.debug("The plugin is not powered by any shares.") + return # ############################################################################# # ##### Stand alone program ########