Add "most of" Buefy support for grid filters

still a couple of details to wrap up yet, but this is most of it!
This commit is contained in:
Lance Edgar 2019-04-15 18:36:14 -05:00
parent 23c38e33d4
commit a0cd1f4cd0
8 changed files with 313 additions and 96 deletions

View file

@ -384,6 +384,7 @@ class Grid(object):
def render_grid(self, template='/grids/grid.mako', **kwargs):
context = kwargs
context['grid'] = self
context['request'] = self.request
grid_class = ''
if self.width == 'full':
grid_class = 'full'
@ -912,10 +913,57 @@ class Grid(object):
def render_buefy(self, template='/grids/buefy.mako', **kwargs):
"""
Render the Buefy grid, including filters.
Render the Buefy grid, complete with filters. Note that this also
includes the context menu items and grid tools.
"""
if 'grid_columns' not in kwargs:
kwargs['grid_columns'] = self.get_buefy_columns()
if 'grid_data' not in kwargs:
kwargs['grid_data'] = self.get_buefy_data()
if 'static_data' not in kwargs:
kwargs['static_data'] = self.has_static_data()
if self.filterable and 'filters_data' not in kwargs:
kwargs['filters_data'] = self.get_filters_data()
if self.filterable and 'filters_sequence' not in kwargs:
kwargs['filters_sequence'] = self.get_filters_sequence()
return self.render_complete(template=template, **kwargs)
def get_filters_sequence(self):
"""
Returns a list of filter keys (strings) in the sequence with which they
should be displayed in the UI.
"""
return list(self.filters)
def get_filters_data(self):
"""
Returns a dict of current filters data, for use with Buefy grid view.
"""
data = {}
for filtr in self.filters.values():
valueless = [v for v in filtr.valueless_verbs
if v in filtr.verbs]
data[filtr.key] = {
'key': filtr.key,
'label': filtr.label,
'active': filtr.active,
'visible': filtr.active,
'verbs': filtr.verbs,
'valueless_verbs': valueless,
'verb_labels': filtr.verb_labels,
'verb': filtr.verb or filtr.default_verb or filtr.verbs[0],
'value': filtr.value,
}
return data
def render_filters(self, template='/grids/filters.mako', **kwargs):
"""
Render the filters to a Unicode string, using the specified template.