From 29877c9abe1e0817624337ce09147a12f6339f0b Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Mon, 28 Aug 2023 13:03:35 -0700 Subject: [PATCH] 12489 Use HTMX for Location and Non-Racked Devices in Site detail view (#12491) * 12489 use htmx for site view locations and non-racked-devices * 12489 remove now unused queries in context * adds device type and role to device component filter #12015 * Revert "Fixes #12463: Fix the association of completed jobs with reports & scripts in the REST API" This reverts commit a29a07ed26b2fe15ea21b000edbede1c20faef93. * 12489 update nonracked_devices on rack and location templates * 12489 fix whitespace issue * Undo errant commits * 12489 update site id in templates * 12489 remove nonracked_devices include * 12489 add has_position filter * Use empty lookup for position field * Remove non-racked devices list from rack view (was moved to a tab) * Clean up location and device tables * Restore plugins block on rack template --------- Co-authored-by: Abhimanyu Saharan Co-authored-by: jeremystretch --- netbox/dcim/views.py | 32 -------- .../templates/dcim/inc/nonracked_devices.html | 76 ------------------- netbox/templates/dcim/location.html | 22 +++++- netbox/templates/dcim/site.html | 72 +++++++----------- 4 files changed, 49 insertions(+), 153 deletions(-) delete mode 100644 netbox/templates/dcim/inc/nonracked_devices.html diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 2f5da4ce1..211a58928 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -398,32 +398,8 @@ class SiteView(generic.ObjectView): (Circuit.objects.restrict(request.user, 'view').filter(terminations__site=instance).distinct(), 'site_id'), ) - locations = Location.objects.add_related_count( - Location.objects.all(), - Rack, - 'location', - 'rack_count', - cumulative=True - ) - locations = Location.objects.add_related_count( - locations, - Device, - 'location', - 'device_count', - cumulative=True - ).restrict(request.user, 'view').filter(site=instance) - - nonracked_devices = Device.objects.filter( - site=instance, - rack__isnull=True, - parent_bay__isnull=True - ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role') - return { 'related_models': related_models, - 'locations': locations, - 'nonracked_devices': nonracked_devices.order_by('-pk')[:10], - 'total_nonracked_devices_count': nonracked_devices.count(), } @@ -495,16 +471,8 @@ class LocationView(generic.ObjectView): (Device.objects.restrict(request.user, 'view').filter(location__in=locations), 'location_id'), ) - nonracked_devices = Device.objects.filter( - location=instance, - rack__isnull=True, - parent_bay__isnull=True - ).prefetch_related('device_type__manufacturer', 'parent_bay', 'device_role') - return { 'related_models': related_models, - 'nonracked_devices': nonracked_devices.order_by('-pk')[:10], - 'total_nonracked_devices_count': nonracked_devices.count(), } diff --git a/netbox/templates/dcim/inc/nonracked_devices.html b/netbox/templates/dcim/inc/nonracked_devices.html deleted file mode 100644 index d4cd58839..000000000 --- a/netbox/templates/dcim/inc/nonracked_devices.html +++ /dev/null @@ -1,76 +0,0 @@ -{% load helpers %} - -
-
- Non-Racked Devices -
-
- {% if nonracked_devices %} - - - - - - - - {% for device in nonracked_devices %} - - - - - {% if device.parent_bay %} - - - {% else %} - - {% endif %} - - {% endfor %} -
NameRoleTypeParent Device
- {{ device }} - {{ device.device_role }}{{ device.device_type }}{{ device.parent_bay.device|linkify }}{{ device.parent_bay }}
- - {% if total_nonracked_devices_count > nonracked_devices.count %} - {% if object|meta:'verbose_name' == 'site' %} -
- Displaying {{ nonracked_devices.count }} of {{ total_nonracked_devices_count }} devices (View full list) -
- {% elif object|meta:'verbose_name' == 'location' %} -
- Displaying {{ nonracked_devices.count }} of {{ total_nonracked_devices_count }} devices (View full list) -
- {% endif %} - {% endif %} - - {% else %} -
- None -
- {% endif %} -
- - {% if perms.dcim.add_device %} - {% if object|meta:'verbose_name' == 'rack' %} - - {% elif object|meta:'verbose_name' == 'site' %} - - {% elif object|meta:'verbose_name' == 'location' %} - - {% endif %} - {% endif %} -
\ No newline at end of file diff --git a/netbox/templates/dcim/location.html b/netbox/templates/dcim/location.html index 795aeb35f..48700588a 100644 --- a/netbox/templates/dcim/location.html +++ b/netbox/templates/dcim/location.html @@ -65,7 +65,6 @@
{% include 'inc/panels/related_objects.html' %} - {% include 'dcim/inc/nonracked_devices.html' %} {% include 'inc/panels/image_attachments.html' %} {% plugin_right_page object %}
@@ -78,6 +77,27 @@ hx-get="{% url 'dcim:location_list' %}?parent_id={{ object.pk }}" hx-trigger="load" > + {% if perms.dcim.add_location %} + + {% endif %} + +
+
Non-Racked Devices
+
+ {% if perms.dcim.add_device %} + + {% endif %}
{% plugin_full_width_page object %} diff --git a/netbox/templates/dcim/site.html b/netbox/templates/dcim/site.html index 697737ceb..e0f44261f 100644 --- a/netbox/templates/dcim/site.html +++ b/netbox/templates/dcim/site.html @@ -131,56 +131,40 @@
{% include 'inc/panels/related_objects.html' with filter_name='site_id' %} -
-
Locations
-
- {% if locations %} - - - - - - - - {% for location in locations %} - - - - - - - {% endfor %} -
LocationRacksDevices
- {% for i in location.level|as_range %}{% endfor %} - {{ location|linkify }} - - {{ location.rack_count }} - - {{ location.device_count }} - - - - -
- {% else %} - None - {% endif %} -
- {% if perms.dcim.add_location %} - - {% endif %} -
{% include 'inc/panels/image_attachments.html' %} {% plugin_right_page object %}
- {% include 'dcim/inc/nonracked_devices.html' %} +
+
Locations
+
+ {% if perms.dcim.add_location %} + + {% endif %} +
+
+
Non-Racked Devices
+
+ {% if perms.dcim.add_device %} + + {% endif %} +
{% plugin_full_width_page object %}