From cb6c25f829c43faaa2de739b9b2272d209f62506 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 9 Dec 2022 23:13:28 -0600 Subject: [PATCH] Let view supps give data instead of actual xref button --- tailbone/templates/master/view.mako | 16 +++++++++++---- tailbone/views/master.py | 32 +++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/tailbone/templates/master/view.mako b/tailbone/templates/master/view.mako index f8be8f5b..f6dd584a 100644 --- a/tailbone/templates/master/view.mako +++ b/tailbone/templates/master/view.mako @@ -57,16 +57,24 @@ % if use_buefy: % else:

Cross-Reference

+ % for button in xref_buttons: + ${button} + % endfor % for link in xref_links: ${link} % endfor diff --git a/tailbone/views/master.py b/tailbone/views/master.py index c782b52e..c96270b7 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -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): """