Просмотр исходного кода

Merge pull request #8873 from minitriga/issue_8457

Closes: #8457 - Nonracked  Devices Location/Site
Jeremy Stretch 3 лет назад
Родитель
Сommit
52de50aa64

+ 12 - 0
netbox/dcim/views.py

@@ -328,6 +328,11 @@ class SiteView(generic.ObjectView):
             'device_count',
             cumulative=True
         ).restrict(request.user, 'view').filter(site=instance)
+        nonracked_devices = Device.objects.filter(
+            site=instance,
+            position__isnull=True,
+            parent_bay__isnull=True
+        ).prefetch_related('device_type__manufacturer')
 
         asns = ASN.objects.restrict(request.user, 'view').filter(sites=instance)
         asn_count = asns.count()
@@ -338,6 +343,7 @@ class SiteView(generic.ObjectView):
             'stats': stats,
             'locations': locations,
             'asns': asns,
+            'nonracked_devices': nonracked_devices,
         }
 
 
@@ -415,11 +421,17 @@ class LocationView(generic.ObjectView):
         ).filter(pk__in=location_ids).exclude(pk=instance.pk)
         child_locations_table = tables.LocationTable(child_locations)
         paginate_table(child_locations_table, request)
+        nonracked_devices = Device.objects.filter(
+            location=instance,
+            position__isnull=True,
+            parent_bay__isnull=True
+        ).prefetch_related('device_type__manufacturer')
 
         return {
             'rack_count': rack_count,
             'device_count': device_count,
             'child_locations_table': child_locations_table,
+            'nonracked_devices': nonracked_devices,
         }
 
 

+ 62 - 0
netbox/templates/dcim/inc/nonracked_devices.html

@@ -0,0 +1,62 @@
+{% load helpers %}
+
+<div class="card">
+<h5 class="card-header">
+    Non-Racked Devices
+</h5>
+<div class="card-body">
+{% if nonracked_devices %}
+    <table class="table table-hover">
+        <tr>
+            <th>Name</th>
+            <th>Role</th>
+            <th>Type</th>
+            <th colspan="2">Parent Device</th>
+        </tr>
+        {% 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 }}</a>
+            </td>
+            <td>{{ device.device_role }}</td>
+            <td>{{ device.device_type }}</td>
+            {% if device.parent_bay %}
+                <td><a href="{{ device.parent_bay.device.get_absolute_url }}">{{ device.parent_bay.device }}</a></td>
+                <td>{{ device.parent_bay }}</td>
+            {% else %}
+                <td colspan="2" class="text-muted">&mdash;</td>
+            {% endif %}
+        </tr>
+        {% endfor %}
+    </table>
+    {% else %}
+        <div class="text-muted">
+            None
+        </div>
+    {% endif %}
+    </div>
+    {% if perms.dcim.add_device %}
+        {% if object|meta:'verbose_name' == 'rack' %}
+        <div class="card-footer text-end noprint">
+            <a href="{% url 'dcim:device_add' %}?site={{ object.site.pk }}&rack={{ object.pk }}" class="btn btn-primary btn-sm">
+                <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
+                Add a Non-Racked Device
+            </a>
+        </div>
+        {% elif object|meta:'verbose_name' == 'site' %}
+        <div class="card-footer text-end noprint">
+            <a href="{% url 'dcim:device_add' %}?site={{ object.pk }}" class="btn btn-primary btn-sm">
+                <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
+                Add a Non-Racked Device
+            </a>
+        </div>
+        {% elif object|meta:'verbose_name' == 'location' %}
+        <div class="card-footer text-end noprint">
+            <a href="{% url 'dcim:device_add' %}?site={{ object.site.pk }}&location={{ object.pk }}" class="btn btn-primary btn-sm">
+                <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
+                Add a Non-Racked Device
+            </a>
+        </div>
+        {% endif %}
+    {% endif %}
+</div>

+ 1 - 0
netbox/templates/dcim/location.html

@@ -90,6 +90,7 @@
 	<div class="col col-md-6">
     {% include 'inc/panels/custom_fields.html' %}
     {% include 'inc/panels/contacts.html' %}
+    {% include 'dcim/inc/nonracked_devices.html' %}
     {% include 'inc/panels/image_attachments.html' %}
     {% plugin_right_page object %}
 	</div>

+ 1 - 44
netbox/templates/dcim/rack.html

@@ -288,50 +288,7 @@
               </div>
             </div>
         </div>
-        <div class="card">
-            <h5 class="card-header">
-                Non-Racked Devices
-            </h5>
-            <div class="card-body">
-            {% if nonracked_devices %}
-                <table class="table table-hover">
-                    <tr>
-                        <th>Name</th>
-                        <th>Role</th>
-                        <th>Type</th>
-                        <th colspan="2">Parent Device</th>
-                    </tr>
-                    {% 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 }}</a>
-                        </td>
-                        <td>{{ device.device_role }}</td>
-                        <td>{{ device.device_type }}</td>
-                        {% if device.parent_bay %}
-                            <td><a href="{{ device.parent_bay.device.get_absolute_url }}">{{ device.parent_bay.device }}</a></td>
-                            <td>{{ device.parent_bay }}</td>
-                        {% else %}
-                            <td colspan="2" class="text-muted">&mdash;</td>
-                        {% endif %}
-                    </tr>
-                    {% endfor %}
-                </table>
-            {% else %}
-                <div class="text-muted">
-                    None
-                </div>
-            {% endif %}
-            </div>
-            {% if perms.dcim.add_device %}
-                <div class="card-footer text-end noprint">
-                    <a href="{% url 'dcim:device_add' %}?site={{ object.site.pk }}&rack={{ object.pk }}" class="btn btn-primary btn-sm">
-                        <i class="mdi mdi-plus-thick" aria-hidden="true"></i>
-                        Add a Non-Racked Device
-                    </a>
-                </div>
-            {% endif %}
-        </div>
+        {% include 'dcim/inc/nonracked_devices.html' %}
         {% include 'inc/panels/contacts.html' %}
         {% plugin_right_page object %}
     </div>

+ 1 - 0
netbox/templates/dcim/site.html

@@ -277,6 +277,7 @@
           </table>
         </div>
       </div>
+      {% include 'dcim/inc/nonracked_devices.html' %}
       {% include 'inc/panels/contacts.html' %}
       <div class="card">
         <h5 class="card-header">Locations</h5>