Fix master view get_effective_data() for v3 grids

used when creating new batch from product results etc.

this also tweaks purchase credits view a bit
This commit is contained in:
Lance Edgar 2017-07-14 16:43:49 -05:00
parent 82f4a6efcd
commit 2a9cf3db49
3 changed files with 41 additions and 3 deletions

View file

@ -96,6 +96,12 @@ class Grid(object):
if key in self.columns:
self.columns.remove(key)
def set_joiner(self, key, joiner):
self.joiners[key] = joiner
def set_sorter(self, key, *args, **kwargs):
self.sorters[key] = self.make_sorter(*args, **kwargs)
def set_label(self, key, label):
self.labels[key] = label
if key in self.filters:
@ -216,7 +222,7 @@ class Grid(object):
column_formats['checkbox'] = self.checkbox_column_format
if self.renderers:
kwargs['renderers'] = dict(self.renderers)
kwargs['renderers'] = self.make_webhelpers_grid_renderers()
if self.extra_row_class:
kwargs['extra_record_class'] = self.extra_row_class
if self.linked_columns:
@ -240,6 +246,20 @@ class Grid(object):
if key not in self.sorters])
return grid
def make_webhelpers_grid_renderers(self):
"""
Return a dict of renderers for the webhelpers grid. We honor any
existing renderers which have already been set, but then we also try to
supplement that by auto-assigning renderers based on underlying column
type. Note that this special logic only applies to grids with a valid
:attr:`model_class`.
"""
renderers = dict(self.renderers)
# for column in self.columns:
# if column not in renderers:
# pass
return renderers
def checkbox_column_format(self, column_number, row_number, item):
return HTML.td(self.render_checkbox(item), class_='checkbox')

View file

@ -102,6 +102,18 @@ class MasterView2(MasterView):
grid.load_settings()
return grid
def get_effective_data(self, session=None, **kwargs):
"""
Convenience method which returns the "effective" data for the master
grid, filtered and sorted to match what would show on the UI, but not
paged etc.
"""
if session is None:
session = self.Session()
kwargs.setdefault('pageable', False)
grid = self.make_grid(session=session, **kwargs)
return grid.make_visible_data()
def make_row_grid(self, factory=None, key=None, data=None, columns=None, **kwargs):
"""
Make and return a new (configured) rows grid instance.

View file

@ -44,6 +44,8 @@ class PurchaseCreditView(MasterView):
grid_columns = [
'vendor',
'invoice_number',
'invoice_date',
'upc',
'brand_name',
'description',
@ -51,6 +53,7 @@ class PurchaseCreditView(MasterView):
'cases_shorted',
'units_shorted',
'credit_type',
'mispick_upc',
'date_received',
'status',
]
@ -58,20 +61,23 @@ class PurchaseCreditView(MasterView):
def configure_grid(self, g):
super(PurchaseCreditView, self).configure_grid(g)
g.joiners['vendor'] = lambda q: q.outerjoin(model.Vendor)
g.sorters['vendor'] = g.make_sorter(model.Vendor.name)
g.set_joiner('vendor', lambda q: q.outerjoin(model.Vendor))
g.set_sorter('vendor', model.Vendor.name)
g.default_sortkey = 'date_received'
g.default_sortdir = 'desc'
# g.set_type('upc', 'gpc')
g.set_type('cases_shorted', 'quantity')
g.set_type('units_shorted', 'quantity')
g.set_label('invoice_number', "Invoice No.")
g.set_label('upc', "UPC")
g.set_label('brand_name', "Brand")
g.set_label('cases_shorted', "Cases")
g.set_label('units_shorted', "Units")
g.set_label('credit_type', "Type")
g.set_label('mispick_upc', "Mispick UPC")
g.set_label('date_received', "Date")