Add way to override grid action label rendering

so that custom HTML can be embedded in there somehow..
This commit is contained in:
Lance Edgar 2021-09-22 16:42:49 -05:00
parent b229b409b0
commit 87d8322b85
3 changed files with 16 additions and 3 deletions

View file

@ -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):
"""

View file

@ -201,7 +201,7 @@
% endif
>
<i class="fas fa-${action.icon}"></i>
${action.label}
${action.render_label()|n}
</a>
&nbsp;
% endfor

View file

@ -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):
"""