From b8df05cf88b21f1165b43160329a3a617ffb2a11 Mon Sep 17 00:00:00 2001 From: Ichabond Date: Thu, 2 Nov 2017 08:51:27 -0700 Subject: [PATCH] Fixes #1655. Removed explicit field references. (#1656) * Fixes #1655 Further field name references were found in `consoleport.html`. These have now been removed, so we rely on proper a proper `__str__` implementation of both `ConsolePort` and `ConsoleServerPort`. * Fixes #1655: Removed explicit field references Cleaned up all (notable) .name references, and removed them so __str__ can do the lifting. Did not remove the references where it was explicitly referenced to .name (eg. in details). Extended the Secret model to also include the name in __str__, since that was weirdly absent. * Adapted PR to comply with comments Re-introduced certain references to make sure explicit references are still used where needed. --- netbox/secrets/models.py | 3 +++ netbox/templates/circuits/circuit.html | 2 +- netbox/templates/dcim/device.html | 8 ++++---- netbox/templates/dcim/devicebay_populate.html | 2 +- netbox/templates/dcim/inc/consoleport.html | 4 ++-- netbox/templates/dcim/inc/consoleserverport.html | 2 +- netbox/templates/dcim/inc/device_header.html | 2 +- netbox/templates/dcim/inc/devicebay.html | 2 +- netbox/templates/dcim/inc/interface.html | 4 ++-- netbox/templates/dcim/inc/inventoryitem.html | 2 +- netbox/templates/dcim/inc/poweroutlet.html | 4 ++-- netbox/templates/dcim/inc/powerport.html | 4 ++-- netbox/templates/dcim/rack.html | 8 ++++---- netbox/templates/dcim/site.html | 4 ++-- netbox/templates/ipam/prefix.html | 6 +++--- netbox/templates/ipam/vlan.html | 8 ++++---- netbox/templates/virtualization/inc/interface.html | 2 +- netbox/templates/virtualization/virtualmachine.html | 4 ++-- 18 files changed, 37 insertions(+), 34 deletions(-) diff --git a/netbox/secrets/models.py b/netbox/secrets/models.py index ded93ed58..317fe0dd5 100644 --- a/netbox/secrets/models.py +++ b/netbox/secrets/models.py @@ -286,6 +286,9 @@ class Secret(CreatedUpdatedModel): super(Secret, self).__init__(*args, **kwargs) def __str__(self): + if self.role and self.device and self.name: + return '{} for {} ({})'.format(self.role, self.device, self.name) + # Return role and device if no name is set if self.role and self.device: return '{} for {}'.format(self.role, self.device) return 'Secret' diff --git a/netbox/templates/circuits/circuit.html b/netbox/templates/circuits/circuit.html index ce375daef..027efa83c 100644 --- a/netbox/templates/circuits/circuit.html +++ b/netbox/templates/circuits/circuit.html @@ -65,7 +65,7 @@ {% if circuit.tenant %} {% if circuit.tenant.group %} - {{ circuit.tenant.group.name }} + {{ circuit.tenant.group }} {% endif %} {{ circuit.tenant }} diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 9625a002c..056396991 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -28,10 +28,10 @@ {% if device.rack %} {% if device.rack.group %} - {{ device.rack.group.name }} + {{ device.rack.group }} {% endif %} - {{ device.rack.name }}{% if device.rack.facility_id %} ({{ device.rack.facility_id }}){% endif %} + {{ device.rack }} {% else %} None {% endif %} @@ -42,7 +42,7 @@ {% if device.parent_bay %} {% with device.parent_bay.device as parent %} - {{ parent }} {{ device.parent_bay.name }} + {{ parent }} {{ device.parent_bay }} {% if parent.position %} (U{{ parent.position }} / {{ parent.get_face_display }}) {% endif %} @@ -61,7 +61,7 @@ {% if device.tenant %} {% if device.tenant.group %} - {{ device.tenant.group.name }} + {{ device.tenant.group }} {% endif %} {{ device.tenant }} diff --git a/netbox/templates/dcim/devicebay_populate.html b/netbox/templates/dcim/devicebay_populate.html index d328d557d..38a8d57da 100644 --- a/netbox/templates/dcim/devicebay_populate.html +++ b/netbox/templates/dcim/devicebay_populate.html @@ -26,7 +26,7 @@
-

{{ device_bay.name }}

+

{{ device_bay }}

{% render_form form %} diff --git a/netbox/templates/dcim/inc/consoleport.html b/netbox/templates/dcim/inc/consoleport.html index 34c08af94..62375c7f2 100644 --- a/netbox/templates/dcim/inc/consoleport.html +++ b/netbox/templates/dcim/inc/consoleport.html @@ -1,13 +1,13 @@ - {{ cp.name }} + {{ cp }} {% if cp.cs_port %} {{ cp.cs_port.device }} - {{ cp.cs_port.name }} + {{ cp.cs_port }} {% else %} diff --git a/netbox/templates/dcim/inc/consoleserverport.html b/netbox/templates/dcim/inc/consoleserverport.html index 69dbfc0b8..62da09245 100644 --- a/netbox/templates/dcim/inc/consoleserverport.html +++ b/netbox/templates/dcim/inc/consoleserverport.html @@ -13,7 +13,7 @@ {{ csp.connected_console.device }} - {{ csp.connected_console.name }} + {{ csp.connected_console }} {% else %} diff --git a/netbox/templates/dcim/inc/device_header.html b/netbox/templates/dcim/inc/device_header.html index 37c5e715a..73b5845ef 100644 --- a/netbox/templates/dcim/inc/device_header.html +++ b/netbox/templates/dcim/inc/device_header.html @@ -8,7 +8,7 @@ {% endif %} {% if device.parent_bay %}
  • {{ device.parent_bay.device }}
  • -
  • {{ device.parent_bay.name }}
  • +
  • {{ device.parent_bay }}
  • {% endif %}
  • {{ device }}
  • diff --git a/netbox/templates/dcim/inc/devicebay.html b/netbox/templates/dcim/inc/devicebay.html index f69299bfb..f974f9fcb 100644 --- a/netbox/templates/dcim/inc/devicebay.html +++ b/netbox/templates/dcim/inc/devicebay.html @@ -5,7 +5,7 @@ {% endif %} - {{ devicebay.name }} + {{ devicebay }} {% if devicebay.installed_device %} diff --git a/netbox/templates/dcim/inc/interface.html b/netbox/templates/dcim/inc/interface.html index 7e133da8d..c6d36dbef 100644 --- a/netbox/templates/dcim/inc/interface.html +++ b/netbox/templates/dcim/inc/interface.html @@ -6,9 +6,9 @@ {% endif %} - {{ iface.name }} + {{ iface }} {% if iface.lag %} - {{ iface.lag.name }} + {{ iface.lag }} {% endif %} {% if iface.description %} diff --git a/netbox/templates/dcim/inc/inventoryitem.html b/netbox/templates/dcim/inc/inventoryitem.html index 8bc3149b1..21de1014e 100644 --- a/netbox/templates/dcim/inc/inventoryitem.html +++ b/netbox/templates/dcim/inc/inventoryitem.html @@ -1,5 +1,5 @@ - {{ item.name }} + {{ item }} {% if not item.discovered %}{% endif %} {{ item.manufacturer|default:"" }} {{ item.part_id }} diff --git a/netbox/templates/dcim/inc/poweroutlet.html b/netbox/templates/dcim/inc/poweroutlet.html index 061b3c682..b462e1ca1 100644 --- a/netbox/templates/dcim/inc/poweroutlet.html +++ b/netbox/templates/dcim/inc/poweroutlet.html @@ -5,7 +5,7 @@ {% endif %} - {{ po.name }} + {{ po }} {% if po.connected_port %} @@ -13,7 +13,7 @@ {{ po.connected_port.device }} - {{ po.connected_port.name }} + {{ po.connected_port }} {% else %} diff --git a/netbox/templates/dcim/inc/powerport.html b/netbox/templates/dcim/inc/powerport.html index 06ec9da75..555d6d3ee 100644 --- a/netbox/templates/dcim/inc/powerport.html +++ b/netbox/templates/dcim/inc/powerport.html @@ -1,13 +1,13 @@ - {{ pp.name }} + {{ pp }} {% if pp.power_outlet %} {{ pp.power_outlet.device }} - {{ pp.power_outlet.name }} + {{ pp.power_outlet }} {% else %} diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 4463ee21b..05585348f 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -49,7 +49,7 @@ {% endif %} -

    {% block title %}Rack {{ rack.name }}{% endblock %}

    +

    {% block title %}Rack {{ rack }}{% endblock %}

    {% include 'inc/created_updated.html' with obj=rack %}
    @@ -72,7 +72,7 @@ Group {% if rack.group %} - {{ rack.group.name }} + {{ rack.group }} {% else %} None {% endif %} @@ -93,7 +93,7 @@ {% if rack.tenant %} {% if rack.tenant.group %} - {{ rack.tenant.group.name }} + {{ rack.tenant.group }} {% endif %} {{ rack.tenant }} @@ -173,7 +173,7 @@ {% for device in nonracked_devices %} - {{ device.name }} + {{ device }} {{ device.device_role }} {{ device.device_type.full_name }} diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index c178fbf64..228eec4c8 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -76,7 +76,7 @@ {% if site.tenant %} {% if site.tenant.group %} - {{ site.tenant.group.name }} + {{ site.tenant.group }} {% endif %} {{ site.tenant }} @@ -221,7 +221,7 @@ {% for rg in rack_groups %} - + {% endfor %} diff --git a/netbox/templates/ipam/prefix.html b/netbox/templates/ipam/prefix.html index 23a996d82..25780ba5e 100644 --- a/netbox/templates/ipam/prefix.html +++ b/netbox/templates/ipam/prefix.html @@ -30,13 +30,13 @@ {% endif %}
    {{ rg.name }} {{ rg }} {{ rg.rack_count }}
    {% if prefix.tenant %} {% if prefix.tenant.group %} - {{ prefix.tenant.group.name }} + {{ prefix.tenant.group }} {% endif %} {{ prefix.tenant }} {% elif prefix.vrf.tenant %} {% if prefix.vrf.tenant.group %} - {{ prefix.vrf.tenant.group.name }} + {{ prefix.vrf.tenant.group }} {% endif %} {{ prefix.vrf.tenant }} @@ -75,7 +75,7 @@ {% if prefix.vlan %} {% if prefix.vlan.group %} - {{ prefix.vlan.group.name }} + {{ prefix.vlan.group }} {% endif %} {{ prefix.vlan.display_name }} diff --git a/netbox/templates/ipam/vlan.html b/netbox/templates/ipam/vlan.html index 4298e9b46..ae353e823 100644 --- a/netbox/templates/ipam/vlan.html +++ b/netbox/templates/ipam/vlan.html @@ -9,9 +9,9 @@
  • {{ vlan.site }}
  • {% endif %} {% if vlan.group %} -
  • {{ vlan.group.name }}
  • +
  • {{ vlan.group }}
  • {% endif %} -
  • {{ vlan.name }} ({{ vlan.vid }})
  • +
  • {{ vlan }}
  • @@ -68,7 +68,7 @@
    Group {% if vlan.group %} - {{ vlan.group.name }} + {{ vlan.group }} {% else %} None {% endif %} @@ -87,7 +87,7 @@ {% if vlan.tenant %} {% if vlan.tenant.group %} - {{ vlan.tenant.group.name }} + {{ vlan.tenant.group }} {% endif %} {{ vlan.tenant }} diff --git a/netbox/templates/virtualization/inc/interface.html b/netbox/templates/virtualization/inc/interface.html index ef37561bb..bea4758d7 100644 --- a/netbox/templates/virtualization/inc/interface.html +++ b/netbox/templates/virtualization/inc/interface.html @@ -5,7 +5,7 @@ - {{ iface.name }} + {{ iface }} {% if iface.description %} {% endif %} diff --git a/netbox/templates/virtualization/virtualmachine.html b/netbox/templates/virtualization/virtualmachine.html index cb83142ea..194461a90 100644 --- a/netbox/templates/virtualization/virtualmachine.html +++ b/netbox/templates/virtualization/virtualmachine.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@
    Name{{ vm.name }}{{ vm }}
    Status {% if vm.tenant %} {% if vm.tenant.group %} - {{ vm.tenant.group.name }} + {{ vm.tenant.group }} {% endif %} {{ vm.tenant }}