Enable a plugin to add buttons next to the bulk buttons and use the selection mechanism. #11808

Closed
opened 2025-12-29 21:50:08 +01:00 by adam · 1 comment
Owner

Originally created by @CFrits on GitHub (Nov 4, 2025).

NetBox version

v4.4.4

Feature type

Change to existing functionality

Proposed functionality

A plugin can inject buttons in several places, but not next to the bulk buttons (Edit Selected.. etc) and use the selection mechanism.
The proposal is to add an extra function to the PluginTemplateExtension simular to list_buttons().

Use case

The use case is a plugin which can export a selected nummer of device interfaces to a gitlab file.
The template tag can than be included into the appropriate template files.

netbox/netbox/plugins/templates.py

def extrabulk_buttons(self):
   """
   Buttons that will be rendered and added to the existing list of extra bulk buttons, like "Edit Selected" and
   "Delete selected" 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

netbox/utilities/templatetags/plugins.py

@register.simple_tag(takes_context=True)
def plugin_extrabulk_buttons(context, model):
    """
    Render all extra bulk buttons registered by plugins
    """
    return _get_registered_content(model, 'extrabulk_buttons', context)

netbox/templates/dcim/device/interfaces.html

{% load plugins %}

{% block bulk_extra_controls %}
  {% plugin_extrabulk_buttons object %}
{% endblock bulk_extra_controls %}

netbox/netbox/tests/dummy_plugin/template_content.py

class SamplePluginExtraButtons(PluginTemplateExtension):

    models = ["dcim.device"]

    def __init__(self, context):
        super().__init__(context)

    def extrabulk_buttons(self):
        device = self.context["object"]

        return self.render("sample_netbox_plugin/extrabuttons.html", extra_context={"device": device })

Database changes

No response

External dependencies

No response

Originally created by @CFrits on GitHub (Nov 4, 2025). ### NetBox version v4.4.4 ### Feature type Change to existing functionality ### Proposed functionality A plugin can inject buttons in several places, but not next to the bulk buttons (Edit Selected.. etc) and use the selection mechanism. The proposal is to add an extra function to the PluginTemplateExtension simular to list_buttons(). ### Use case The use case is a plugin which can export a selected nummer of device interfaces to a gitlab file. The template tag can than be included into the appropriate template files. netbox/netbox/plugins/templates.py def extrabulk_buttons(self): """ Buttons that will be rendered and added to the existing list of extra bulk buttons, like "Edit Selected" and "Delete selected" 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 netbox/utilities/templatetags/plugins.py @register.simple_tag(takes_context=True) def plugin_extrabulk_buttons(context, model): """ Render all extra bulk buttons registered by plugins """ return _get_registered_content(model, 'extrabulk_buttons', context) netbox/templates/dcim/device/interfaces.html {% load plugins %} {% block bulk_extra_controls %} {% plugin_extrabulk_buttons object %} {% endblock bulk_extra_controls %} netbox/netbox/tests/dummy_plugin/template_content.py class SamplePluginExtraButtons(PluginTemplateExtension): models = ["dcim.device"] def __init__(self, context): super().__init__(context) def extrabulk_buttons(self): device = self.context["object"] return self.render("sample_netbox_plugin/extrabuttons.html", extra_context={"device": device }) ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurenetbox labels 2025-12-29 21:50:08 +01:00
adam closed this issue 2025-12-29 21:50:08 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 6, 2025):

This can be accomplished by defining custom bulk actions and adding them to the actions defined for the view. See DeviceListView for example:

class DeviceListView(generic.ObjectListView):
    ...
    actions = (AddObject, BulkImport, BulkExport, BulkAddComponents, BulkEdit, BulkRename, BulkDelete)
@jeremystretch commented on GitHub (Nov 6, 2025): This can be accomplished by defining custom bulk actions and adding them to the actions defined for the view. See `DeviceListView` for example: ``` class DeviceListView(generic.ObjectListView): ... actions = (AddObject, BulkImport, BulkExport, BulkAddComponents, BulkEdit, BulkRename, BulkDelete) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11808