diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index f932b7994..4df1dec71 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -111,8 +111,7 @@ class ComponentTemplateTable(BaseTable): class ConsolePortTemplateTable(ComponentTemplateTable): actions = ButtonsColumn( model=ConsolePortTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_consoleports' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -124,8 +123,7 @@ class ConsolePortTemplateTable(ComponentTemplateTable): class ConsoleServerPortTemplateTable(ComponentTemplateTable): actions = ButtonsColumn( model=ConsoleServerPortTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_consoleserverports' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -137,8 +135,7 @@ class ConsoleServerPortTemplateTable(ComponentTemplateTable): class PowerPortTemplateTable(ComponentTemplateTable): actions = ButtonsColumn( model=PowerPortTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_powerports' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -150,8 +147,7 @@ class PowerPortTemplateTable(ComponentTemplateTable): class PowerOutletTemplateTable(ComponentTemplateTable): actions = ButtonsColumn( model=PowerOutletTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_poweroutlets' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -166,8 +162,7 @@ class InterfaceTemplateTable(ComponentTemplateTable): ) actions = ButtonsColumn( model=InterfaceTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_interfaces' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -183,8 +178,7 @@ class FrontPortTemplateTable(ComponentTemplateTable): color = ColorColumn() actions = ButtonsColumn( model=FrontPortTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_frontports' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): @@ -196,9 +190,7 @@ class FrontPortTemplateTable(ComponentTemplateTable): class RearPortTemplateTable(ComponentTemplateTable): color = ColorColumn() actions = ButtonsColumn( - model=RearPortTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_rearports' + model=RearPortTemplate ) class Meta(ComponentTemplateTable.Meta): @@ -210,8 +202,7 @@ class RearPortTemplateTable(ComponentTemplateTable): class DeviceBayTemplateTable(ComponentTemplateTable): actions = ButtonsColumn( model=DeviceBayTemplate, - buttons=('edit', 'delete'), - return_url_extra='%23tab_devicebays' + buttons=('edit', 'delete') ) class Meta(ComponentTemplateTable.Meta): diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 3180d47b1..5c5b6b8d3 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -51,10 +51,21 @@ class DeviceComponentsView(generic.ObjectChildrenView): class DeviceTypeComponentsView(DeviceComponentsView): queryset = DeviceType.objects.all() template_name = 'dcim/devicetype/component_templates.html' + viewname = None # Used for return_url resolution def get_children(self, request, parent): return self.child_model.objects.restrict(request.user, 'view').filter(device_type=parent) + def get_extra_context(self, request, instance): + if self.viewname: + return_url = reverse(self.viewname, kwargs={'pk': instance.pk}) + else: + return_url = instance.get_absolute_url() + return { + 'active_tab': f"{self.child_model._meta.verbose_name_plural.replace(' ', '-')}", + 'return_url': return_url, + } + class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View): """ @@ -798,48 +809,56 @@ class DeviceTypeConsolePortsView(DeviceTypeComponentsView): child_model = ConsolePortTemplate table = tables.ConsolePortTemplateTable filterset = filtersets.ConsolePortTemplateFilterSet + viewname = 'dcim:devicetype_consoleports' class DeviceTypeConsoleServerPortsView(DeviceTypeComponentsView): child_model = ConsoleServerPortTemplate table = tables.ConsoleServerPortTemplateTable filterset = filtersets.ConsoleServerPortTemplateFilterSet + viewname = 'dcim:devicetype_consoleserverports' class DeviceTypePowerPortsView(DeviceTypeComponentsView): child_model = PowerPortTemplate table = tables.PowerPortTemplateTable filterset = filtersets.PowerPortTemplateFilterSet + viewname = 'dcim:devicetype_powerports' class DeviceTypePowerOutletsView(DeviceTypeComponentsView): child_model = PowerOutletTemplate table = tables.PowerOutletTemplateTable filterset = filtersets.PowerOutletTemplateFilterSet + viewname = 'dcim:devicetype_poweroutlets' class DeviceTypeInterfacesView(DeviceTypeComponentsView): child_model = InterfaceTemplate table = tables.InterfaceTemplateTable filterset = filtersets.InterfaceTemplateFilterSet + viewname = 'dcim:devicetype_interfaces' class DeviceTypeFrontPortsView(DeviceTypeComponentsView): child_model = FrontPortTemplate table = tables.FrontPortTemplateTable filterset = filtersets.FrontPortTemplateFilterSet + viewname = 'dcim:devicetype_frontports' class DeviceTypeRearPortsView(DeviceTypeComponentsView): child_model = RearPortTemplate table = tables.RearPortTemplateTable filterset = filtersets.RearPortTemplateFilterSet + viewname = 'dcim:devicetype_rearports' class DeviceTypeDeviceBaysView(DeviceTypeComponentsView): child_model = DeviceBayTemplate table = tables.DeviceBayTemplateTable filterset = filtersets.DeviceBayTemplateFilterSet + viewname = 'dcim:devicetype_devicebays' class DeviceTypeEditView(generic.ObjectEditView): diff --git a/netbox/templates/dcim/device/base.html b/netbox/templates/dcim/device/base.html index 13d4bbcbc..705a51eea 100644 --- a/netbox/templates/dcim/device/base.html +++ b/netbox/templates/dcim/device/base.html @@ -95,74 +95,74 @@ - {% with interface_count=object.interfaces_count %} - {% if interface_count %} + {% with tab_name='interfaces' interface_count=object.interfaces_count %} + {% if active_tab == tab_name or interface_count %} {% endif %} {% endwith %} - {% with frontport_count=object.frontports.count %} - {% if frontport_count %} + {% with tab_name='front-ports' frontport_count=object.frontports.count %} + {% if active_tab == tab_name or frontport_count %} {% endif %} {% endwith %} - {% with rearport_count=object.rearports.count %} - {% if rearport_count %} + {% with tab_name='rear-ports' rearport_count=object.rearports.count %} + {% if active_tab == tab_name or rearport_count %} {% endif %} {% endwith %} - {% with consoleport_count=object.consoleports.count %} - {% if consoleport_count %} + {% with tab_name='console-ports' consoleport_count=object.consoleports.count %} + {% if active_tab == tab_name or consoleport_count %} {% endif %} {% endwith %} - {% with consoleserverport_count=object.consoleserverports.count %} - {% if consoleserverport_count %} + {% with tab_name='console-server-ports' consoleserverport_count=object.consoleserverports.count %} + {% if active_tab == tab_name or consoleserverport_count %} {% endif %} {% endwith %} - {% with powerport_count=object.powerports.count %} - {% if powerport_count %} + {% with tab_name='power-ports' powerport_count=object.powerports.count %} + {% if active_tab == tab_name or powerport_count %} {% endif %} {% endwith %} - {% with poweroutlet_count=object.poweroutlets.count %} - {% if poweroutlet_count %} + {% with tab_name='power-outlets' poweroutlet_count=object.poweroutlets.count %} + {% if active_tab == tab_name or poweroutlet_count %} {% endif %} {% endwith %} - {% with devicebay_count=object.devicebays.count %} - {% if devicebay_count %} + {% with tab_name='device-bays' devicebay_count=object.devicebays.count %} + {% if active_tab == tab_name or devicebay_count %} {% endif %} {% endwith %} - {% with inventoryitem_count=object.inventoryitems.count %} - {% if inventoryitem_count %} + {% with tab_name='inventory-items' inventoryitem_count=object.inventoryitems.count %} + {% if active_tab == tab_name or inventoryitem_count %} {% endif %} {% endwith %} diff --git a/netbox/templates/dcim/device/devicebays.html b/netbox/templates/dcim/device/devicebays.html index 2d66e860d..6ab387513 100644 --- a/netbox/templates/dcim/device/devicebays.html +++ b/netbox/templates/dcim/device/devicebays.html @@ -17,22 +17,22 @@
{% if perms.dcim.change_devicebay %} - - {% endif %} {% if perms.dcim.delete_devicebay %} - {% endif %}
{% if perms.dcim.add_devicebay %}
- + Add Device Bays
diff --git a/netbox/templates/dcim/devicetype/base.html b/netbox/templates/dcim/devicetype/base.html index a06886de5..b3c161002 100644 --- a/netbox/templates/dcim/devicetype/base.html +++ b/netbox/templates/dcim/devicetype/base.html @@ -18,28 +18,28 @@
@@ -53,66 +53,66 @@ - {% with interface_count=object.interfacetemplates.count %} - {% if interface_count %} + {% with tab_name='interface-templates' interface_count=object.interfacetemplates.count %} + {% if active_tab == tab_name or interface_count %} {% endif %} {% endwith %} - {% with frontport_count=object.frontporttemplates.count %} - {% if frontport_count %} + {% with tab_name='front-port-templates' frontport_count=object.frontporttemplates.count %} + {% if active_tab == tab_name or frontport_count %} {% endif %} {% endwith %} - {% with rearport_count=object.rearporttemplates.count %} - {% if rearport_count %} + {% with tab_name='rear-port-templates' rearport_count=object.rearporttemplates.count %} + {% if active_tab == tab_name or rearport_count %} {% endif %} {% endwith %} - {% with consoleport_count=object.consoleporttemplates.count %} - {% if consoleport_count %} + {% with tab_name='console-port-templates' consoleport_count=object.consoleporttemplates.count %} + {% if active_tab == tab_name or consoleport_count %} {% endif %} {% endwith %} - {% with consoleserverport_count=object.consoleserverporttemplates.count %} - {% if consoleserverport_count %} + {% with tab_name='console-server-port-templates' consoleserverport_count=object.consoleserverporttemplates.count %} + {% if active_tab == tab_name or consoleserverport_count %} {% endif %} {% endwith %} - {% with powerport_count=object.powerporttemplates.count %} - {% if powerport_count %} + {% with tab_name='power-port-templates' powerport_count=object.powerporttemplates.count %} + {% if active_tab == tab_name or powerport_count %} {% endif %} {% endwith %} - {% with poweroutlet_count=object.poweroutlettemplates.count %} - {% if poweroutlet_count %} + {% with tab_name='power-outlet-templates' poweroutlet_count=object.poweroutlettemplates.count %} + {% if active_tab == tab_name or poweroutlet_count %} {% endif %} {% endwith %} - {% with devicebay_count=object.devicebaytemplates.count %} - {% if devicebay_count %} + {% with tab_name='device-bay-templates' devicebay_count=object.devicebaytemplates.count %} + {% if active_tab == tab_name or devicebay_count %} {% endif %} {% endwith %} diff --git a/netbox/templates/dcim/devicetype/component_templates.html b/netbox/templates/dcim/devicetype/component_templates.html index b1e0daf78..002a2044b 100644 --- a/netbox/templates/dcim/devicetype/component_templates.html +++ b/netbox/templates/dcim/devicetype/component_templates.html @@ -13,18 +13,18 @@