fix: add "xref buttons" tool panel for master view
also add `url` param for `MasterView.make_button()`
This commit is contained in:
parent
0631b8e16b
commit
170afe650b
|
@ -33,6 +33,21 @@
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="tool_panels()">
|
||||||
|
${parent.tool_panels()}
|
||||||
|
${self.tool_panel_xref()}
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="tool_panel_xref()">
|
||||||
|
% if xref_buttons:
|
||||||
|
<wutta-tool-panel heading="Cross-Reference">
|
||||||
|
% for button in xref_buttons:
|
||||||
|
${button}
|
||||||
|
% endfor
|
||||||
|
</wutta-tool-panel>
|
||||||
|
% endif
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="render_vue_templates()">
|
<%def name="render_vue_templates()">
|
||||||
${parent.render_vue_templates()}
|
${parent.render_vue_templates()}
|
||||||
% if master.has_rows:
|
% if master.has_rows:
|
||||||
|
|
|
@ -601,6 +601,8 @@ class MasterView(View):
|
||||||
|
|
||||||
context['rows_grid'] = grid
|
context['rows_grid'] = grid
|
||||||
|
|
||||||
|
context['xref_buttons'] = self.get_xref_buttons(obj)
|
||||||
|
|
||||||
return self.render_to_response('view', context)
|
return self.render_to_response('view', context)
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
|
@ -1569,6 +1571,7 @@ class MasterView(View):
|
||||||
label,
|
label,
|
||||||
variant=None,
|
variant=None,
|
||||||
primary=False,
|
primary=False,
|
||||||
|
url=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -1595,10 +1598,17 @@ class MasterView(View):
|
||||||
avoids the Buefy vs. Oruga confusion, and the
|
avoids the Buefy vs. Oruga confusion, and the
|
||||||
implementation can change in the future.
|
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:
|
||||||
|
``<b-button tag="a" href="{url}">``
|
||||||
|
|
||||||
:param \**kwargs: All remaining kwargs are passed to the
|
:param \**kwargs: All remaining kwargs are passed to the
|
||||||
underlying ``HTML.tag()`` call, so will be rendered as
|
underlying ``HTML.tag()`` call, so will be rendered as
|
||||||
attributes on the button tag.
|
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
|
:returns: HTML literal for the button element. Will be something
|
||||||
along the lines of:
|
along the lines of:
|
||||||
|
|
||||||
|
@ -1620,7 +1630,45 @@ class MasterView(View):
|
||||||
elif primary:
|
elif primary:
|
||||||
btn_kw['type'] = 'is-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('<b-button ',
|
||||||
|
'<b-button tag="a" ')
|
||||||
|
button = HTML.literal(button)
|
||||||
|
|
||||||
|
return button
|
||||||
|
|
||||||
|
def get_xref_buttons(self, obj):
|
||||||
|
"""
|
||||||
|
Should return a list of "cross-reference" buttons to be shown
|
||||||
|
when viewing the given object.
|
||||||
|
|
||||||
|
Default logic always returns empty list; subclass can override
|
||||||
|
as needed.
|
||||||
|
|
||||||
|
If applicable, this method should do its own permission checks
|
||||||
|
and only include the buttons current user should be allowed to
|
||||||
|
see/use.
|
||||||
|
|
||||||
|
See also :meth:`make_button()` - example::
|
||||||
|
|
||||||
|
def get_xref_buttons(self, product):
|
||||||
|
buttons = []
|
||||||
|
if self.request.has_perm('external_products.view'):
|
||||||
|
url = self.request.route_url('external_products.view',
|
||||||
|
id=product.external_id)
|
||||||
|
buttons.append(self.make_button("View External", url=url))
|
||||||
|
return buttons
|
||||||
|
"""
|
||||||
|
return []
|
||||||
|
|
||||||
def make_progress(self, key, **kwargs):
|
def make_progress(self, key, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -441,6 +441,12 @@ class TestMasterView(WebTestCase):
|
||||||
self.assertIn('click me', html)
|
self.assertIn('click me', html)
|
||||||
self.assertIn('is-primary', html)
|
self.assertIn('is-primary', html)
|
||||||
|
|
||||||
|
# with url
|
||||||
|
html = view.make_button('click me', url='http://example.com')
|
||||||
|
self.assertIn('<b-button tag="a"', html)
|
||||||
|
self.assertIn('click me', html)
|
||||||
|
self.assertIn('href="http://example.com"', html)
|
||||||
|
|
||||||
def test_make_progress(self):
|
def test_make_progress(self):
|
||||||
|
|
||||||
# basic
|
# basic
|
||||||
|
|
Loading…
Reference in a new issue