mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
Closes #3461: Fail gracefully on custom link rendering exception
This commit is contained in:
parent
8a4293a4cc
commit
b5455ed882
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
|
* [#3461](https://github.com/netbox-community/netbox/issues/3461) - Fail gracefully on custom link rendering exception
|
||||||
* [#3705](https://github.com/netbox-community/netbox/issues/3705) - Provide request context when executing custom scripts
|
* [#3705](https://github.com/netbox-community/netbox/issues/3705) - Provide request context when executing custom scripts
|
||||||
* [#3762](https://github.com/netbox-community/netbox/issues/3762) - Add date/time picker widgets
|
* [#3762](https://github.com/netbox-community/netbox/issues/3762) - Add date/time picker widgets
|
||||||
* [#3788](https://github.com/netbox-community/netbox/issues/3788) - Enable partial search for inventory items
|
* [#3788](https://github.com/netbox-community/netbox/issues/3788) - Enable partial search for inventory items
|
||||||
|
@ -46,12 +46,17 @@ def custom_links(obj):
|
|||||||
|
|
||||||
# Add non-grouped links
|
# Add non-grouped links
|
||||||
else:
|
else:
|
||||||
text_rendered = render_jinja2(cl.text, context)
|
try:
|
||||||
if text_rendered:
|
text_rendered = render_jinja2(cl.text, context)
|
||||||
link_target = ' target="_blank"' if cl.new_window else ''
|
if text_rendered:
|
||||||
template_code += LINK_BUTTON.format(
|
link_rendered = render_jinja2(cl.url, context)
|
||||||
cl.url, link_target, cl.button_class, text_rendered
|
link_target = ' target="_blank"' if cl.new_window else ''
|
||||||
)
|
template_code += LINK_BUTTON.format(
|
||||||
|
link_rendered, link_target, cl.button_class, text_rendered
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
template_code += '<a class="btn btn-sm btn-default" disabled="disabled" title="{}">' \
|
||||||
|
'<i class="fa fa-warning"></i> {}</a>\n'.format(e, cl.name)
|
||||||
|
|
||||||
# Add grouped links to template
|
# Add grouped links to template
|
||||||
for group, links in group_names.items():
|
for group, links in group_names.items():
|
||||||
@ -59,11 +64,17 @@ def custom_links(obj):
|
|||||||
links_rendered = []
|
links_rendered = []
|
||||||
|
|
||||||
for cl in links:
|
for cl in links:
|
||||||
text_rendered = render_jinja2(cl.text, context)
|
try:
|
||||||
if text_rendered:
|
text_rendered = render_jinja2(cl.text, context)
|
||||||
link_target = ' target="_blank"' if cl.new_window else ''
|
if text_rendered:
|
||||||
|
link_target = ' target="_blank"' if cl.new_window else ''
|
||||||
|
links_rendered.append(
|
||||||
|
GROUP_LINK.format(cl.url, link_target, cl.text)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
links_rendered.append(
|
links_rendered.append(
|
||||||
GROUP_LINK.format(cl.url, link_target, cl.text)
|
'<li><a disabled="disabled" title="{}"><span class="text-muted">'
|
||||||
|
'<i class="fa fa-warning"></i> {}</span></a></li>'.format(e, cl.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
if links_rendered:
|
if links_rendered:
|
||||||
@ -71,7 +82,4 @@ def custom_links(obj):
|
|||||||
links[0].button_class, group, ''.join(links_rendered)
|
links[0].button_class, group, ''.join(links_rendered)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Render template
|
return mark_safe(template_code)
|
||||||
rendered = render_jinja2(template_code, context)
|
|
||||||
|
|
||||||
return mark_safe(rendered)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user