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

Merge pull request #9067 from jasonyates/FR8920-nonrackeddevices

Limit amount of nonracked devices displayed
Jeremy Stretch 3 лет назад
Родитель
Сommit
8781d03aa7
2 измененных файлов с 47 добавлено и 29 удалено
  1. 6 2
      netbox/dcim/views.py
  2. 41 27
      netbox/templates/dcim/inc/nonracked_devices.html

+ 6 - 2
netbox/dcim/views.py

@@ -342,6 +342,7 @@ 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,
@@ -357,7 +358,8 @@ class SiteView(generic.ObjectView):
             'stats': stats,
             'locations': locations,
             'asns': asns,
-            'nonracked_devices': nonracked_devices,
+            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
+            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 
@@ -435,6 +437,7 @@ class LocationView(generic.ObjectView):
         ).filter(pk__in=location_ids).exclude(pk=instance.pk)
         child_locations_table = tables.LocationTable(child_locations)
         child_locations_table.configure(request)
+
         nonracked_devices = Device.objects.filter(
             location=instance,
             position__isnull=True,
@@ -445,7 +448,8 @@ class LocationView(generic.ObjectView):
             'rack_count': rack_count,
             'device_count': device_count,
             'child_locations_table': child_locations_table,
-            'nonracked_devices': nonracked_devices,
+            'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
+            'total_nonracked_devices_count': nonracked_devices.count(),
         }
 
 

+ 41 - 27
netbox/templates/dcim/inc/nonracked_devices.html

@@ -1,40 +1,54 @@
 {% 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>{{ device.parent_bay.device|linkify }}</td>
-                <td>{{ device.parent_bay }}</td>
-            {% else %}
-                <td colspan="2" class="text-muted">&mdash;</td>
+    <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>{{ device.parent_bay.device|linkify }}</td>
+                    <td>{{ device.parent_bay }}</td>
+                {% else %}
+                    <td colspan="2" class="text-muted">&mdash;</td>
+                {% endif %}
+            </tr>
+            {% endfor %}
+        </table>
+
+        {%  if total_nonracked_devices_count > nonracked_devices.count %}
+            {% if object|meta:'verbose_name' == 'site' %}
+                <div class="text-muted">
+                    Displaying {{ nonracked_devices.count }} of {{ total_nonracked_devices_count }} devices (<a href="{% url 'dcim:device_list' %}?site_id={{ object.pk }}&rack_id=null">View full list</a>)
+                </div>
+            {% elif object|meta:'verbose_name' == 'location' %}
+                <div class="text-muted">
+                    Displaying {{ nonracked_devices.count }} of {{ total_nonracked_devices_count }} devices (<a href="{% url 'dcim:device_list' %}?location_id={{ object.pk }}&rack_id=null">View full list</a>)
+                </div>
             {% endif %}
-        </tr>
-        {% endfor %}
-    </table>
+        {% endif %}
+
     {% 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">