Set default column renderers for grid based on data types

guess this really just moves that logic so it happens earlier
This commit is contained in:
Lance Edgar 2018-06-01 13:02:55 -05:00
parent db645fb393
commit 46c8887c3e

View file

@ -87,7 +87,7 @@ class Grid(object):
self.enums = enums or {} self.enums = enums or {}
self.labels = labels or {} self.labels = labels or {}
self.renderers = renderers or {} self.renderers = self.make_default_renderers(renderers or {})
self.extra_row_class = extra_row_class self.extra_row_class = extra_row_class
self.linked_columns = linked_columns or [] self.linked_columns = linked_columns or []
self.url = url self.url = url
@ -301,7 +301,7 @@ class Grid(object):
column_formats['checkbox'] = self.checkbox_column_format column_formats['checkbox'] = self.checkbox_column_format
if self.renderers: if self.renderers:
kwargs['renderers'] = self.make_webhelpers_grid_renderers() kwargs['renderers'] = self.renderers
if self.extra_row_class: if self.extra_row_class:
kwargs['extra_record_class'] = self.extra_row_class kwargs['extra_record_class'] = self.extra_row_class
if self.linked_columns: if self.linked_columns:
@ -325,16 +325,15 @@ class Grid(object):
if key not in self.sorters]) if key not in self.sorters])
return grid return grid
def make_webhelpers_grid_renderers(self): def make_default_renderers(self, renderers):
""" """
Return a dict of renderers for the webhelpers grid. We honor any Make the default set of column renderers for the grid.
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)
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`.
"""
if self.model_class: if self.model_class:
mapper = orm.class_mapper(self.model_class) mapper = orm.class_mapper(self.model_class)
for prop in mapper.iterate_properties: for prop in mapper.iterate_properties: