Add 'percent' as field type for Form; fix rendering of 'percent' for Grid

these both now assume the value obtained will be a "typical" percentage
decimal, i.e. 0.30130 instead of 30.130
This commit is contained in:
Lance Edgar 2018-12-18 17:41:38 -06:00
parent 3e9fdbacad
commit a637ba1e6b
2 changed files with 9 additions and 1 deletions

View file

@ -586,6 +586,8 @@ class Form(object):
self.set_renderer(key, self.render_currency) self.set_renderer(key, self.render_currency)
elif type_ == 'quantity': elif type_ == 'quantity':
self.set_renderer(key, self.render_quantity) self.set_renderer(key, self.render_quantity)
elif type_ == 'percent':
self.set_renderer(key, self.render_percent)
elif type_ == 'gpc': elif type_ == 'gpc':
self.set_renderer(key, self.render_gpc) self.set_renderer(key, self.render_gpc)
elif type_ == 'enum': elif type_ == 'enum':
@ -812,6 +814,12 @@ class Form(object):
return "" return ""
return pretty_quantity(value) return pretty_quantity(value)
def render_percent(self, obj, field):
value = self.obtain_value(obj, field)
if value is None:
return ""
return "{:0.3f} %".format(value * 100)
def render_gpc(self, obj, field): def render_gpc(self, obj, field):
value = self.obtain_value(obj, field) value = self.obtain_value(obj, field)
if value is None: if value is None:

View file

@ -271,7 +271,7 @@ class Grid(object):
value = self.obtain_value(obj, column_name) value = self.obtain_value(obj, column_name)
if value is None: if value is None:
return "" return ""
return "{:0.2f}".format(value) return "{:0.3f} %".format(value * 100)
def render_quantity(self, obj, column_name): def render_quantity(self, obj, column_name):
value = self.obtain_value(obj, column_name) value = self.obtain_value(obj, column_name)