Add hyperlinks to product UPC and description, within main grid
These won't honor the indexing scheme yet, still need to think about that.
This commit is contained in:
parent
b718336ac2
commit
aaa1d17507
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2015 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,13 +24,14 @@
|
||||||
Product Field Renderers
|
Product Field Renderers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
|
from rattail.gpc import GPC
|
||||||
|
|
||||||
from formalchemy import TextFieldRenderer
|
from formalchemy import TextFieldRenderer
|
||||||
from rattail.gpc import GPC
|
from webhelpers.html import tags, literal
|
||||||
from .common import AutocompleteFieldRenderer
|
|
||||||
from webhelpers.html import literal
|
|
||||||
|
|
||||||
|
from tailbone.forms.renderers.common import AutocompleteFieldRenderer
|
||||||
from tailbone.util import pretty_datetime
|
from tailbone.util import pretty_datetime
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,14 +58,18 @@ class GPCFieldRenderer(TextFieldRenderer):
|
||||||
@property
|
@property
|
||||||
def length(self):
|
def length(self):
|
||||||
# Hm, should maybe consider hard-coding this...?
|
# Hm, should maybe consider hard-coding this...?
|
||||||
return len(str(GPC(0)))
|
return len(unicode(GPC(0)))
|
||||||
|
|
||||||
def render_readonly(self, **kwargs):
|
def render_readonly(self, **kwargs):
|
||||||
gpc = self.raw_value
|
gpc = self.raw_value
|
||||||
if gpc is None:
|
if gpc is None:
|
||||||
return ''
|
return ''
|
||||||
gpc = unicode(gpc)
|
gpc = unicode(gpc)
|
||||||
return '{0}-{1}'.format(gpc[:-1], gpc[-1])
|
gpc = '{}-{}'.format(gpc[:-1], gpc[-1])
|
||||||
|
if kwargs.get('link'):
|
||||||
|
product = self.field.parent.model
|
||||||
|
gpc = tags.link_to(gpc, kwargs['link'](product))
|
||||||
|
return gpc
|
||||||
|
|
||||||
|
|
||||||
class DepartmentFieldRenderer(TextFieldRenderer):
|
class DepartmentFieldRenderer(TextFieldRenderer):
|
||||||
|
|
|
@ -70,6 +70,21 @@ from tailbone.progress import SessionProgress
|
||||||
# return query
|
# return query
|
||||||
|
|
||||||
|
|
||||||
|
class DescriptionFieldRenderer(fa.TextFieldRenderer):
|
||||||
|
"""
|
||||||
|
Renderer for product descriptions within the grid; adds hyperlink.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
description = self.raw_value
|
||||||
|
if description is None:
|
||||||
|
return ''
|
||||||
|
if kwargs.get('link'):
|
||||||
|
product = self.field.parent.model
|
||||||
|
description = tags.link_to(description, kwargs['link'](product))
|
||||||
|
return description
|
||||||
|
|
||||||
|
|
||||||
class ProductsView(MasterView):
|
class ProductsView(MasterView):
|
||||||
"""
|
"""
|
||||||
Master view for the Product class.
|
Master view for the Product class.
|
||||||
|
@ -166,9 +181,16 @@ class ProductsView(MasterView):
|
||||||
g.filters['vendor_any'] = g.make_filter('vendor_any', self.VendorAny.name, label="Vendor (any)")
|
g.filters['vendor_any'] = g.make_filter('vendor_any', self.VendorAny.name, label="Vendor (any)")
|
||||||
# factory=VendorAnyFilter, joiner=join_vendor_any)
|
# factory=VendorAnyFilter, joiner=join_vendor_any)
|
||||||
|
|
||||||
g.default_sortkey = 'description'
|
g.default_sortkey = 'upc'
|
||||||
|
|
||||||
|
product_link = lambda p: self.get_action_url('view', p)
|
||||||
|
|
||||||
g.upc.set(renderer=forms.renderers.GPCFieldRenderer)
|
g.upc.set(renderer=forms.renderers.GPCFieldRenderer)
|
||||||
|
g.upc.attrs(link=product_link)
|
||||||
|
|
||||||
|
g.description.set(renderer=DescriptionFieldRenderer)
|
||||||
|
g.description.attrs(link=product_link)
|
||||||
|
|
||||||
g.regular_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
g.regular_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
||||||
g.current_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
g.current_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
||||||
g.configure(
|
g.configure(
|
||||||
|
|
Loading…
Reference in a new issue