Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12489 Use HTMX for Location and Non-Racked Devices in Site detail view #12491

Merged
merged 17 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netbox/dcim/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ class DeviceFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilter
queryset=Rack.objects.all(),
label=_('Rack (ID)'),
)
has_position = django_filters.BooleanFilter(
jeremystretch marked this conversation as resolved.
Show resolved Hide resolved
label=_('Has a position'),
method='_has_position'
)
cluster_id = django_filters.ModelMultipleChoiceFilter(
queryset=Cluster.objects.all(),
label=_('VM cluster (ID)'),
Expand Down Expand Up @@ -1050,6 +1054,9 @@ def _module_bays(self, queryset, name, value):
def _device_bays(self, queryset, name, value):
return queryset.exclude(devicebays__isnull=value)

def _has_position(self, queryset, name, value):
return queryset.exclude(position__isnull=value)


class VirtualDeviceContextFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
device_id = django_filters.ModelMultipleChoiceFilter(
Expand Down
32 changes: 0 additions & 32 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,32 +398,8 @@ def get_extra_context(self, request, instance):
(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(),
}


Expand Down Expand Up @@ -495,16 +471,8 @@ def get_extra_context(self, request, instance):
(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(),
}


Expand Down
76 changes: 0 additions & 76 deletions netbox/templates/dcim/inc/nonracked_devices.html
arthanson marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

19 changes: 18 additions & 1 deletion netbox/templates/dcim/location.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,30 @@ <h5 class="card-header">
</div>
<div class="col col-md-6">
{% include 'inc/panels/related_objects.html' %}
{% include 'dcim/inc/nonracked_devices.html' %}
{% include 'inc/panels/image_attachments.html' %}
{% plugin_right_page object %}
</div>
</div>
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">
Non-Racked Devices
</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:device_list' %}?location_id={{ object.pk }}&rack_id=null&parent_bay_id=null"
hx-trigger="load"
></div>

{% if perms.dcim.add_device %}
<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 %}
</div>
<div class="card">
<h5 class="card-header">Child Locations</h5>
<div class="card-body htmx-container table-responsive"
Expand Down
20 changes: 19 additions & 1 deletion netbox/templates/dcim/rack.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,25 @@ <h4>Rear</h4>
</div>
<div class="row">
<div class="col col-md-12">
{% plugin_full_width_page object %}
<div class="card">
<h5 class="card-header">
Non-Racked Devices
</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:device_list' %}?rack_id={{ object.pk }}&has_position=False&parent_bay_id=null"
hx-trigger="load"
></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>
{% plugin_full_width_page object %}
</div>
</div>
{% endblock %}
33 changes: 32 additions & 1 deletion netbox/templates/dcim/site.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,38 @@ <h5 class="card-header">Locations</h5>
</div>
<div class="row">
<div class="col col-md-12">
{% include 'dcim/inc/nonracked_devices.html' %}
<div class="card">
<h5 class="card-header">Locations</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:location_list' %}?site_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.dcim.add_location %}
<div class="card-footer text-end noprint">
<a href="{% url 'dcim:location_add' %}?site={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-primary btn-sm">
<i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add a location
</a>
</div>
{% endif %}
</div>
<div class="card">
<h5 class="card-header">
Non-Racked Devices
</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:device_list' %}?site_id={{ object.pk }}&rack_id=null&parent_bay_id=null"
hx-trigger="load"
></div>

{% if perms.dcim.add_device %}
<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>
{% endif %}
</div>
{% plugin_full_width_page object %}
</div>
</div>
Expand Down
Loading