Various tweaks to products grid filters etc.

Trying to troubleshoot some things...think we're good now.  Some of the
changes here were made and then discovered not to be necessary yet, but
left in place since they're probably good ideas anyway.
This commit is contained in:
Lance Edgar 2016-02-13 13:00:55 -06:00
parent 583548cad5
commit a5080b113d
5 changed files with 30 additions and 7 deletions

View file

@ -104,6 +104,7 @@ class AlchemyGrid(Grid):
factory = filters.AlchemyDateFilter factory = filters.AlchemyDateFilter
elif isinstance(column.type, GPCType): elif isinstance(column.type, GPCType):
factory = filters.AlchemyGPCFilter factory = filters.AlchemyGPCFilter
factory = kwargs.pop('factory', factory)
return factory(key, column=column, **kwargs) return factory(key, column=column, **kwargs)
def iter_filters(self): def iter_filters(self):

View file

@ -55,7 +55,7 @@ class Grid(object):
self.data = data self.data = data
self.main_actions = main_actions self.main_actions = main_actions
self.more_actions = more_actions self.more_actions = more_actions
self.joiners = joiners self.joiners = joiners or {} # use new/different empty dict for each instance
# Set extra attributes first, in case other init logic depends on any # Set extra attributes first, in case other init logic depends on any
# of them (i.e. in subclasses). # of them (i.e. in subclasses).

View file

@ -128,7 +128,7 @@ class GridFilter(object):
value_renderer_factory = DefaultValueRenderer value_renderer_factory = DefaultValueRenderer
def __init__(self, key, label=None, verbs=None, value_renderer=None, def __init__(self, key, label=None, verbs=None, value_renderer=None,
default_active=False, default_verb=None, default_value=None): default_active=False, default_verb=None, default_value=None, **kwargs):
self.key = key self.key = key
self.label = label or prettify(key) self.label = label or prettify(key)
self.verbs = verbs or self.get_default_verbs() self.verbs = verbs or self.get_default_verbs()
@ -136,6 +136,8 @@ class GridFilter(object):
self.default_active = default_active self.default_active = default_active
self.default_verb = default_verb self.default_verb = default_verb
self.default_value = default_value self.default_value = default_value
for key, value in kwargs.iteritems():
setattr(self, key, value)
def __repr__(self): def __repr__(self):
return "GridFilter({0})".format(repr(self.key)) return "GridFilter({0})".format(repr(self.key))

View file

@ -38,6 +38,7 @@ class FamiliesView(MasterView):
model_class = model.Family model_class = model.Family
model_title_plural = "Families" model_title_plural = "Families"
route_prefix = 'families' route_prefix = 'families'
grid_key = 'families'
def configure_grid(self, g): def configure_grid(self, g):
g.filters['name'].default_active = True g.filters['name'].default_active = True

View file

@ -43,15 +43,33 @@ from pyramid import httpexceptions
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from webhelpers.html import tags from webhelpers.html import tags
from tailbone import forms from tailbone import forms, newgrids as grids
from tailbone.db import Session from tailbone.db import Session
from tailbone.views import MasterView, SearchableAlchemyGridView, AutocompleteView from tailbone.views import MasterView, SearchableAlchemyGridView, AutocompleteView
from tailbone.views.continuum import VersionView, version_defaults from tailbone.views.continuum import VersionView, version_defaults
from tailbone.forms.renderers import products as products_forms from tailbone.forms.renderers import products as products_forms
from tailbone.newgrids import GridAction
from tailbone.progress import SessionProgress from tailbone.progress import SessionProgress
# TODO: For a moment I thought this was going to be necessary, but now I think
# not. Leaving it around for a bit just in case...
# class VendorAnyFilter(grids.filters.AlchemyStringFilter):
# """
# Custom filter for "vendor (any)" so we can avoid joining on that unless we
# really have to. This is because it seems to throw off the number of
# records which are showed in the result set, when this filter is included in
# the active set but no criteria is specified.
# """
# def filter(self, query, **kwargs):
# original = query
# query = super(VendorAnyFilter, self).filter(query, **kwargs)
# if query is not original:
# query = self.joiner(query)
# return query
class ProductsView(MasterView): class ProductsView(MasterView):
""" """
Master view for the Product class. Master view for the Product class.
@ -122,9 +140,9 @@ class ProductsView(MasterView):
model.ProductPrice.uuid == model.Product.regular_price_uuid) model.ProductPrice.uuid == model.Product.regular_price_uuid)
g.joiners['current_price'] = lambda q: q.outerjoin(model.ProductPrice, g.joiners['current_price'] = lambda q: q.outerjoin(model.ProductPrice,
model.ProductPrice.uuid == model.Product.current_price_uuid) model.ProductPrice.uuid == model.Product.current_price_uuid)
g.joiners['code'] = lambda q: q.outerjoin(model.ProductCode)
g.joiners['vendor'] = join_vendor g.joiners['vendor'] = join_vendor
g.joiners['vendor_any'] = join_vendor_any g.joiners['vendor_any'] = join_vendor_any
g.joiners['code'] = lambda q: q.outerjoin(model.ProductCode)
g.sorters['brand'] = g.make_sorter(model.Brand.name) g.sorters['brand'] = g.make_sorter(model.Brand.name)
g.sorters['department'] = g.make_sorter(model.Department.name) g.sorters['department'] = g.make_sorter(model.Department.name)
@ -143,9 +161,10 @@ class ProductsView(MasterView):
default_active=True, default_verb='contains') default_active=True, default_verb='contains')
g.filters['subdepartment'] = g.make_filter('subdepartment', model.Subdepartment.name) g.filters['subdepartment'] = g.make_filter('subdepartment', model.Subdepartment.name)
g.filters['report_code'] = g.make_filter('report_code', model.ReportCode.name) g.filters['report_code'] = g.make_filter('report_code', model.ReportCode.name)
g.filters['code'] = g.make_filter('code', model.ProductCode.code)
g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name, label="Vendor (preferred)") g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name, label="Vendor (preferred)")
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)")
g.filters['code'] = g.make_filter('code', model.ProductCode.code) # factory=VendorAnyFilter, joiner=join_vendor_any)
g.default_sortkey = 'description' g.default_sortkey = 'description'
@ -167,7 +186,7 @@ class ProductsView(MasterView):
# TODO: need to check for 'print labels' permission here also # TODO: need to check for 'print labels' permission here also
if self.print_labels: if self.print_labels:
g.more_actions.append(GridAction('print_label', icon='print')) g.more_actions.append(grids.GridAction('print_label', icon='print'))
def template_kwargs_index(self, **kwargs): def template_kwargs_index(self, **kwargs):
if self.print_labels: if self.print_labels: