add expiration date to current price in products grid
This commit is contained in:
parent
165538c8f1
commit
990556e76b
|
@ -29,7 +29,9 @@
|
||||||
import formalchemy
|
import formalchemy
|
||||||
# from formalchemy.fields import SelectFieldRenderer
|
# from formalchemy.fields import SelectFieldRenderer
|
||||||
|
|
||||||
|
import edbob
|
||||||
from edbob.pyramid import Session
|
from edbob.pyramid import Session
|
||||||
|
from edbob.pyramid.forms import pretty_datetime
|
||||||
|
|
||||||
import rattail
|
import rattail
|
||||||
|
|
||||||
|
@ -82,6 +84,20 @@ class PriceFieldRenderer(formalchemy.FieldRenderer):
|
||||||
return ''
|
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):
|
class UpcFieldRenderer(formalchemy.TextFieldRenderer):
|
||||||
"""
|
"""
|
||||||
Handles rendering for the product UPC field.
|
Handles rendering for the product UPC field.
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
``rattail.pyramid.views.products`` -- Product Views
|
``rattail.pyramid.views.products`` -- Product Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from webhelpers.html import literal
|
||||||
from webhelpers.html.tags import link_to
|
from webhelpers.html.tags import link_to
|
||||||
|
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
@ -40,7 +41,8 @@ from edbob.pyramid import Session
|
||||||
|
|
||||||
import rattail
|
import rattail
|
||||||
import rattail.labels
|
import rattail.labels
|
||||||
from rattail.pyramid.forms import UpcFieldRenderer, PriceFieldRenderer
|
from rattail.pyramid.forms import (UpcFieldRenderer, PriceFieldRenderer,
|
||||||
|
PriceWithExpirationFieldRenderer)
|
||||||
|
|
||||||
|
|
||||||
class ProductGrid(GridView):
|
class ProductGrid(GridView):
|
||||||
|
@ -120,7 +122,7 @@ class ProductGrid(GridView):
|
||||||
g = self.make_grid(data, config)
|
g = self.make_grid(data, config)
|
||||||
g.upc.set(renderer=UpcFieldRenderer)
|
g.upc.set(renderer=UpcFieldRenderer)
|
||||||
g.regular_price.set(renderer=PriceFieldRenderer)
|
g.regular_price.set(renderer=PriceFieldRenderer)
|
||||||
g.current_price.set(renderer=PriceFieldRenderer)
|
g.current_price.set(renderer=PriceWithExpirationFieldRenderer)
|
||||||
g.configure(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.upc.label("UPC"),
|
g.upc.label("UPC"),
|
||||||
|
@ -129,8 +131,8 @@ class ProductGrid(GridView):
|
||||||
g.size,
|
g.size,
|
||||||
# g.department,
|
# g.department,
|
||||||
g.subdepartment,
|
g.subdepartment,
|
||||||
g.regular_price.label("Reg Price"),
|
g.regular_price.label("Reg. Price"),
|
||||||
g.current_price.label("Cur Price"),
|
g.current_price.label(literal("Cur. Price (Exp.)")),
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue