From 30732318b544ce721db5e1b1a6c3a640aed3fd43 Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 17 Jun 2014 15:45:13 +0200 Subject: [PATCH] Introduce the DISPLAYED_FIELDS in formatter --- weboob/applications/boobank/boobank.py | 4 +++- weboob/applications/boobsize/boobsize.py | 1 + weboob/applications/videoob/videoob.py | 1 + weboob/tools/application/formatters/iformatter.py | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py index 39ea6f83..bee1d941 100644 --- a/weboob/applications/boobank/boobank.py +++ b/weboob/applications/boobank/boobank.py @@ -172,6 +172,7 @@ class TransactionsFormatter(IFormatter): class TransferFormatter(IFormatter): MANDATORY_FIELDS = ('id', 'date', 'origin', 'recipient', 'amount') + DISPLAYED_FIELDS = ('reason', ) def format_obj(self, obj, alias): result = u'------- Transfer %s -------\n' % obj.fullid @@ -186,6 +187,7 @@ class TransferFormatter(IFormatter): class InvestmentFormatter(IFormatter): MANDATORY_FIELDS = ('label', 'quantity', 'unitvalue') + DISPLAYED_FIELDS = ('code', 'diff') tot_valuation = Decimal(0) tot_diff = Decimal(0) @@ -209,7 +211,7 @@ class InvestmentFormatter(IFormatter): self.colored('%6d' % obj.quantity, 'yellow'), self.colored('%11.2f' % obj.unitvalue, 'yellow'), self.colored('%11.2f' % obj.valuation, 'yellow'), - self.colored('%8.2f' % diff, 'green' if diff >=0 else 'red') + self.colored('%8.2f' % diff, 'green' if diff >= 0 else 'red') ) def flush(self): diff --git a/weboob/applications/boobsize/boobsize.py b/weboob/applications/boobsize/boobsize.py index 6dbdb2fb..d158dd1e 100644 --- a/weboob/applications/boobsize/boobsize.py +++ b/weboob/applications/boobsize/boobsize.py @@ -30,6 +30,7 @@ __all__ = ['Boobsize'] class GaugeFormatter(IFormatter): MANDATORY_FIELDS = ('name', 'object', 'sensors') + DISPLAYED_FIELDS = self.MANDATORY_FIELDS + ('city', ) def start_format(self, **kwargs): # Name = 27 Object = 10 City = 10 Sensors = 33 diff --git a/weboob/applications/videoob/videoob.py b/weboob/applications/videoob/videoob.py index b1d89019..765d81a6 100644 --- a/weboob/applications/videoob/videoob.py +++ b/weboob/applications/videoob/videoob.py @@ -34,6 +34,7 @@ __all__ = ['Videoob'] class VideoListFormatter(PrettyFormatter): MANDATORY_FIELDS = ('id', 'title', 'duration', 'date') + DISPLAYED_FIELDS = self.MANDATORY_FIELDS + ('author', 'rating') def get_title(self, obj): return obj.title diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index 129e808a..3cfe042f 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -74,7 +74,11 @@ class MandatoryFieldsNotFound(Exception): class IFormatter(object): + # Tuple of fields mandatory to not crash MANDATORY_FIELDS = None + # Tuple of displayed field. Set to None if all available fields are + # displayed + DISPLAYED_FIELDS = None BOLD = ConsoleApplication.BOLD NC = ConsoleApplication.NC