Skip to content

Commit

Permalink
#10500: Cleanup (#17305)
Browse files Browse the repository at this point in the history
* Use MPTTColumn for module bays

* Fix return URLs

* Omit extraneous relationships from nested serializers

* Add note re: v4.1
  • Loading branch information
jeremystretch authored Aug 29, 2024
1 parent 9a11191 commit db6246a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions docs/models/dcim/modulebay.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The device to which this module bay belongs.

### Module

!!! info "This feature was introduced in NetBox v4.1."

The module to which this bay belongs (optional).

### Name
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/api/serializers_/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class ModuleBaySerializer(NetBoxModelSerializer):
device = DeviceSerializer(nested=True)
module = ModuleSerializer(
nested=True,
fields=('id', 'url', 'display', 'module_bay'),
fields=('id', 'url', 'display'),
required=False,
allow_null=True,
default=None
Expand Down
3 changes: 1 addition & 2 deletions netbox/dcim/api/serializers_/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class Meta:


class NestedModuleBaySerializer(WritableNestedSerializer):
installed_module = ModuleBayNestedModuleSerializer(required=False, allow_null=True)

class Meta:
model = models.ModuleBay
fields = ['id', 'url', 'display_url', 'display', 'installed_module', 'name']
fields = ['id', 'url', 'display_url', 'display', 'name']
8 changes: 3 additions & 5 deletions netbox/dcim/tables/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,10 @@ def render_installed_module(self, value):


class DeviceModuleBayTable(ModuleBayTable):
name = tables.TemplateColumn(
name = columns.MPTTColumn(
verbose_name=_('Name'),
template_code='<a href="{{ record.get_absolute_url }}" style="padding-left: {{ record.level }}0px">'
'{{ value }}</a>',
order_by=Accessor('_name'),
attrs={'td': {'class': 'text-nowrap'}}
linkify=True,
order_by=Accessor('_name')
)
actions = columns.ActionsColumn(
extra_buttons=MODULEBAY_BUTTONS
Expand Down
16 changes: 8 additions & 8 deletions netbox/templates/dcim/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@
</button>
<ul class="dropdown-menu" aria-labeled-by="add-components">
{% if perms.dcim.add_consoleport %}
<li><a class="dropdown-item" href="{% url 'dcim:consoleport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_consoleports' pk=object.device.pk %}">{% trans "Console Ports" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:consoleport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Console Ports" %}</a></li>
{% endif %}
{% if perms.dcim.add_consoleserverport %}
<li><a class="dropdown-item" href="{% url 'dcim:consoleserverport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_consoleserverports' pk=object.device.pk %}">{% trans "Console Server Ports" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:consoleserverport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Console Server Ports" %}</a></li>
{% endif %}
{% if perms.dcim.add_powerport %}
<li><a class="dropdown-item" href="{% url 'dcim:powerport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_powerports' pk=object.device.pk %}">{% trans "Power Ports" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:powerport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Power Ports" %}</a></li>
{% endif %}
{% if perms.dcim.add_poweroutlet %}
<li><a class="dropdown-item" href="{% url 'dcim:poweroutlet_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_poweroutlets' pk=object.device.pk %}">{% trans "Power Outlets" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:poweroutlet_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Power Outlets" %}</a></li>
{% endif %}
{% if perms.dcim.add_interface %}
<li><a class="dropdown-item" href="{% url 'dcim:interface_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_interfaces' pk=object.device.pk %}">{% trans "Interfaces" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:interface_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Interfaces" %}</a></li>
{% endif %}
{% if perms.dcim.add_frontport %}
<li><a class="dropdown-item" href="{% url 'dcim:frontport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_frontports' pk=object.device.pk %}">{% trans "Front Ports" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:frontport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Front Ports" %}</a></li>
{% endif %}
{% if perms.dcim.add_rearport %}
<li><a class="dropdown-item" href="{% url 'dcim:rearport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_rearports' pk=object.device.pk %}">{% trans "Rear Ports" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:rearport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Rear Ports" %}</a></li>
{% endif %}
{% if perms.dcim.add_modulebay %}
<li><a class="dropdown-item" href="{% url 'dcim:modulebay_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_modulebays' pk=object.pk %}">{% trans "Module Bays" %}</a></li>
<li><a class="dropdown-item" href="{% url 'dcim:modulebay_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={{ object.get_absolute_url }}">{% trans "Module Bays" %}</a></li>
{% endif %}
</ul>
</div>
Expand Down

0 comments on commit db6246a

Please sign in to comment.