Skip to content

Commit 8781d03

Browse files
Merge pull request #9067 from jasonyates/FR8920-nonrackeddevices
Limit amount of nonracked devices displayed
2 parents 1266a2f + 23fddf7 commit 8781d03

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

netbox/dcim/views.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def get_extra_context(self, request, instance):
342342
'device_count',
343343
cumulative=True
344344
).restrict(request.user, 'view').filter(site=instance)
345+
345346
nonracked_devices = Device.objects.filter(
346347
site=instance,
347348
position__isnull=True,
@@ -357,7 +358,8 @@ def get_extra_context(self, request, instance):
357358
'stats': stats,
358359
'locations': locations,
359360
'asns': asns,
360-
'nonracked_devices': nonracked_devices,
361+
'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
362+
'total_nonracked_devices_count': nonracked_devices.count(),
361363
}
362364

363365

@@ -435,6 +437,7 @@ def get_extra_context(self, request, instance):
435437
).filter(pk__in=location_ids).exclude(pk=instance.pk)
436438
child_locations_table = tables.LocationTable(child_locations)
437439
child_locations_table.configure(request)
440+
438441
nonracked_devices = Device.objects.filter(
439442
location=instance,
440443
position__isnull=True,
@@ -445,7 +448,8 @@ def get_extra_context(self, request, instance):
445448
'rack_count': rack_count,
446449
'device_count': device_count,
447450
'child_locations_table': child_locations_table,
448-
'nonracked_devices': nonracked_devices,
451+
'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
452+
'total_nonracked_devices_count': nonracked_devices.count(),
449453
}
450454

451455

netbox/templates/dcim/inc/nonracked_devices.html

+41-27
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
11
{% load helpers %}
22

33
<div class="card">
4-
<h5 class="card-header">
5-
Non-Racked Devices
6-
</h5>
7-
<div class="card-body">
8-
{% if nonracked_devices %}
9-
<table class="table table-hover">
10-
<tr>
11-
<th>Name</th>
12-
<th>Role</th>
13-
<th>Type</th>
14-
<th colspan="2">Parent Device</th>
15-
</tr>
16-
{% for device in nonracked_devices %}
17-
<tr{% if device.device_type.u_height %} class="warning"{% endif %}>
18-
<td>
19-
<a href="{% url 'dcim:device' pk=device.pk %}">{{ device }}</a>
20-
</td>
21-
<td>{{ device.device_role }}</td>
22-
<td>{{ device.device_type }}</td>
23-
{% if device.parent_bay %}
24-
<td>{{ device.parent_bay.device|linkify }}</td>
25-
<td>{{ device.parent_bay }}</td>
26-
{% else %}
27-
<td colspan="2" class="text-muted">&mdash;</td>
4+
<h5 class="card-header">
5+
Non-Racked Devices
6+
</h5>
7+
<div class="card-body">
8+
{% if nonracked_devices %}
9+
<table class="table table-hover">
10+
<tr>
11+
<th>Name</th>
12+
<th>Role</th>
13+
<th>Type</th>
14+
<th colspan="2">Parent Device</th>
15+
</tr>
16+
{% for device in nonracked_devices %}
17+
<tr{% if device.device_type.u_height %} class="warning"{% endif %}>
18+
<td>
19+
<a href="{% url 'dcim:device' pk=device.pk %}">{{ device }}</a>
20+
</td>
21+
<td>{{ device.device_role }}</td>
22+
<td>{{ device.device_type }}</td>
23+
{% if device.parent_bay %}
24+
<td>{{ device.parent_bay.device|linkify }}</td>
25+
<td>{{ device.parent_bay }}</td>
26+
{% else %}
27+
<td colspan="2" class="text-muted">&mdash;</td>
28+
{% endif %}
29+
</tr>
30+
{% endfor %}
31+
</table>
32+
33+
{% if total_nonracked_devices_count > nonracked_devices.count %}
34+
{% if object|meta:'verbose_name' == 'site' %}
35+
<div class="text-muted">
36+
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>)
37+
</div>
38+
{% elif object|meta:'verbose_name' == 'location' %}
39+
<div class="text-muted">
40+
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>)
41+
</div>
2842
{% endif %}
29-
</tr>
30-
{% endfor %}
31-
</table>
43+
{% endif %}
44+
3245
{% else %}
3346
<div class="text-muted">
3447
None
3548
</div>
3649
{% endif %}
3750
</div>
51+
3852
{% if perms.dcim.add_device %}
3953
{% if object|meta:'verbose_name' == 'rack' %}
4054
<div class="card-footer text-end noprint">

0 commit comments

Comments
 (0)