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:
|
% if use_buefy:
|
||||||
<nav class="panel">
|
<nav class="panel">
|
||||||
<p class="panel-heading">Cross-Reference</p>
|
<p class="panel-heading">Cross-Reference</p>
|
||||||
<div class="panel-block">
|
<div class="panel-block buttons">
|
||||||
|
<div style="display: flex; flex-direction: column;">
|
||||||
|
% for button in xref_buttons:
|
||||||
|
${button}
|
||||||
|
% endfor
|
||||||
% for link in xref_links:
|
% for link in xref_links:
|
||||||
${link}
|
${link}
|
||||||
% endfor
|
% endfor
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
% else:
|
% else:
|
||||||
<div class="object-helper">
|
<div class="object-helper">
|
||||||
<h3>Cross-Reference</h3>
|
<h3>Cross-Reference</h3>
|
||||||
<div class="object-helper-content">
|
<div class="object-helper-content">
|
||||||
|
% for button in xref_buttons:
|
||||||
|
${button}
|
||||||
|
% endfor
|
||||||
% for link in xref_links:
|
% for link in xref_links:
|
||||||
${link}
|
${link}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
|
@ -2510,13 +2510,40 @@ class MasterView(View):
|
||||||
def get_xref_buttons(self, obj):
|
def get_xref_buttons(self, obj):
|
||||||
buttons = []
|
buttons = []
|
||||||
for supp in self.iter_view_supplements():
|
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
|
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):
|
def get_xref_links(self, obj):
|
||||||
links = []
|
links = []
|
||||||
for supp in self.iter_view_supplements():
|
for supp in self.iter_view_supplements():
|
||||||
links.extend(supp.get_xref_links(obj))
|
links.extend(supp.get_xref_links(obj) or [])
|
||||||
return links
|
return links
|
||||||
|
|
||||||
def template_kwargs_edit(self, **kwargs):
|
def template_kwargs_edit(self, **kwargs):
|
||||||
|
@ -5079,6 +5106,7 @@ class ViewSupplement(object):
|
||||||
self.master = master
|
self.master = master
|
||||||
self.request = master.request
|
self.request = master.request
|
||||||
self.model = master.model
|
self.model = master.model
|
||||||
|
self.rattail_config = master.rattail_config
|
||||||
|
|
||||||
def get_grid_query(self, query):
|
def get_grid_query(self, query):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue