add expiration date to current price in products grid

This commit is contained in:
Lance Edgar 2012-08-02 16:39:42 -07:00
parent 165538c8f1
commit 990556e76b
2 changed files with 22 additions and 4 deletions

View file

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

View file

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