mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Standardize HTMX usage for nested group models
This commit is contained in:
parent
30578bfc97
commit
212356fc02
@ -14,7 +14,7 @@ from django.views.generic import View
|
|||||||
from circuits.models import Circuit, CircuitTermination
|
from circuits.models import Circuit, CircuitTermination
|
||||||
from extras.views import ObjectConfigContextView
|
from extras.views import ObjectConfigContextView
|
||||||
from ipam.models import ASN, IPAddress, Prefix, Service, VLAN, VLANGroup
|
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 netbox.views import generic
|
||||||
from utilities.forms import ConfirmationForm
|
from utilities.forms import ConfirmationForm
|
||||||
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
||||||
@ -210,23 +210,6 @@ class RegionListView(generic.ObjectListView):
|
|||||||
class RegionView(generic.ObjectView):
|
class RegionView(generic.ObjectView):
|
||||||
queryset = Region.objects.all()
|
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')
|
@register_model_view(Region, 'edit')
|
||||||
class RegionEditView(generic.ObjectEditView):
|
class RegionEditView(generic.ObjectEditView):
|
||||||
@ -291,23 +274,6 @@ class SiteGroupListView(generic.ObjectListView):
|
|||||||
class SiteGroupView(generic.ObjectView):
|
class SiteGroupView(generic.ObjectView):
|
||||||
queryset = SiteGroup.objects.all()
|
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')
|
@register_model_view(SiteGroup, 'edit')
|
||||||
class SiteGroupEditView(generic.ObjectEditView):
|
class SiteGroupEditView(generic.ObjectEditView):
|
||||||
@ -477,22 +443,6 @@ class LocationView(generic.ObjectView):
|
|||||||
rack_count = Rack.objects.filter(location__in=location_ids).count()
|
rack_count = Rack.objects.filter(location__in=location_ids).count()
|
||||||
device_count = Device.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(
|
nonracked_devices = Device.objects.filter(
|
||||||
location=instance,
|
location=instance,
|
||||||
rack__isnull=True,
|
rack__isnull=True,
|
||||||
@ -502,7 +452,6 @@ class LocationView(generic.ObjectView):
|
|||||||
return {
|
return {
|
||||||
'rack_count': rack_count,
|
'rack_count': rack_count,
|
||||||
'device_count': device_count,
|
'device_count': device_count,
|
||||||
'child_locations_table': child_locations_table,
|
|
||||||
'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
|
'nonracked_devices': nonracked_devices.order_by('-pk')[:10],
|
||||||
'total_nonracked_devices_count': nonracked_devices.count(),
|
'total_nonracked_devices_count': nonracked_devices.count(),
|
||||||
}
|
}
|
||||||
|
@ -92,11 +92,11 @@
|
|||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">Locations</h5>
|
<h5 class="card-header">Child Locations</h5>
|
||||||
<div class="card-body table-responsive">
|
<div class="card-body htmx-container table-responsive"
|
||||||
{% render_table child_locations_table 'inc/table.html' %}
|
hx-get="{% url 'dcim:location_list' %}?parent_id={{ object.pk }}"
|
||||||
{% include 'inc/paginator.html' with paginator=child_locations_table.paginator page=child_locations_table.page %}
|
hx-trigger="load"
|
||||||
</div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
{% plugin_full_width_page object %}
|
{% plugin_full_width_page object %}
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">Region</h5>
|
||||||
Region
|
|
||||||
</h5>
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
@ -55,12 +53,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">Child Regions</h5>
|
||||||
Child Regions
|
<div class="card-body htmx-container table-responsive"
|
||||||
</h5>
|
hx-get="{% url 'dcim:region_list' %}?parent_id={{ object.pk }}"
|
||||||
<div class="card-body table-responsive">
|
hx-trigger="load"
|
||||||
{% render_table child_regions_table 'inc/table.html' %}
|
></div>
|
||||||
</div>
|
|
||||||
{% if perms.dcim.add_region %}
|
{% if perms.dcim.add_region %}
|
||||||
<div class="card-footer text-end noprint">
|
<div class="card-footer text-end noprint">
|
||||||
<a href="{% url 'dcim:region_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
<a href="{% url 'dcim:region_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">Site Group</h5>
|
||||||
Site Group
|
|
||||||
</h5>
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
@ -42,7 +40,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Sites</th>
|
<th scope="row">Sites</th>
|
||||||
<td>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -55,12 +53,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">Child Groups</h5>
|
||||||
Child Groups
|
<div class="card-body htmx-container table-responsive"
|
||||||
</h5>
|
hx-get="{% url 'dcim:sitegroup_list' %}?parent_id={{ object.pk }}"
|
||||||
<div class="card-body table-responsive">
|
hx-trigger="load"
|
||||||
{% render_table child_groups_table 'inc/table.html' %}
|
></div>
|
||||||
</div>
|
|
||||||
{% if perms.dcim.add_sitegroup %}
|
{% if perms.dcim.add_sitegroup %}
|
||||||
<div class="card-footer text-end noprint">
|
<div class="card-footer text-end noprint">
|
||||||
<a href="{% url 'dcim:sitegroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
<a href="{% url 'dcim:sitegroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
||||||
|
@ -46,12 +46,11 @@
|
|||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
{% include 'inc/panels/custom_fields.html' %}
|
{% include 'inc/panels/custom_fields.html' %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">Child Groups</h5>
|
||||||
Child Groups
|
<div class="card-body htmx-container table-responsive"
|
||||||
</h5>
|
hx-get="{% url 'tenancy:contactgroup_list' %}?parent_id={{ object.pk }}"
|
||||||
<div class="card-body table-responsive">
|
hx-trigger="load"
|
||||||
{% render_table child_groups_table 'inc/table.html' %}
|
></div>
|
||||||
</div>
|
|
||||||
{% if perms.tenancy.add_contactgroup %}
|
{% if perms.tenancy.add_contactgroup %}
|
||||||
<div class="card-footer text-end noprint">
|
<div class="card-footer text-end noprint">
|
||||||
<a href="{% url 'tenancy:contactgroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
<a href="{% url 'tenancy:contactgroup_add' %}?parent={{ object.pk }}" class="btn btn-sm btn-primary">
|
||||||
|
@ -53,6 +53,20 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
{% include 'inc/panels/custom_fields.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 '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 %}
|
{% plugin_right_page object %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,11 +46,25 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% include 'inc/panels/tags.html' %}
|
||||||
{% plugin_left_page object %}
|
{% plugin_left_page object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
{% include 'inc/panels/tags.html' %}
|
|
||||||
{% include 'inc/panels/custom_fields.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 %}
|
{% plugin_right_page object %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -171,23 +171,6 @@ class ContactGroupListView(generic.ObjectListView):
|
|||||||
class ContactGroupView(generic.ObjectView):
|
class ContactGroupView(generic.ObjectView):
|
||||||
queryset = ContactGroup.objects.all()
|
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')
|
@register_model_view(ContactGroup, 'edit')
|
||||||
class ContactGroupEditView(generic.ObjectEditView):
|
class ContactGroupEditView(generic.ObjectEditView):
|
||||||
|
Loading…
Reference in New Issue
Block a user