Add dedicated views for nested group models

This commit is contained in:
Jeremy Stretch
2021-03-26 15:07:29 -04:00
parent b7e44a744d
commit 2820d26a0f
13 changed files with 382 additions and 11 deletions

View File

@@ -45,7 +45,7 @@ class TenantGroup(NestedGroupModel):
ordering = ['name']
def get_absolute_url(self):
return "{}?group={}".format(reverse('tenancy:tenant_list'), self.slug)
return reverse('tenancy:tenantgroup', args=[self.pk])
def to_csv(self):
return (

View File

@@ -35,7 +35,9 @@ class TenantColumn(tables.TemplateColumn):
class TenantGroupTable(BaseTable):
pk = ToggleColumn()
name = MPTTColumn()
name = MPTTColumn(
linkify=True
)
tenant_count = LinkedCountColumn(
viewname='tenancy:tenant_list',
url_params={'group': 'slug'},

View File

@@ -13,6 +13,7 @@ urlpatterns = [
path('tenant-groups/import/', views.TenantGroupBulkImportView.as_view(), name='tenantgroup_import'),
path('tenant-groups/edit/', views.TenantGroupBulkEditView.as_view(), name='tenantgroup_bulk_edit'),
path('tenant-groups/delete/', views.TenantGroupBulkDeleteView.as_view(), name='tenantgroup_bulk_delete'),
path('tenant-groups/<int:pk>/', views.TenantGroupView.as_view(), name='tenantgroup'),
path('tenant-groups/<int:pk>/edit/', views.TenantGroupEditView.as_view(), name='tenantgroup_edit'),
path('tenant-groups/<int:pk>/delete/', views.TenantGroupDeleteView.as_view(), name='tenantgroup_delete'),
path('tenant-groups/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='tenantgroup_changelog', kwargs={'model': TenantGroup}),

View File

@@ -1,9 +1,8 @@
from django.shortcuts import get_object_or_404, render
from circuits.models import Circuit
from dcim.models import Site, Rack, Device, RackReservation
from ipam.models import IPAddress, Prefix, VLAN, VRF
from netbox.views import generic
from utilities.tables import paginate_table
from virtualization.models import VirtualMachine, Cluster
from . import filters, forms, tables
from .models import Tenant, TenantGroup
@@ -24,6 +23,23 @@ class TenantGroupListView(generic.ObjectListView):
table = tables.TenantGroupTable
class TenantGroupView(generic.ObjectView):
queryset = TenantGroup.objects.all()
def get_extra_context(self, request, instance):
tenants = Tenant.objects.restrict(request.user, 'view').filter(
group=instance
)
tenants_table = tables.TenantTable(tenants)
tenants_table.columns.hide('group')
paginate_table(tenants_table, request)
return {
'tenants_table': tenants_table,
}
class TenantGroupEditView(generic.ObjectEditView):
queryset = TenantGroup.objects.all()
model_form = forms.TenantGroupForm