1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add dedicated views for organizational models

This commit is contained in:
Jeremy Stretch
2021-03-26 14:44:43 -04:00
parent bb00f2ff46
commit b7e44a744d
31 changed files with 949 additions and 69 deletions

View File

@ -11,6 +11,7 @@ from ipam.models import IPAddress, Service
from ipam.tables import InterfaceIPAddressTable, InterfaceVLANTable
from netbox.views import generic
from secrets.models import Secret
from utilities.tables import paginate_table
from utilities.utils import count_related
from . import filters, forms, tables
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
@ -27,6 +28,23 @@ class ClusterTypeListView(generic.ObjectListView):
table = tables.ClusterTypeTable
class ClusterTypeView(generic.ObjectView):
queryset = ClusterType.objects.all()
def get_extra_context(self, request, instance):
clusters = Cluster.objects.restrict(request.user, 'view').filter(
type=instance
)
clusters_table = tables.ClusterTable(clusters)
clusters_table.columns.hide('type')
paginate_table(clusters_table, request)
return {
'clusters_table': clusters_table,
}
class ClusterTypeEditView(generic.ObjectEditView):
queryset = ClusterType.objects.all()
model_form = forms.ClusterTypeForm
@ -69,6 +87,23 @@ class ClusterGroupListView(generic.ObjectListView):
table = tables.ClusterGroupTable
class ClusterGroupView(generic.ObjectView):
queryset = ClusterGroup.objects.all()
def get_extra_context(self, request, instance):
clusters = Cluster.objects.restrict(request.user, 'view').filter(
group=instance
)
clusters_table = tables.ClusterTable(clusters)
clusters_table.columns.hide('group')
paginate_table(clusters_table, request)
return {
'clusters_table': clusters_table,
}
class ClusterGroupEditView(generic.ObjectEditView):
queryset = ClusterGroup.objects.all()
model_form = forms.ClusterGroupForm