diff --git a/tailbone/forms/renderers/__init__.py b/tailbone/forms/renderers/__init__.py index e7b081b6..7c57f425 100644 --- a/tailbone/forms/renderers/__init__.py +++ b/tailbone/forms/renderers/__init__.py @@ -24,22 +24,19 @@ FormAlchemy Field Renderers """ -from tailbone.forms.renderers.common import ( - AutocompleteFieldRenderer, - DateTimeFieldRenderer, - DecimalFieldRenderer, - EnumFieldRenderer, - YesNoFieldRenderer, - ) +from .common import (AutocompleteFieldRenderer, + DecimalFieldRenderer, CurrencyFieldRenderer, + DateTimeFieldRenderer, + EnumFieldRenderer, YesNoFieldRenderer) -from .people import ( - PersonFieldRenderer, PersonFieldLinkRenderer, - CustomerFieldRenderer, CustomerFieldLinkRenderer, - UserFieldRenderer) +from .people import (PersonFieldRenderer, PersonFieldLinkRenderer, + CustomerFieldRenderer, CustomerFieldLinkRenderer, + UserFieldRenderer) from .employees import EmployeeFieldRenderer -from tailbone.forms.renderers.products import GPCFieldRenderer -from tailbone.forms.renderers.products import * +from .products import (ProductFieldRenderer, GPCFieldRenderer, + BrandFieldRenderer, VendorFieldRenderer, + PriceFieldRenderer, PriceWithExpirationFieldRenderer) -from tailbone.forms.renderers.stores import StoreFieldRenderer +from .stores import StoreFieldRenderer diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py index 1638ece1..1769080e 100644 --- a/tailbone/forms/renderers/common.py +++ b/tailbone/forms/renderers/common.py @@ -147,6 +147,21 @@ class DecimalFieldRenderer(formalchemy.FieldRenderer): return fmt.format(value) +class CurrencyFieldRenderer(formalchemy.FieldRenderer): + """ + Sort of generic field renderer for currency values. + """ + + def __init__(self, field): + super(CurrencyFieldRenderer, self).__init__(field) + + def render_readonly(self, **kwargs): + value = self.raw_value + if value is None: + return '' + return '$ {0:0,.2f}'.format(value) + + class YesNoFieldRenderer(CheckBoxFieldRenderer): def render_readonly(self, **kwargs): diff --git a/tailbone/forms/renderers/products.py b/tailbone/forms/renderers/products.py index 145659c9..1857d791 100644 --- a/tailbone/forms/renderers/products.py +++ b/tailbone/forms/renderers/products.py @@ -34,11 +34,6 @@ from webhelpers.html import literal from tailbone.util import pretty_datetime -__all__ = ['ProductFieldRenderer', 'GPCFieldRenderer', - 'BrandFieldRenderer', 'VendorFieldRenderer', - 'PriceFieldRenderer', 'PriceWithExpirationFieldRenderer'] - - class ProductFieldRenderer(AutocompleteFieldRenderer): """ Renderer for :class:`rattail.db.model.Product` instance fields.