Add support for Product.not_for_sale flag.

This involved a couple of ancillary changes:

* The price field renderer will not display a price for products marked not
  for sale.

* The "grid" class now allows specifying a custom callable to provide
  additional CSS class for table rows.

* The products grid uses this to add a "not-for-sale" class to table rows
  for products which are marked thusly.
This commit is contained in:
Lance Edgar 2014-09-10 19:38:49 -07:00
parent 98f6a7377b
commit dfb5e83c7e
3 changed files with 39 additions and 21 deletions

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
# Copyright © 2010-2014 Lance Edgar
#
# This file is part of Rattail.
#
@ -26,6 +25,8 @@
Product Field Renderers
"""
from __future__ import unicode_literals
from formalchemy import TextFieldRenderer
from rattail.gpc import GPC
from .common import AutocompleteFieldRenderer
@ -88,19 +89,20 @@ class PriceFieldRenderer(TextFieldRenderer):
def render_readonly(self, **kwargs):
price = self.field.raw_value
if price:
if price.price is not None and price.pack_price is not None:
if price.multiple > 1:
return literal('$ %0.2f / %u  ($ %0.2f / %u)' % (
price.price, price.multiple,
price.pack_price, price.pack_multiple))
return literal('$ %0.2f  ($ %0.2f / %u)' % (
price.price, price.pack_price, price.pack_multiple))
if price.price is not None:
if price.multiple > 1:
return '$ %0.2f / %u' % (price.price, price.multiple)
return '$ %0.2f' % price.price
if price.pack_price is not None:
return '$ %0.2f / %u' % (price.pack_price, price.pack_multiple)
if not price.product.not_for_sale:
if price.price is not None and price.pack_price is not None:
if price.multiple > 1:
return literal('$ %0.2f / %u  ($ %0.2f / %u)' % (
price.price, price.multiple,
price.pack_price, price.pack_multiple))
return literal('$ %0.2f  ($ %0.2f / %u)' % (
price.price, price.pack_price, price.pack_multiple))
if price.price is not None:
if price.multiple > 1:
return '$ %0.2f / %u' % (price.price, price.multiple)
return '$ %0.2f' % price.price
if price.pack_price is not None:
return '$ %0.2f / %u' % (price.pack_price, price.pack_multiple)
return ''