Add QuantityFieldRenderer

This commit is contained in:
Lance Edgar 2016-12-19 12:25:38 -06:00
parent 4c929055e6
commit aa99f3b506
2 changed files with 11 additions and 1 deletions

View file

@ -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)

View file

@ -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):