Browse Source

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.
Ichabond 7 years ago
parent
commit
b8df05cf88

+ 3 - 0
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'

+ 1 - 1
netbox/templates/circuits/circuit.html

@@ -65,7 +65,7 @@
                     <td>
                         {% if circuit.tenant %}
                             {% if circuit.tenant.group %}
-                                <a href="{{ circuit.tenant.group.get_absolute_url }}">{{ circuit.tenant.group.name }}</a>
+                                <a href="{{ circuit.tenant.group.get_absolute_url }}">{{ circuit.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ circuit.tenant.get_absolute_url }}">{{ circuit.tenant }}</a>

+ 4 - 4
netbox/templates/dcim/device.html

@@ -28,10 +28,10 @@
                     <td>
                         {% if device.rack %}
                             {% if device.rack.group %}
-                                <a href="{{ device.rack.group.get_absolute_url }}">{{ device.rack.group.name }}</a>
+                                <a href="{{ device.rack.group.get_absolute_url }}">{{ device.rack.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
-                            <a href="{% url 'dcim:rack' pk=device.rack.pk %}">{{ device.rack.name }}</a>{% if device.rack.facility_id %} ({{ device.rack.facility_id }}){% endif %}
+                            <a href="{% url 'dcim:rack' pk=device.rack.pk %}">{{ device.rack }}</a>
                         {% else %}
                             <span class="text-muted">None</span>
                         {% endif %}
@@ -42,7 +42,7 @@
                     <td>
                         {% if device.parent_bay %}
                             {% with device.parent_bay.device as parent %}
-                                <a href="{{ parent.get_absolute_url }}">{{ parent }}</a> <i class="fa fa-angle-right"></i> {{ device.parent_bay.name }}
+                                <a href="{{ parent.get_absolute_url }}">{{ parent }}</a> <i class="fa fa-angle-right"></i> {{ device.parent_bay }}
                                 {% if parent.position %}
                                     (U{{ parent.position }} / {{ parent.get_face_display }})
                                 {% endif %}
@@ -61,7 +61,7 @@
                     <td>
                         {% if device.tenant %}
                             {% if device.tenant.group %}
-                                <a href="{{ device.tenant.group.get_absolute_url }}">{{ device.tenant.group.name }}</a>
+                                <a href="{{ device.tenant.group.get_absolute_url }}">{{ device.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ device.tenant.get_absolute_url }}">{{ device.tenant }}</a>

+ 1 - 1
netbox/templates/dcim/devicebay_populate.html

@@ -26,7 +26,7 @@
                     <div class="form-group">
                         <label class="col-md-3 control-label required">Bay</label>
                         <div class="col-md-9">
-                            <p class="form-control-static">{{ device_bay.name }}</p>
+                            <p class="form-control-static">{{ device_bay }}</p>
                         </div>
                     </div>
                     {% render_form form %}

+ 2 - 2
netbox/templates/dcim/inc/consoleport.html

@@ -1,13 +1,13 @@
 <tr class="consoleport{% if cp.cs_port and not cp.connection_status %} info{% endif %}">
     <td>
-        <i class="fa fa-fw fa-keyboard-o"></i> {{ cp.name }}
+        <i class="fa fa-fw fa-keyboard-o"></i> {{ cp }}
     </td>
     {% if cp.cs_port %}
         <td>
             <a href="{% url 'dcim:device' pk=cp.cs_port.device.pk %}">{{ cp.cs_port.device }}</a>
         </td>
         <td>
-            {{ cp.cs_port.name }}
+            {{ cp.cs_port }}
         </td>
     {% else %}
         <td colspan="2">

+ 1 - 1
netbox/templates/dcim/inc/consoleserverport.html

@@ -13,7 +13,7 @@
             <a href="{% url 'dcim:device' pk=csp.connected_console.device.pk %}">{{ csp.connected_console.device }}</a>
         </td>
         <td>
-            {{ csp.connected_console.name }}
+            {{ csp.connected_console }}
         </td>
     {% else %}
         <td colspan="2">

+ 1 - 1
netbox/templates/dcim/inc/device_header.html

@@ -8,7 +8,7 @@
         {% endif %}
         {% if device.parent_bay %}
             <li><a href="{% url 'dcim:device' pk=device.parent_bay.device.pk %}">{{ device.parent_bay.device }}</a></li>
-            <li>{{ device.parent_bay.name }}</li>
+            <li>{{ device.parent_bay }}</li>
         {% endif %}
         <li>{{ device }}</li>
     </ol>

+ 1 - 1
netbox/templates/dcim/inc/devicebay.html

@@ -5,7 +5,7 @@
         </td>
     {% endif %}
     <td>
-        <i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i> {{ devicebay.name }}
+        <i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i> {{ devicebay }}
     </td>
     {% if devicebay.installed_device %}
         <td>

+ 2 - 2
netbox/templates/dcim/inc/interface.html

@@ -6,9 +6,9 @@
     {% endif %}
     <td>
         <i class="fa fa-fw fa-{% if iface.mgmt_only %}wrench{% elif iface.is_virtual %}square{% elif iface.is_wireless %}wifi{% else %}exchange{% endif %}"></i>
-        <span title="{{ iface.get_form_factor_display }}">{{ iface.name }}</span>
+        <span title="{{ iface.get_form_factor_display }}">{{ iface }}</span>
         {% if iface.lag %}
-            <span class="label label-primary">{{ iface.lag.name }}</span>
+            <span class="label label-primary">{{ iface.lag }}</span>
         {% endif %}
         {% if iface.description %}
             <i class="fa fa-fw fa-comment-o" title="{{ iface.description }}"></i>

+ 1 - 1
netbox/templates/dcim/inc/inventoryitem.html

@@ -1,5 +1,5 @@
 <tr>
-    <td style="padding-left: {{ indent|add:5 }}px">{{ item.name }}</td>
+    <td style="padding-left: {{ indent|add:5 }}px">{{ item }}</td>
     <td>{% if not item.discovered %}<i class="fa fa-asterisk" title="Manually created"></i>{% endif %}</td>
     <td>{{ item.manufacturer|default:"" }}</td>
     <td>{{ item.part_id }}</td>

+ 2 - 2
netbox/templates/dcim/inc/poweroutlet.html

@@ -5,7 +5,7 @@
         </td>
     {% endif %}
     <td>
-        <i class="fa fa-fw fa-bolt"></i> {{ po.name }}
+        <i class="fa fa-fw fa-bolt"></i> {{ po }}
     </td>
     <td></td>
     {% if po.connected_port %}
@@ -13,7 +13,7 @@
             <a href="{% url 'dcim:device' pk=po.connected_port.device.pk %}">{{ po.connected_port.device }}</a>
         </td>
         <td>
-            {{ po.connected_port.name }}
+            {{ po.connected_port }}
         </td>
     {% else %}
         <td colspan="2">

+ 2 - 2
netbox/templates/dcim/inc/powerport.html

@@ -1,13 +1,13 @@
 <tr class="powerport{% if pp.power_outlet and not pp.connection_status %} info{% endif %}">
     <td>
-        <i class="fa fa-fw fa-bolt"></i> {{ pp.name }}
+        <i class="fa fa-fw fa-bolt"></i> {{ pp }}
     </td>
     {% if pp.power_outlet %}
         <td>
             <a href="{% url 'dcim:device' pk=pp.power_outlet.device.pk %}">{{ pp.power_outlet.device }}</a>
         </td>
         <td>
-            {{ pp.power_outlet.name }}
+            {{ pp.power_outlet }}
         </td>
     {% else %}
         <td colspan="2">

+ 4 - 4
netbox/templates/dcim/rack.html

@@ -49,7 +49,7 @@
 		</a>
     {% endif %}
 </div>
-<h1>{% block title %}Rack {{ rack.name }}{% endblock %}</h1>
+<h1>{% block title %}Rack {{ rack }}{% endblock %}</h1>
 {% include 'inc/created_updated.html' with obj=rack %}
 <div class="row">
 	<div class="col-md-6">
@@ -72,7 +72,7 @@
                     <td>Group</td>
                     <td>
                         {% if rack.group %}
-                            <a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}&group={{ rack.group.slug }}">{{ rack.group.name }}</a>
+                            <a href="{% url 'dcim:rack_list' %}?site={{ rack.site.slug }}&group={{ rack.group.slug }}">{{ rack.group }}</a>
                         {% else %}
                             <span class="text-muted">None</span>
                         {% endif %}
@@ -93,7 +93,7 @@
                     <td>
                         {% if rack.tenant %}
                             {% if rack.tenant.group %}
-                                <a href="{{ rack.tenant.group.get_absolute_url }}">{{ rack.tenant.group.name }}</a>
+                                <a href="{{ rack.tenant.group.get_absolute_url }}">{{ rack.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ rack.tenant.get_absolute_url }}">{{ rack.tenant }}</a>
@@ -173,7 +173,7 @@
                     {% for device in nonracked_devices %}
                         <tr{% if device.device_type.u_height %} class="warning"{% endif %}>
                             <td>
-                                <a href="{% url 'dcim:device' pk=device.pk %}">{{ device.name }}</a>
+                                <a href="{% url 'dcim:device' pk=device.pk %}">{{ device }}</a>
                             </td>
                             <td>{{ device.device_role }}</td>
                             <td>{{ device.device_type.full_name }}</td>

+ 2 - 2
netbox/templates/dcim/site.html

@@ -76,7 +76,7 @@
                     <td>
                         {% if site.tenant %}
                             {% if site.tenant.group %}
-                                <a href="{{ site.tenant.group.get_absolute_url }}">{{ site.tenant.group.name }}</a>
+                                <a href="{{ site.tenant.group.get_absolute_url }}">{{ site.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ site.tenant.get_absolute_url }}">{{ site.tenant }}</a>
@@ -221,7 +221,7 @@
                 <table class="table table-hover panel-body">
                     {% for rg in rack_groups %}
                         <tr>
-                            <td><i class="fa fa-fw fa-folder-o"></i> <a href="{{ rg.get_absolute_url }}">{{ rg.name }}</a></td>
+                            <td><i class="fa fa-fw fa-folder-o"></i> <a href="{{ rg.get_absolute_url }}">{{ rg }}</a></td>
                             <td>{{ rg.rack_count }}</td>
                         </tr>
                     {% endfor %}

+ 3 - 3
netbox/templates/ipam/prefix.html

@@ -30,13 +30,13 @@
                     <td>
                         {% if prefix.tenant %}
                             {% if prefix.tenant.group %}
-                                <a href="{{ prefix.tenant.group.get_absolute_url }}">{{ prefix.tenant.group.name }}</a>
+                                <a href="{{ prefix.tenant.group.get_absolute_url }}">{{ prefix.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ prefix.tenant.get_absolute_url }}">{{ prefix.tenant }}</a>
                         {% elif prefix.vrf.tenant %}
                             {% if prefix.vrf.tenant.group %}
-                                <a href="{{ prefix.vrf.tenant.group.get_absolute_url }}">{{ prefix.vrf.tenant.group.name }}</a>
+                                <a href="{{ prefix.vrf.tenant.group.get_absolute_url }}">{{ prefix.vrf.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ prefix.vrf.tenant.get_absolute_url }}">{{ prefix.vrf.tenant }}</a>
@@ -75,7 +75,7 @@
                     <td>
                         {% if prefix.vlan %}
                             {% if prefix.vlan.group %}
-                                <a href="{{ prefix.vlan.group.get_absolute_url }}">{{ prefix.vlan.group.name }}</a>
+                                <a href="{{ prefix.vlan.group.get_absolute_url }}">{{ prefix.vlan.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{% url 'ipam:vlan' pk=prefix.vlan.pk %}">{{ prefix.vlan.display_name }}</a>

+ 4 - 4
netbox/templates/ipam/vlan.html

@@ -9,9 +9,9 @@
                 <li><a href="{% url 'ipam:vlan_list' %}?site={{ vlan.site.slug }}">{{ vlan.site }}</a></li>
             {% endif %}
             {% if vlan.group %}
-                <li><a href="{% url 'ipam:vlan_list' %}?group={{ vlan.group.slug }}">{{ vlan.group.name }}</a></li>
+                <li><a href="{% url 'ipam:vlan_list' %}?group={{ vlan.group.slug }}">{{ vlan.group }}</a></li>
             {% endif %}
-            <li>{{ vlan.name }} ({{ vlan.vid }})</li>
+            <li>{{ vlan }}</li>
         </ol>
     </div>
     <div class="col-sm-4 col-md-3">
@@ -68,7 +68,7 @@
                     <td>Group</td>
                     <td>
                         {% if vlan.group %}
-                            <a href="{{ vlan.group.get_absolute_url }}">{{ vlan.group.name }}</a>
+                            <a href="{{ vlan.group.get_absolute_url }}">{{ vlan.group }}</a>
                         {% else %}
                             <span class="text-muted">None</span>
                         {% endif %}
@@ -87,7 +87,7 @@
                     <td>
                         {% if vlan.tenant %}
                             {% if vlan.tenant.group %}
-                                <a href="{{ vlan.tenant.group.get_absolute_url }}">{{ vlan.tenant.group.name }}</a>
+                                <a href="{{ vlan.tenant.group.get_absolute_url }}">{{ vlan.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ vlan.tenant.get_absolute_url }}">{{ vlan.tenant }}</a>

+ 1 - 1
netbox/templates/virtualization/inc/interface.html

@@ -5,7 +5,7 @@
         </td>
     {% endif %}
     <td>
-        <i class="fa fa-fw fa-square"></i> <span>{{ iface.name }}</span>
+        <i class="fa fa-fw fa-square"></i> <span>{{ iface }}</span>
         {% if iface.description %}
             <i class="fa fa-fw fa-comment-o" title="{{ iface.description }}"></i>
         {% endif %}

+ 2 - 2
netbox/templates/virtualization/virtualmachine.html

@@ -49,7 +49,7 @@
             <table class="table table-hover panel-body attr-table">
                 <tr>
                     <td>Name</td>
-                    <td>{{ vm.name }}</td>
+                    <td>{{ vm }}</td>
                 </tr>
                 <tr>
                     <td>Status</td>
@@ -82,7 +82,7 @@
                     <td>
                         {% if vm.tenant %}
                             {% if vm.tenant.group %}
-                                <a href="{{ vm.tenant.group.get_absolute_url }}">{{ vm.tenant.group.name }}</a>
+                                <a href="{{ vm.tenant.group.get_absolute_url }}">{{ vm.tenant.group }}</a>
                                 <i class="fa fa-angle-right"></i>
                             {% endif %}
                             <a href="{{ vm.tenant.get_absolute_url }}">{{ vm.tenant }}</a>