From 170afe650bc578de2289edaedbc00c3b66a85427 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 2 Jan 2025 22:35:43 -0600 Subject: [PATCH] fix: add "xref buttons" tool panel for master view also add `url` param for `MasterView.make_button()` --- src/wuttaweb/templates/master/view.mako | 15 ++++++++ src/wuttaweb/views/master.py | 50 ++++++++++++++++++++++++- tests/views/test_master.py | 6 +++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/wuttaweb/templates/master/view.mako b/src/wuttaweb/templates/master/view.mako index b4db013..7d189ef 100644 --- a/src/wuttaweb/templates/master/view.mako +++ b/src/wuttaweb/templates/master/view.mako @@ -33,6 +33,21 @@ % endif +<%def name="tool_panels()"> + ${parent.tool_panels()} + ${self.tool_panel_xref()} + + +<%def name="tool_panel_xref()"> + % if xref_buttons: + + % for button in xref_buttons: + ${button} + % endfor + + % endif + + <%def name="render_vue_templates()"> ${parent.render_vue_templates()} % if master.has_rows: diff --git a/src/wuttaweb/views/master.py b/src/wuttaweb/views/master.py index 0030859..ec7cdf8 100644 --- a/src/wuttaweb/views/master.py +++ b/src/wuttaweb/views/master.py @@ -601,6 +601,8 @@ class MasterView(View): context['rows_grid'] = grid + context['xref_buttons'] = self.get_xref_buttons(obj) + return self.render_to_response('view', context) ############################## @@ -1569,6 +1571,7 @@ class MasterView(View): label, variant=None, primary=False, + url=None, **kwargs, ): """ @@ -1595,10 +1598,17 @@ class MasterView(View): avoids the Buefy vs. Oruga confusion, and the implementation can change in the future. + :param url: Specify this (instead of ``href``) to make the + button act like a link. This will yield something like: + ```` + :param \**kwargs: All remaining kwargs are passed to the underlying ``HTML.tag()`` call, so will be rendered as attributes on the button tag. + **NB.** You cannot specify a ``tag`` kwarg, for technical + reasons. + :returns: HTML literal for the button element. Will be something along the lines of: @@ -1620,7 +1630,45 @@ class MasterView(View): elif primary: btn_kw['type'] = 'is-primary' - return HTML.tag('b-button', **btn_kw) + if url: + btn_kw['href'] = url + + button = HTML.tag('b-button', **btn_kw) + + if url: + # nb. unfortunately HTML.tag() calls its first arg 'tag' + # and so we can't pass a kwarg with that name...so instead + # we patch that into place manually + button = str(button) + button = button.replace('