Add CurrencyFieldRenderer.

Also clean up the subpackage root a little bit.
This commit is contained in:
Lance Edgar 2015-08-14 15:27:52 -05:00
parent 62784390b0
commit e79531fda8
3 changed files with 26 additions and 19 deletions

View file

@ -24,22 +24,19 @@
FormAlchemy Field Renderers FormAlchemy Field Renderers
""" """
from tailbone.forms.renderers.common import ( from .common import (AutocompleteFieldRenderer,
AutocompleteFieldRenderer, DecimalFieldRenderer, CurrencyFieldRenderer,
DateTimeFieldRenderer, DateTimeFieldRenderer,
DecimalFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer)
EnumFieldRenderer,
YesNoFieldRenderer,
)
from .people import ( from .people import (PersonFieldRenderer, PersonFieldLinkRenderer,
PersonFieldRenderer, PersonFieldLinkRenderer,
CustomerFieldRenderer, CustomerFieldLinkRenderer, CustomerFieldRenderer, CustomerFieldLinkRenderer,
UserFieldRenderer) UserFieldRenderer)
from .employees import EmployeeFieldRenderer from .employees import EmployeeFieldRenderer
from tailbone.forms.renderers.products import GPCFieldRenderer from .products import (ProductFieldRenderer, GPCFieldRenderer,
from tailbone.forms.renderers.products import * BrandFieldRenderer, VendorFieldRenderer,
PriceFieldRenderer, PriceWithExpirationFieldRenderer)
from tailbone.forms.renderers.stores import StoreFieldRenderer from .stores import StoreFieldRenderer

View file

@ -147,6 +147,21 @@ class DecimalFieldRenderer(formalchemy.FieldRenderer):
return fmt.format(value) 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): class YesNoFieldRenderer(CheckBoxFieldRenderer):
def render_readonly(self, **kwargs): def render_readonly(self, **kwargs):

View file

@ -34,11 +34,6 @@ from webhelpers.html import literal
from tailbone.util import pretty_datetime from tailbone.util import pretty_datetime
__all__ = ['ProductFieldRenderer', 'GPCFieldRenderer',
'BrandFieldRenderer', 'VendorFieldRenderer',
'PriceFieldRenderer', 'PriceWithExpirationFieldRenderer']
class ProductFieldRenderer(AutocompleteFieldRenderer): class ProductFieldRenderer(AutocompleteFieldRenderer):
""" """
Renderer for :class:`rattail.db.model.Product` instance fields. Renderer for :class:`rattail.db.model.Product` instance fields.