Add DecimalFieldRenderer
.
This commit is contained in:
parent
b6192b49f2
commit
ab23a8067c
|
@ -27,6 +27,7 @@ FormAlchemy Field Renderers
|
|||
from tailbone.forms.renderers.common import (
|
||||
AutocompleteFieldRenderer,
|
||||
DateTimeFieldRenderer,
|
||||
DecimalFieldRenderer,
|
||||
EnumFieldRenderer,
|
||||
YesNoFieldRenderer,
|
||||
)
|
||||
|
|
|
@ -124,6 +124,29 @@ class EnumFieldRenderer(SelectFieldRenderer):
|
|||
return SelectFieldRenderer.render(self, opts, **kwargs)
|
||||
|
||||
|
||||
class DecimalFieldRenderer(formalchemy.FieldRenderer):
|
||||
"""
|
||||
Sort of generic field renderer for decimal values. You must provide the
|
||||
number of places after the decimal (scale). Note that this in turn relies
|
||||
on simple string formatting; the renderer does not attempt any mathematics
|
||||
of its own.
|
||||
"""
|
||||
|
||||
def __init__(self, scale):
|
||||
self.scale = scale
|
||||
|
||||
def __call__(self, field):
|
||||
super(DecimalFieldRenderer, self).__init__(field)
|
||||
return self
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
value = self.raw_value
|
||||
if value is None:
|
||||
return ''
|
||||
fmt = '{{0:0.{0}f}}'.format(self.scale)
|
||||
return fmt.format(value)
|
||||
|
||||
|
||||
class YesNoFieldRenderer(CheckBoxFieldRenderer):
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue