Let view supps give data instead of actual xref button
This commit is contained in:
parent
05a3e3f805
commit
cb6c25f829
|
@ -57,16 +57,24 @@
|
|||
% if use_buefy:
|
||||
<nav class="panel">
|
||||
<p class="panel-heading">Cross-Reference</p>
|
||||
<div class="panel-block">
|
||||
% for link in xref_links:
|
||||
${link}
|
||||
% endfor
|
||||
<div class="panel-block buttons">
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
% for button in xref_buttons:
|
||||
${button}
|
||||
% endfor
|
||||
% for link in xref_links:
|
||||
${link}
|
||||
% endfor
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
% else:
|
||||
<div class="object-helper">
|
||||
<h3>Cross-Reference</h3>
|
||||
<div class="object-helper-content">
|
||||
% for button in xref_buttons:
|
||||
${button}
|
||||
% endfor
|
||||
% for link in xref_links:
|
||||
${link}
|
||||
% endfor
|
||||
|
|
|
@ -2510,13 +2510,40 @@ class MasterView(View):
|
|||
def get_xref_buttons(self, obj):
|
||||
buttons = []
|
||||
for supp in self.iter_view_supplements():
|
||||
buttons.extend(supp.get_xref_buttons(obj))
|
||||
buttons.extend(supp.get_xref_buttons(obj) or [])
|
||||
buttons = self.normalize_xref_buttons(buttons)
|
||||
return buttons
|
||||
|
||||
def normalize_xref_buttons(self, buttons):
|
||||
normal = []
|
||||
for button in buttons:
|
||||
|
||||
# build a button if only given the data
|
||||
if isinstance(button, dict):
|
||||
button = self.make_xref_button(**button)
|
||||
|
||||
normal.append(button)
|
||||
return normal
|
||||
|
||||
def make_xref_button(self, **kwargs):
|
||||
|
||||
# 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 = HTML.tag('b-button', type='is-primary',
|
||||
href=kwargs['url'], target='_blank',
|
||||
icon_pack='fas', icon_left='external-link-alt',
|
||||
c=kwargs['text'])
|
||||
button = six.text_type(button)
|
||||
button = button.replace('target="_blank"',
|
||||
'target="_blank" tag="a"')
|
||||
button = HTML.literal(button)
|
||||
return button
|
||||
|
||||
def get_xref_links(self, obj):
|
||||
links = []
|
||||
for supp in self.iter_view_supplements():
|
||||
links.extend(supp.get_xref_links(obj))
|
||||
links.extend(supp.get_xref_links(obj) or [])
|
||||
return links
|
||||
|
||||
def template_kwargs_edit(self, **kwargs):
|
||||
|
@ -5079,6 +5106,7 @@ class ViewSupplement(object):
|
|||
self.master = master
|
||||
self.request = master.request
|
||||
self.model = master.model
|
||||
self.rattail_config = master.rattail_config
|
||||
|
||||
def get_grid_query(self, query):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue