From 5ac3b6f14cbf8dc75c5d42327ae60ef91373fbc6 Mon Sep 17 00:00:00 2001 From: Florent Fourcot Date: Thu, 29 Dec 2016 12:21:14 +0100 Subject: [PATCH] boobank: add a custom formatter for advisor command The prettytable output is horrible for so many fields --- weboob/applications/boobank/boobank.py | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 22e3549035..3054766dc8 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -276,6 +276,41 @@ def get_title(self, obj): return obj.label +class AdvisorListFormatter(IFormatter): + MANDATORY_FIELDS = ('id', 'name') + + def start_format(self, **kwargs): + self.output(' Bank Name Contacts') + self.output('-----------------+------------------------------+-----------------------------------------') + + def format_obj(self, obj, alias): + bank = obj.backend + phones = "" + if not empty(obj.phone): + phones += obj.phone + if not empty(obj.mobile): + if phones != "": + phones += " or %s" % obj.mobile + else: + phones += obj.mobile + + if not empty(obj.email): + email = obj.email + else: + email = "" + + result = u" %s %s %s " % (self.colored('%-15s' % bank, 'yellow'), + self.colored('%-30s' % obj.name, 'red'), + self.colored("%-30s" % email, 'green')) + if phones != "": + result += "\n %s %s" % ((" ") * 47, self.colored("%-25s" % phones, 'green')) + if not empty(obj.agency): + result += "\n %s %s" % ((" ") * 47, self.colored("%-25s" % obj.agency, "green")) + if not empty(obj.address): + result += "\n %s %s" % ((" ") * 47, self.colored("%-25s" % obj.address, "green")) + + return result + class AccountListFormatter(IFormatter): MANDATORY_FIELDS = ('id', 'label', 'balance', 'coming', 'type') @@ -344,6 +379,7 @@ class Boobank(ReplApplication): 'ofx': OfxFormatter, 'ops_list': TransactionsFormatter, 'investment_list': InvestmentFormatter, + 'advisor_list': AdvisorListFormatter, } DEFAULT_FORMATTER = 'table' COMMANDS_FORMATTERS = {'ls': 'account_list', @@ -352,6 +388,7 @@ class Boobank(ReplApplication): 'history': 'ops_list', 'coming': 'ops_list', 'investment': 'investment_list', + 'advisor': 'advisor_list', } COLLECTION_OBJECTS = (Account, Transaction, ) -- GitLab