mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Add generic.ObjectContactsView register, and remove Models ContactsView
This commit is contained in:
parent
eb4794ded7
commit
db27160e42
@ -6,7 +6,6 @@ from django.utils.translation import gettext_lazy as _
|
||||
from dcim.views import PathTraceView
|
||||
from ipam.models import ASN
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.forms import ConfirmationForm
|
||||
from utilities.query import count_related
|
||||
from utilities.views import GetRelatedModelsMixin, register_model_view
|
||||
@ -77,11 +76,6 @@ class ProviderBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.ProviderTable
|
||||
|
||||
|
||||
@register_model_view(Provider, 'contacts')
|
||||
class ProviderContactsView(ObjectContactsView):
|
||||
queryset = Provider.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# ProviderAccounts
|
||||
#
|
||||
@ -144,11 +138,6 @@ class ProviderAccountBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.ProviderAccountTable
|
||||
|
||||
|
||||
@register_model_view(ProviderAccount, 'contacts')
|
||||
class ProviderAccountContactsView(ObjectContactsView):
|
||||
queryset = ProviderAccount.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Provider networks
|
||||
#
|
||||
@ -416,11 +405,6 @@ class CircuitSwapTerminations(generic.ObjectEditView):
|
||||
})
|
||||
|
||||
|
||||
@register_model_view(Circuit, 'contacts')
|
||||
class CircuitContactsView(ObjectContactsView):
|
||||
queryset = Circuit.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Circuit terminations
|
||||
#
|
||||
|
@ -17,7 +17,6 @@ from ipam.models import ASN, IPAddress, Prefix, VLANGroup
|
||||
from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
|
||||
from netbox.constants import DEFAULT_ACTION_PERMISSIONS
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.forms import ConfirmationForm
|
||||
from utilities.paginator import EnhancedPaginator, get_paginate_count
|
||||
from utilities.permissions import get_permission_for_model
|
||||
@ -302,11 +301,6 @@ class RegionBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.RegionTable
|
||||
|
||||
|
||||
@register_model_view(Region, 'contacts')
|
||||
class RegionContactsView(ObjectContactsView):
|
||||
queryset = Region.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Site groups
|
||||
#
|
||||
@ -410,11 +404,6 @@ class SiteGroupBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.SiteGroupTable
|
||||
|
||||
|
||||
@register_model_view(SiteGroup, 'contacts')
|
||||
class SiteGroupContactsView(ObjectContactsView):
|
||||
queryset = SiteGroup.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Sites
|
||||
#
|
||||
@ -493,11 +482,6 @@ class SiteBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.SiteTable
|
||||
|
||||
|
||||
@register_model_view(Site, 'contacts')
|
||||
class SiteContactsView(ObjectContactsView):
|
||||
queryset = Site.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Locations
|
||||
#
|
||||
@ -604,11 +588,6 @@ class LocationBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.LocationTable
|
||||
|
||||
|
||||
@register_model_view(Location, 'contacts')
|
||||
class LocationContactsView(ObjectContactsView):
|
||||
queryset = Location.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Rack roles
|
||||
#
|
||||
@ -896,7 +875,7 @@ class RackBulkDeleteView(generic.BulkDeleteView):
|
||||
|
||||
|
||||
@register_model_view(Rack, 'contacts')
|
||||
class RackContactsView(ObjectContactsView):
|
||||
class RackContactsView():
|
||||
queryset = Rack.objects.all()
|
||||
|
||||
|
||||
@ -1038,11 +1017,6 @@ class ManufacturerBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.ManufacturerTable
|
||||
|
||||
|
||||
@register_model_view(Manufacturer, 'contacts')
|
||||
class ManufacturerContactsView(ObjectContactsView):
|
||||
queryset = Manufacturer.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Device types
|
||||
#
|
||||
@ -2329,11 +2303,6 @@ class DeviceBulkRenameView(generic.BulkRenameView):
|
||||
table = tables.DeviceTable
|
||||
|
||||
|
||||
@register_model_view(Device, 'contacts')
|
||||
class DeviceContactsView(ObjectContactsView):
|
||||
queryset = Device.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Modules
|
||||
#
|
||||
@ -3893,11 +3862,6 @@ class PowerPanelBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.PowerPanelTable
|
||||
|
||||
|
||||
@register_model_view(PowerPanel, 'contacts')
|
||||
class PowerPanelContactsView(ObjectContactsView):
|
||||
queryset = PowerPanel.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Power feeds
|
||||
#
|
||||
|
@ -11,7 +11,6 @@ from dcim.forms import InterfaceFilterForm
|
||||
from dcim.models import Interface, Site
|
||||
from ipam.tables import VLANTranslationRuleTable
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.query import count_related
|
||||
from utilities.tables import get_table_ordering
|
||||
from utilities.views import GetRelatedModelsMixin, ViewTab, register_model_view
|
||||
@ -434,11 +433,6 @@ class AggregateBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.AggregateTable
|
||||
|
||||
|
||||
@register_model_view(Aggregate, 'contacts')
|
||||
class AggregateContactsView(ObjectContactsView):
|
||||
queryset = Aggregate.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Prefix/VLAN roles
|
||||
#
|
||||
@ -684,11 +678,6 @@ class PrefixBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.PrefixTable
|
||||
|
||||
|
||||
@register_model_view(Prefix, 'contacts')
|
||||
class PrefixContactsView(ObjectContactsView):
|
||||
queryset = Prefix.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# IP Ranges
|
||||
#
|
||||
@ -778,11 +767,6 @@ class IPRangeBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.IPRangeTable
|
||||
|
||||
|
||||
@register_model_view(IPRange, 'contacts')
|
||||
class IPRangeContactsView(ObjectContactsView):
|
||||
queryset = IPRange.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# IP addresses
|
||||
#
|
||||
@ -965,11 +949,6 @@ class IPAddressRelatedIPsView(generic.ObjectChildrenView):
|
||||
return parent.get_related_ips().restrict(request.user, 'view')
|
||||
|
||||
|
||||
@register_model_view(IPAddress, 'contacts')
|
||||
class IPAddressContactsView(ObjectContactsView):
|
||||
queryset = IPAddress.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# VLAN groups
|
||||
#
|
||||
@ -1477,8 +1456,3 @@ class ServiceBulkDeleteView(generic.BulkDeleteView):
|
||||
queryset = Service.objects.prefetch_related('device', 'virtual_machine')
|
||||
filterset = filtersets.ServiceFilterSet
|
||||
table = tables.ServiceTable
|
||||
|
||||
|
||||
@register_model_view(Service, 'contacts')
|
||||
class ServiceContactsView(ObjectContactsView):
|
||||
queryset = Service.objects.all()
|
||||
|
@ -637,6 +637,10 @@ def register_models(*models):
|
||||
)
|
||||
|
||||
# Register applicable feature views for the model
|
||||
if issubclass(model, ContactsMixin):
|
||||
register_model_view(model, 'contacts', kwargs={'model': model})(
|
||||
'netbox.views.generic.ObjectContactsView'
|
||||
)
|
||||
if issubclass(model, JournalingMixin):
|
||||
register_model_view(model, 'journal', kwargs={'model': model})(
|
||||
'netbox.views.generic.ObjectJournalView'
|
||||
|
@ -1,43 +1,13 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from netbox.views import generic
|
||||
from utilities.query import count_related
|
||||
from utilities.views import GetRelatedModelsMixin, ViewTab, register_model_view
|
||||
from utilities.views import GetRelatedModelsMixin, register_model_view
|
||||
from . import filtersets, forms, tables
|
||||
from .models import *
|
||||
|
||||
|
||||
class ObjectContactsView(generic.ObjectChildrenView):
|
||||
child_model = ContactAssignment
|
||||
table = tables.ContactAssignmentTable
|
||||
filterset = filtersets.ContactAssignmentFilterSet
|
||||
filterset_form = forms.ContactAssignmentFilterForm
|
||||
template_name = 'tenancy/object_contacts.html'
|
||||
tab = ViewTab(
|
||||
label=_('Contacts'),
|
||||
badge=lambda obj: obj.contacts.count(),
|
||||
permission='tenancy.view_contactassignment',
|
||||
weight=5000
|
||||
)
|
||||
|
||||
def get_children(self, request, parent):
|
||||
return ContactAssignment.objects.restrict(request.user, 'view').filter(
|
||||
object_type=ContentType.objects.get_for_model(parent),
|
||||
object_id=parent.pk
|
||||
).order_by('priority', 'contact', 'role')
|
||||
|
||||
def get_table(self, *args, **kwargs):
|
||||
table = super().get_table(*args, **kwargs)
|
||||
|
||||
# Hide object columns
|
||||
table.columns.hide('object_type')
|
||||
table.columns.hide('object')
|
||||
|
||||
return table
|
||||
|
||||
|
||||
#
|
||||
# Tenant groups
|
||||
#
|
||||
@ -168,11 +138,6 @@ class TenantBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.TenantTable
|
||||
|
||||
|
||||
@register_model_view(Tenant, 'contacts')
|
||||
class TenantContactsView(ObjectContactsView):
|
||||
queryset = Tenant.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Contact groups
|
||||
#
|
||||
|
@ -14,7 +14,6 @@ from ipam.models import IPAddress
|
||||
from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
|
||||
from netbox.constants import DEFAULT_ACTION_PERMISSIONS
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.query import count_related
|
||||
from utilities.query_functions import CollateAsChar
|
||||
from utilities.views import GetRelatedModelsMixin, ViewTab, register_model_view
|
||||
@ -146,11 +145,6 @@ class ClusterGroupBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.ClusterGroupTable
|
||||
|
||||
|
||||
@register_model_view(ClusterGroup, 'contacts')
|
||||
class ClusterGroupContactsView(ObjectContactsView):
|
||||
queryset = ClusterGroup.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Clusters
|
||||
#
|
||||
@ -342,11 +336,6 @@ class ClusterRemoveDevicesView(generic.ObjectEditView):
|
||||
})
|
||||
|
||||
|
||||
@register_model_view(Cluster, 'contacts')
|
||||
class ClusterContactsView(ObjectContactsView):
|
||||
queryset = Cluster.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Virtual machines
|
||||
#
|
||||
@ -467,11 +456,6 @@ class VirtualMachineBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.VirtualMachineTable
|
||||
|
||||
|
||||
@register_model_view(VirtualMachine, 'contacts')
|
||||
class VirtualMachineContactsView(ObjectContactsView):
|
||||
queryset = VirtualMachine.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# VM interfaces
|
||||
#
|
||||
|
@ -1,6 +1,5 @@
|
||||
from ipam.tables import RouteTargetTable
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.query import count_related
|
||||
from utilities.views import GetRelatedModelsMixin, register_model_view
|
||||
from . import filtersets, forms, tables
|
||||
@ -68,11 +67,6 @@ class TunnelGroupBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.TunnelGroupTable
|
||||
|
||||
|
||||
@register_model_view(TunnelGroup, 'contacts')
|
||||
class TunnelGroupContactsView(ObjectContactsView):
|
||||
queryset = TunnelGroup.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Tunnels
|
||||
#
|
||||
@ -137,11 +131,6 @@ class TunnelBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.TunnelTable
|
||||
|
||||
|
||||
@register_model_view(Tunnel, 'contacts')
|
||||
class TunnelContactsView(ObjectContactsView):
|
||||
queryset = Tunnel.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Tunnel terminations
|
||||
#
|
||||
@ -507,11 +496,6 @@ class L2VPNBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.L2VPNTable
|
||||
|
||||
|
||||
@register_model_view(L2VPN, 'contacts')
|
||||
class L2VPNContactsView(ObjectContactsView):
|
||||
queryset = L2VPN.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# L2VPN terminations
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user