From e7b01dc95bd5ab13b573c55622c55e2da871b20e Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 11 Nov 2022 11:30:41 -0800 Subject: [PATCH] 4751 add plugin buttons to list templates --- netbox/extras/plugins/templates.py | 8 ++++++++ netbox/extras/templatetags/plugins.py | 8 ++++++++ netbox/extras/tests/dummy_plugin/template_content.py | 3 +++ netbox/templates/generic/object_list.html | 2 ++ 4 files changed, 21 insertions(+) diff --git a/netbox/extras/plugins/templates.py b/netbox/extras/plugins/templates.py index 5f3d038c6..e9b9a9dca 100644 --- a/netbox/extras/plugins/templates.py +++ b/netbox/extras/plugins/templates.py @@ -63,3 +63,11 @@ class PluginTemplateExtension: automatically handled. """ raise NotImplementedError + + def list_buttons(self): + """ + Buttons that will be rendered and added to the existing list of buttons on the list view. Content + should be returned as an HTML string. Note that content does not need to be marked as safe because this is + automatically handled. + """ + raise NotImplementedError diff --git a/netbox/extras/templatetags/plugins.py b/netbox/extras/templatetags/plugins.py index b2f4ec0a7..eab9e2920 100644 --- a/netbox/extras/templatetags/plugins.py +++ b/netbox/extras/templatetags/plugins.py @@ -73,3 +73,11 @@ def plugin_full_width_page(context, obj): Render all full width page content registered by plugins """ return _get_registered_content(obj, 'full_width_page', context) + + +@register.simple_tag(takes_context=True) +def plugin_list_buttons(context, obj): + """ + Render all list buttons registered by plugins + """ + return _get_registered_content(obj, 'list_buttons', context) diff --git a/netbox/extras/tests/dummy_plugin/template_content.py b/netbox/extras/tests/dummy_plugin/template_content.py index 6151454ea..364768a22 100644 --- a/netbox/extras/tests/dummy_plugin/template_content.py +++ b/netbox/extras/tests/dummy_plugin/template_content.py @@ -16,5 +16,8 @@ class SiteContent(PluginTemplateExtension): def buttons(self): return "SITE CONTENT - BUTTONS" + def list_buttons(self): + return "SITE CONTENT - LIST BUTTONS" + template_extensions = [SiteContent] diff --git a/netbox/templates/generic/object_list.html b/netbox/templates/generic/object_list.html index c58565c31..ad1918e6c 100644 --- a/netbox/templates/generic/object_list.html +++ b/netbox/templates/generic/object_list.html @@ -24,6 +24,8 @@ Context: {% block controls %}
+ {% plugin_list_buttons object %} + {% block extra_controls %}{% endblock %} {% if 'add' in actions %} {% add_button model %}