diff --git a/tailbone/forms/renderers/__init__.py b/tailbone/forms/renderers/__init__.py index bf9a58c5..984e40ca 100644 --- a/tailbone/forms/renderers/__init__.py +++ b/tailbone/forms/renderers/__init__.py @@ -29,7 +29,7 @@ from __future__ import unicode_literals, absolute_import from .core import CustomFieldRenderer, DateFieldRenderer from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer, - DecimalFieldRenderer, CurrencyFieldRenderer, + DecimalFieldRenderer, CurrencyFieldRenderer, QuantityFieldRenderer, DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer) diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py index 58982b5f..d035e0b5 100644 --- a/tailbone/forms/renderers/common.py +++ b/tailbone/forms/renderers/common.py @@ -29,6 +29,7 @@ from __future__ import unicode_literals, absolute_import import datetime from rattail.time import localtime, make_utc +from rattail.util import pretty_quantity import formalchemy as fa from formalchemy import fields as fa_fields, helpers as fa_helpers @@ -248,6 +249,15 @@ class CurrencyFieldRenderer(fa_fields.FloatFieldRenderer): return "${:0,.2f}".format(value) +class QuantityFieldRenderer(fa_fields.FloatFieldRenderer): + """ + Sort of generic field renderer for quantity values. + """ + + def render_readonly(self, **kwargs): + return pretty_quantity(self.raw_value) + + class YesNoFieldRenderer(fa.CheckBoxFieldRenderer): def render_readonly(self, **kwargs):