From 0953bba0a3771affac8a4312d08a14ce7cbb3f0c Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 24 Feb 2022 16:33:51 -0500 Subject: [PATCH] Closes #8747: Rename ObjectListView action_buttons to actions --- docs/plugins/development/templates.md | 16 ++++----- netbox/dcim/views.py | 28 +++++++-------- netbox/extras/views.py | 6 ++-- netbox/ipam/views.py | 2 +- netbox/netbox/views/generic/bulk_views.py | 6 ++-- netbox/templates/generic/object_list.html | 43 +++++++++++------------ netbox/virtualization/views.py | 2 +- 7 files changed, 50 insertions(+), 53 deletions(-) diff --git a/docs/plugins/development/templates.md b/docs/plugins/development/templates.md index 61ffd3ce2..755206951 100644 --- a/docs/plugins/development/templates.md +++ b/docs/plugins/development/templates.md @@ -126,14 +126,14 @@ This template is used by the `ObjectListView` generic view to display a filterab #### Context -| Name | Required | Description | -|------------------|----------|-----------------------------------------------------------------------| -| `model` | Yes | The object class | -| `table` | Yes | The table class used for rendering the list of objects | -| `permissions` | Yes | A mapping of add, change, and delete permissions for the current user | -| `action_buttons` | Yes | A list of buttons to display (options are `add`, `import`, `export`) | -| `filter_form` | - | The bound filterset form for filtering the objects list | -| `return_url` | - | The return URL to pass when submitting a bulk operation form | +| Name | Required | Description | +|---------------|----------|---------------------------------------------------------------------------------------------| +| `model` | Yes | The object class | +| `table` | Yes | The table class used for rendering the list of objects | +| `permissions` | Yes | A mapping of add, change, and delete permissions for the current user | +| `actions` | Yes | A list of buttons to display (`add`, `import`, `export`, `bulk_edit`, and/or `bulk_delete`) | +| `filter_form` | - | The bound filterset form for filtering the objects list | +| `return_url` | - | The return URL to pass when submitting a bulk operation form | ### bulk_import.html diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index eb189b457..06dd5367f 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1812,7 +1812,7 @@ class ConsolePortListView(generic.ObjectListView): filterset = filtersets.ConsolePortFilterSet filterset_form = forms.ConsolePortFilterForm table = tables.ConsolePortTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class ConsolePortView(generic.ObjectView): @@ -1871,7 +1871,7 @@ class ConsoleServerPortListView(generic.ObjectListView): filterset = filtersets.ConsoleServerPortFilterSet filterset_form = forms.ConsoleServerPortFilterForm table = tables.ConsoleServerPortTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class ConsoleServerPortView(generic.ObjectView): @@ -1930,7 +1930,7 @@ class PowerPortListView(generic.ObjectListView): filterset = filtersets.PowerPortFilterSet filterset_form = forms.PowerPortFilterForm table = tables.PowerPortTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class PowerPortView(generic.ObjectView): @@ -1989,7 +1989,7 @@ class PowerOutletListView(generic.ObjectListView): filterset = filtersets.PowerOutletFilterSet filterset_form = forms.PowerOutletFilterForm table = tables.PowerOutletTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class PowerOutletView(generic.ObjectView): @@ -2048,7 +2048,7 @@ class InterfaceListView(generic.ObjectListView): filterset = filtersets.InterfaceFilterSet filterset_form = forms.InterfaceFilterForm table = tables.InterfaceTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class InterfaceView(generic.ObjectView): @@ -2170,7 +2170,7 @@ class FrontPortListView(generic.ObjectListView): filterset = filtersets.FrontPortFilterSet filterset_form = forms.FrontPortFilterForm table = tables.FrontPortTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class FrontPortView(generic.ObjectView): @@ -2237,7 +2237,7 @@ class RearPortListView(generic.ObjectListView): filterset = filtersets.RearPortFilterSet filterset_form = forms.RearPortFilterForm table = tables.RearPortTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class RearPortView(generic.ObjectView): @@ -2296,7 +2296,7 @@ class ModuleBayListView(generic.ObjectListView): filterset = filtersets.ModuleBayFilterSet filterset_form = forms.ModuleBayFilterForm table = tables.ModuleBayTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class ModuleBayView(generic.ObjectView): @@ -2352,7 +2352,7 @@ class DeviceBayListView(generic.ObjectListView): filterset = filtersets.DeviceBayFilterSet filterset_form = forms.DeviceBayFilterForm table = tables.DeviceBayTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class DeviceBayView(generic.ObjectView): @@ -2474,7 +2474,7 @@ class InventoryItemListView(generic.ObjectListView): filterset = filtersets.InventoryItemFilterSet filterset_form = forms.InventoryItemFilterForm table = tables.InventoryItemTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class InventoryItemView(generic.ObjectView): @@ -2707,7 +2707,7 @@ class CableListView(generic.ObjectListView): filterset = filtersets.CableFilterSet filterset_form = forms.CableFilterForm table = tables.CableTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class CableView(generic.ObjectView): @@ -2874,7 +2874,7 @@ class ConsoleConnectionsListView(generic.ObjectListView): filterset_form = forms.ConsoleConnectionFilterForm table = tables.ConsoleConnectionTable template_name = 'dcim/connections_list.html' - action_buttons = ('export',) + actions = ('export',) def get_extra_context(self, request): return { @@ -2888,7 +2888,7 @@ class PowerConnectionsListView(generic.ObjectListView): filterset_form = forms.PowerConnectionFilterForm table = tables.PowerConnectionTable template_name = 'dcim/connections_list.html' - action_buttons = ('export',) + actions = ('export',) def get_extra_context(self, request): return { @@ -2902,7 +2902,7 @@ class InterfaceConnectionsListView(generic.ObjectListView): filterset_form = forms.InterfaceConnectionFilterForm table = tables.InterfaceConnectionTable template_name = 'dcim/connections_list.html' - action_buttons = ('export',) + actions = ('export',) def get_extra_context(self, request): return { diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 903cdea64..4ad17df98 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -269,7 +269,7 @@ class ConfigContextListView(generic.ObjectListView): filterset = filtersets.ConfigContextFilterSet filterset_form = forms.ConfigContextFilterForm table = tables.ConfigContextTable - action_buttons = ('add',) + actions = ('add', 'bulk_edit', 'bulk_delete') class ConfigContextView(generic.ObjectView): @@ -366,7 +366,7 @@ class ObjectChangeListView(generic.ObjectListView): filterset_form = forms.ObjectChangeFilterForm table = tables.ObjectChangeTable template_name = 'extras/objectchange_list.html' - action_buttons = ('export',) + actions = ('export',) class ObjectChangeView(generic.ObjectView): @@ -458,7 +458,7 @@ class JournalEntryListView(generic.ObjectListView): filterset = filtersets.JournalEntryFilterSet filterset_form = forms.JournalEntryFilterForm table = tables.JournalEntryTable - action_buttons = ('export',) + actions = ('export', 'bulk_edit', 'bulk_delete') class JournalEntryView(generic.ObjectView): diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 25b2506c6..fbb1e5820 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -1080,7 +1080,7 @@ class ServiceListView(generic.ObjectListView): filterset = filtersets.ServiceFilterSet filterset_form = forms.ServiceFilterForm table = tables.ServiceTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class ServiceView(generic.ObjectView): diff --git a/netbox/netbox/views/generic/bulk_views.py b/netbox/netbox/views/generic/bulk_views.py index 4ebbe2d7d..4de8bfef0 100644 --- a/netbox/netbox/views/generic/bulk_views.py +++ b/netbox/netbox/views/generic/bulk_views.py @@ -42,12 +42,12 @@ class ObjectListView(BaseMultiObjectView): Attributes: filterset: A django-filter FilterSet that is applied to the queryset filterset_form: The form class used to render filter options - action_buttons: A list of buttons to include at the top of the page + actions: Supported actions for the model. Default options are add, import, export, bulk_edit, and bulk_delete """ template_name = 'generic/object_list.html' filterset = None filterset_form = None - action_buttons = ('add', 'import', 'export') + actions = ('add', 'import', 'export', 'bulk_edit', 'bulk_delete') def get_required_permission(self): return get_permission_for_model(self.queryset.model, 'view') @@ -180,7 +180,7 @@ class ObjectListView(BaseMultiObjectView): 'model': model, 'table': table, 'permissions': permissions, - 'action_buttons': self.action_buttons, + 'actions': self.actions, 'filter_form': self.filterset_form(request.GET, label_suffix='') if self.filterset_form else None, **self.get_extra_context(request), } diff --git a/netbox/templates/generic/object_list.html b/netbox/templates/generic/object_list.html index 2958f3473..2d0494502 100644 --- a/netbox/templates/generic/object_list.html +++ b/netbox/templates/generic/object_list.html @@ -16,7 +16,8 @@ Context: permissions: A mapping of add/change/delete permissions to boolean indicating whether the current user possesses each of them. Controls the display of add/edit/delete buttons. - action_buttons: A list of buttons to display. Options are add, import, export. + actions: A list of buttons to display. This template checks for add, import, + export, bulk_edit, and bulk_delete. filter_form: The bound filterset form for filtering the objects list (optional) return_url: Return URL to use for bulk actions (optional) {% endcomment %} @@ -27,13 +28,13 @@ Context:
{% block extra_controls %}{% endblock %} - {% if permissions.add and 'add' in action_buttons %} + {% if permissions.add and 'add' in actions %} {% add_button model|validated_viewname:"add" %} {% endif %} - {% if permissions.add and 'import' in action_buttons %} + {% if permissions.add and 'import' in actions %} {% import_button model|validated_viewname:"import" %} {% endif %} - {% if 'export' in action_buttons %} + {% if 'export' in actions %} {% export_button model|content_type %} {% endif %}
@@ -115,25 +116,21 @@ Context:
{# Form buttons #} - {% if permissions.change or permissions.delete %} - {% with bulk_edit_url=model|validated_viewname:"bulk_edit" bulk_delete_url=model|validated_viewname:"bulk_delete" %} -
-
- {% block bulk_buttons %}{% endblock %} - {% if bulk_edit_url and permissions.change %} - - {% endif %} - {% if bulk_delete_url and permissions.delete %} - - {% endif %} -
-
- {% endwith %} - {% endif %} +
+
+ {% block bulk_buttons %}{% endblock %} + {% if 'bulk_edit' in actions and permissions.change %} + + {% endif %} + {% if 'bulk_delete' in actions and permissions.delete %} + + {% endif %} +
+
diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index 88e23048a..fe4b162ce 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -404,7 +404,7 @@ class VMInterfaceListView(generic.ObjectListView): filterset = filtersets.VMInterfaceFilterSet filterset_form = forms.VMInterfaceFilterForm table = tables.VMInterfaceTable - action_buttons = ('import', 'export') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') class VMInterfaceView(generic.ObjectView):