Standardize HTMX usage for nested group models

This commit is contained in:
jeremystretch 2023-01-16 11:14:46 -05:00
parent 30578bfc97
commit 212356fc02
8 changed files with 53 additions and 100 deletions

View File

@ -14,7 +14,7 @@ from django.views.generic import View
from circuits.models import Circuit, CircuitTermination
from extras.views import ObjectConfigContextView
from ipam.models import ASN, IPAddress, Prefix, Service, VLAN, VLANGroup
from ipam.tables import AssignedIPAddressesTable, InterfaceVLANTable
from ipam.tables import InterfaceVLANTable
from netbox.views import generic
from utilities.forms import ConfirmationForm
from utilities.paginator import EnhancedPaginator, get_paginate_count
@ -210,23 +210,6 @@ class RegionListView(generic.ObjectListView):
class RegionView(generic.ObjectView):
queryset = Region.objects.all()
def get_extra_context(self, request, instance):
child_regions = Region.objects.add_related_count(
Region.objects.all(),
Site,
'region',
'site_count',
cumulative=True
).restrict(request.user, 'view').filter(
parent__in=instance.get_descendants(include_self=True)
)
child_regions_table = tables.RegionTable(child_regions)
child_regions_table.columns.hide('actions')
return {
'child_regions_table': child_regions_table,
}
@register_model_view(Region, 'edit')
class RegionEditView(generic.ObjectEditView):
@ -291,23 +274,6 @@ class SiteGroupListView(generic.ObjectListView):
class SiteGroupView(generic.ObjectView):
queryset = SiteGroup.objects.all()
def get_extra_context(self, request, instance):
child_groups = SiteGroup.objects.add_related_count(
SiteGroup.objects.all(),
Site,
'group',
'site_count',
cumulative=True
).restrict(request.user, 'view').filter(
parent__in=instance.get_descendants(include_self=True)
)
child_groups_table = tables.SiteGroupTable(child_groups)
child_groups_table.columns.hide('actions')
return {
'child_groups_table': child_groups_table,
}
@register_model_view(SiteGroup, 'edit')
class SiteGroupEditView(generic.ObjectEditView):
@ -477,22 +443,6 @@ class LocationView(generic.ObjectView):
rack_count = Rack.objects.filter(location__in=location_ids).count()
device_count = Device.objects.filter(location__in=location_ids).count()
child_locations = Location.objects.add_related_count(
Location.objects.add_related_count(
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, user=request.user)
child_locations_table.configure(request)
nonracked_devices = Device.objects.filter(
location=instance,
rack__isnull=True,
@ -502,7 +452,6 @@ class LocationView(generic.ObjectView):
return {
'rack_count': rack_count,
'device_count': device_count,
'child_locations_table': child_locations_table,
'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
'total_nonracked_devices_count': nonracked_devices.count(),
}

View File

@ -92,11 +92,11 @@
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">Locations</h5>
<div class="card-body table-responsive">
{% render_table child_locations_table 'inc/table.html' %}
{% include 'inc/paginator.html' with paginator=child_locations_table.paginator page=child_locations_table.page %}
</div>
<h5 class="card-header">Child Locations</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:location_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
</div>
{% plugin_full_width_page object %}
</div>

View File

@ -22,9 +22,7 @@
<div class="row mb-3">
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
Region
</h5>
<h5 class="card-header">Region</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
@ -55,12 +53,11 @@
</div>
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
Child Regions
</h5>
<div class="card-body table-responsive">
{% render_table child_regions_table 'inc/table.html' %}
</div>
<h5 class="card-header">Child Regions</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:region_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.dcim.add_region %}
<div class="card-footer text-end noprint">
<a href="{% url 'dcim:region_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">

View File

@ -22,9 +22,7 @@
<div class="row mb-3">
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
Site Group
</h5>
<h5 class="card-header">Site Group</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
@ -42,7 +40,7 @@
<tr>
<th scope="row">Sites</th>
<td>
<a href="{% url 'dcim:site_list' %}?group_id={{ object.pk }}">{{ object.groups.count }}</a>
<a href="{% url 'dcim:site_list' %}?group_id={{ object.pk }}">{{ object.sites.count }}</a>
</td>
</tr>
</table>
@ -55,12 +53,11 @@
</div>
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
Child Groups
</h5>
<div class="card-body table-responsive">
{% render_table child_groups_table 'inc/table.html' %}
</div>
<h5 class="card-header">Child Groups</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'dcim:sitegroup_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.dcim.add_sitegroup %}
<div class="card-footer text-end noprint">
<a href="{% url 'dcim:sitegroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">

View File

@ -46,12 +46,11 @@
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
<div class="card">
<h5 class="card-header">
Child Groups
</h5>
<div class="card-body table-responsive">
{% render_table child_groups_table 'inc/table.html' %}
</div>
<h5 class="card-header">Child Groups</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'tenancy:contactgroup_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.tenancy.add_contactgroup %}
<div class="card-footer text-end noprint">
<a href="{% url 'tenancy:contactgroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">

View File

@ -53,6 +53,20 @@
</div>
<div class="col col-md-6">
{% include 'inc/panels/custom_fields.html' %}
<div class="card">
<h5 class="card-header">Child Groups</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'tenancy:tenantgroup_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.tenancy.add_tenantgroup %}
<div class="card-footer text-end noprint">
<a href="{% url 'tenancy:tenantgroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Tenant Group
</a>
</div>
{% endif %}
</div>
{% plugin_right_page object %}
</div>
</div>

View File

@ -46,11 +46,25 @@
</table>
</div>
</div>
{% include 'inc/panels/tags.html' %}
{% plugin_left_page object %}
</div>
<div class="col col-md-6">
{% include 'inc/panels/tags.html' %}
{% include 'inc/panels/custom_fields.html' %}
<div class="card">
<h5 class="card-header">Child Groups</h5>
<div class="card-body htmx-container table-responsive"
hx-get="{% url 'wireless:wirelesslangroup_list' %}?parent_id={{ object.pk }}"
hx-trigger="load"
></div>
{% if perms.wireless.add_wirelesslangroup %}
<div class="card-footer text-end noprint">
<a href="{% url 'wireless:wirelesslangroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Wireless LAN Group
</a>
</div>
{% endif %}
</div>
{% plugin_right_page object %}
</div>
</div>

View File

@ -171,23 +171,6 @@ class ContactGroupListView(generic.ObjectListView):
class ContactGroupView(generic.ObjectView):
queryset = ContactGroup.objects.all()
def get_extra_context(self, request, instance):
child_groups = ContactGroup.objects.add_related_count(
ContactGroup.objects.all(),
Contact,
'group',
'contact_count',
cumulative=True
).restrict(request.user, 'view').filter(
parent__in=instance.get_descendants(include_self=True)
)
child_groups_table = tables.ContactGroupTable(child_groups)
child_groups_table.columns.hide('actions')
return {
'child_groups_table': child_groups_table,
}
@register_model_view(ContactGroup, 'edit')
class ContactGroupEditView(generic.ObjectEditView):