Introduce the DISPLAYED_FIELDS in formatter
This commit is contained in:
parent
b0349f0e8c
commit
30732318b5
4 changed files with 9 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue