From 990556e76b2f5c5d8c50d6c98ba192e1fa24c246 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 2 Aug 2012 16:39:42 -0700 Subject: [PATCH] add expiration date to current price in products grid --- rattail/pyramid/forms.py | 16 ++++++++++++++++ rattail/pyramid/views/products.py | 10 ++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/rattail/pyramid/forms.py b/rattail/pyramid/forms.py index c042dbf4..12ec37e2 100644 --- a/rattail/pyramid/forms.py +++ b/rattail/pyramid/forms.py @@ -29,7 +29,9 @@ import formalchemy # from formalchemy.fields import SelectFieldRenderer +import edbob from edbob.pyramid import Session +from edbob.pyramid.forms import pretty_datetime import rattail @@ -82,6 +84,20 @@ class PriceFieldRenderer(formalchemy.FieldRenderer): return '' +class PriceWithExpirationFieldRenderer(PriceFieldRenderer): + """ + Price field renderer which also displays the expiration date, if present. + """ + + def render_readonly(self, **kwargs): + res = super(PriceWithExpirationFieldRenderer, self).render_readonly(**kwargs) + if res: + price = self.field.raw_value + if price.ends: + res += '  (%s)' % pretty_datetime(price.ends, from_='utc') + return res + + class UpcFieldRenderer(formalchemy.TextFieldRenderer): """ Handles rendering for the product UPC field. diff --git a/rattail/pyramid/views/products.py b/rattail/pyramid/views/products.py index 737cf4b4..4ab7e6a3 100644 --- a/rattail/pyramid/views/products.py +++ b/rattail/pyramid/views/products.py @@ -26,6 +26,7 @@ ``rattail.pyramid.views.products`` -- Product Views """ +from webhelpers.html import literal from webhelpers.html.tags import link_to from sqlalchemy.orm import joinedload @@ -40,7 +41,8 @@ from edbob.pyramid import Session import rattail import rattail.labels -from rattail.pyramid.forms import UpcFieldRenderer, PriceFieldRenderer +from rattail.pyramid.forms import (UpcFieldRenderer, PriceFieldRenderer, + PriceWithExpirationFieldRenderer) class ProductGrid(GridView): @@ -120,7 +122,7 @@ class ProductGrid(GridView): g = self.make_grid(data, config) g.upc.set(renderer=UpcFieldRenderer) g.regular_price.set(renderer=PriceFieldRenderer) - g.current_price.set(renderer=PriceFieldRenderer) + g.current_price.set(renderer=PriceWithExpirationFieldRenderer) g.configure( include=[ g.upc.label("UPC"), @@ -129,8 +131,8 @@ class ProductGrid(GridView): g.size, # g.department, g.subdepartment, - g.regular_price.label("Reg Price"), - g.current_price.label("Cur Price"), + g.regular_price.label("Reg. Price"), + g.current_price.label(literal("Cur. Price  (Exp.)")), ], readonly=True)