Add 'currency' field type for new forms
This commit is contained in:
parent
7442b933fd
commit
46b49ab987
|
@ -301,6 +301,8 @@ class Form(object):
|
|||
elif type_ == 'boolean':
|
||||
self.set_renderer(key, self.render_boolean)
|
||||
self.set_widget(key, dfwidget.CheckboxWidget(true_val='True', false_val='False'))
|
||||
elif type_ == 'currency':
|
||||
self.set_renderer(key, self.render_currency)
|
||||
elif type_ == 'enum':
|
||||
self.set_renderer(key, self.render_enum)
|
||||
elif type_ == 'codeblock':
|
||||
|
@ -427,6 +429,14 @@ class Form(object):
|
|||
value = self.obtain_value(record, field_name)
|
||||
return pretty_boolean(value)
|
||||
|
||||
def render_currency(self, record, field_name):
|
||||
value = self.obtain_value(record, field_name)
|
||||
if value is None:
|
||||
return ""
|
||||
if value < 0:
|
||||
return "(${:0,.2f})".format(0 - value)
|
||||
return "${:0,.2f}".format(value)
|
||||
|
||||
def render_enum(self, record, field_name):
|
||||
value = self.obtain_value(record, field_name)
|
||||
if value is None:
|
||||
|
|
Loading…
Reference in a new issue