mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
Closes #6210: Include child locations on location view
This commit is contained in:
parent
88ffc9b145
commit
4e405ce530
@ -7,6 +7,7 @@
|
|||||||
* [#6179](https://github.com/netbox-community/netbox/issues/6179) - Enable natural ordering for virtual machines
|
* [#6179](https://github.com/netbox-community/netbox/issues/6179) - Enable natural ordering for virtual machines
|
||||||
* [#6189](https://github.com/netbox-community/netbox/issues/6189) - Add ability to search for locations by name or description
|
* [#6189](https://github.com/netbox-community/netbox/issues/6189) - Add ability to search for locations by name or description
|
||||||
* [#6190](https://github.com/netbox-community/netbox/issues/6190) - Allow filtering devices with no location assigned
|
* [#6190](https://github.com/netbox-community/netbox/issues/6190) - Allow filtering devices with no location assigned
|
||||||
|
* [#6210](https://github.com/netbox-community/netbox/issues/6210) - Include child locations on location view
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
@ -364,16 +364,30 @@ class LocationView(generic.ObjectView):
|
|||||||
queryset = Location.objects.all()
|
queryset = Location.objects.all()
|
||||||
|
|
||||||
def get_extra_context(self, request, instance):
|
def get_extra_context(self, request, instance):
|
||||||
devices = Device.objects.restrict(request.user, 'view').filter(
|
location_ids = instance.get_descendants(include_self=True).values_list('pk', flat=True)
|
||||||
location=instance
|
rack_count = Rack.objects.filter(location__in=location_ids).count()
|
||||||
)
|
device_count = Device.objects.filter(location__in=location_ids).count()
|
||||||
|
|
||||||
devices_table = tables.DeviceTable(devices)
|
child_locations = Location.objects.add_related_count(
|
||||||
devices_table.columns.hide('location')
|
Location.objects.add_related_count(
|
||||||
paginate_table(devices_table, request)
|
Location.objects.all(),
|
||||||
|
Device,
|
||||||
|
'location',
|
||||||
|
'device_count',
|
||||||
|
cumulative=True
|
||||||
|
),
|
||||||
|
Rack,
|
||||||
|
'location',
|
||||||
|
'rack_count',
|
||||||
|
cumulative=True
|
||||||
|
).filter(pk__in=location_ids).exclude(pk=instance.pk)
|
||||||
|
child_locations_table = tables.LocationTable(child_locations)
|
||||||
|
paginate_table(child_locations_table, request)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'devices_table': devices_table,
|
'rack_count': rack_count,
|
||||||
|
'device_count': device_count,
|
||||||
|
'child_locations_table': child_locations_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Racks</td>
|
<td>Racks</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'dcim:rack_list' %}?location_id={{ object.pk }}">{{ object.racks.count }}</a>
|
<a href="{% url 'dcim:rack_list' %}?location_id={{ object.pk }}">{{ rack_count }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Devices</td>
|
<td>Devices</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'dcim:device_list' %}?location_id={{ object.pk }}">{{ devices_table.rows|length }}</a>
|
<a href="{% url 'dcim:device_list' %}?location_id={{ object.pk }}">{{ device_count }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -79,18 +79,18 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<strong>Devices</strong>
|
<strong>Locations</strong>
|
||||||
</div>
|
</div>
|
||||||
{% include 'inc/table.html' with table=devices_table %}
|
{% include 'inc/table.html' with table=child_locations_table %}
|
||||||
{% if perms.dcim.add_device %}
|
{% if perms.dcim.add_location %}
|
||||||
<div class="panel-footer text-right noprint">
|
<div class="panel-footer text-right noprint">
|
||||||
<a href="{% url 'dcim:device_add' %}?location={{ object.pk }}" class="btn btn-xs btn-primary">
|
<a href="{% url 'dcim:location_add' %}?site={{ object.site.pk }}&parent={{ object.pk }}" class="btn btn-xs btn-primary">
|
||||||
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add device
|
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add location
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'inc/paginator.html' with paginator=devices_table.paginator page=devices_table.page %}
|
{% include 'inc/paginator.html' with paginator=child_locations_table.paginator page=child_locations_table.page %}
|
||||||
{% plugin_full_width_page object %}
|
{% plugin_full_width_page object %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user