From 87d8322b85d41316b0d7054fa222a8d7b678c2cc Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 22 Sep 2021 16:42:49 -0500 Subject: [PATCH] Add way to override grid action label rendering so that custom HTML can be embedded in there somehow.. --- tailbone/grids/core.py | 11 +++++++++++ tailbone/templates/grids/buefy.mako | 2 +- tailbone/views/master.py | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index a4d3cc92..1e6787fa 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -1434,6 +1434,17 @@ class GridAction(object): return self.url(row, i) return self.url + def render_label(self): + """ + Render the label "text" within the actions column of a grid + row. Most actions have a static label that never varies, but + you can override this to add e.g. HTML content. Note that the + return value will be treated / rendered as HTML whether or not + it contains any, so perhaps be careful that it is trusted + content. + """ + return self.label + class URLMaker(object): """ diff --git a/tailbone/templates/grids/buefy.mako b/tailbone/templates/grids/buefy.mako index b55ff30e..63deddc9 100644 --- a/tailbone/templates/grids/buefy.mako +++ b/tailbone/templates/grids/buefy.mako @@ -201,7 +201,7 @@ % endif > - ${action.label} + ${action.render_label()|n}   % endfor diff --git a/tailbone/views/master.py b/tailbone/views/master.py index f2634328..a4210ba2 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -2251,14 +2251,16 @@ class MasterView(View): return self.request.route_url('{}.delete'.format(self.get_route_prefix()), **self.get_action_route_kwargs(row)) - def make_action(self, key, url=None, **kwargs): + def make_action(self, key, url=None, factory=None, **kwargs): """ Make a new :class:`GridAction` instance for the current grid. """ if url is None: route = '{}.{}'.format(self.get_route_prefix(), key) url = lambda r, i: self.request.route_url(route, **self.get_action_route_kwargs(r)) - return grids.GridAction(key, url=url, **kwargs) + if not factory: + factory = grids.GridAction + return factory(key, url=url, **kwargs) def get_action_route_kwargs(self, row): """