mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Adds contact tabs (#12460)
* adds contact tabs #11599 * fixed lint issues * changes as per review * changes as per review * replaces generic object template with base template
This commit is contained in:
committed by
GitHub
parent
e71a98499f
commit
4eb5e90ccc
@@ -7,17 +7,40 @@ from dcim.models import Cable, Device, Location, Rack, RackReservation, Site, Vi
|
||||
from ipam.models import Aggregate, ASN, IPAddress, IPRange, L2VPN, Prefix, VLAN, VRF
|
||||
from netbox.views import generic
|
||||
from utilities.utils import count_related
|
||||
from utilities.views import register_model_view
|
||||
from utilities.views import register_model_view, ViewTab
|
||||
from virtualization.models import VirtualMachine, Cluster
|
||||
from wireless.models import WirelessLAN, WirelessLink
|
||||
from . import filtersets, forms, tables
|
||||
from .models import *
|
||||
|
||||
|
||||
class ObjectContactsView(generic.ObjectChildrenView):
|
||||
child_model = Contact
|
||||
table = tables.ContactTable
|
||||
filterset = filtersets.ContactFilterSet
|
||||
template_name = 'tenancy/object_contacts.html'
|
||||
tab = ViewTab(
|
||||
label=_('Contacts'),
|
||||
badge=lambda obj: obj.contacts.count(),
|
||||
permission='tenancy.view_contact',
|
||||
weight=5000
|
||||
)
|
||||
|
||||
def get_children(self, request, parent):
|
||||
return Contact.objects.annotate(
|
||||
assignment_count=count_related(ContactAssignment, 'contact')
|
||||
).restrict(request.user, 'view').filter(assignments__object_id=parent.pk)
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
return {
|
||||
'base_template': f'{instance._meta.app_label}/{instance._meta.model_name}.html',
|
||||
}
|
||||
|
||||
#
|
||||
# Tenant groups
|
||||
#
|
||||
|
||||
|
||||
class TenantGroupListView(generic.ObjectListView):
|
||||
queryset = TenantGroup.objects.add_related_count(
|
||||
TenantGroup.objects.all(),
|
||||
@@ -165,6 +188,11 @@ class TenantBulkDeleteView(generic.BulkDeleteView):
|
||||
table = tables.TenantTable
|
||||
|
||||
|
||||
@register_model_view(Tenant, 'contacts')
|
||||
class TenantContactsView(ObjectContactsView):
|
||||
queryset = Tenant.objects.all()
|
||||
|
||||
|
||||
#
|
||||
# Contact groups
|
||||
#
|
||||
@@ -342,11 +370,11 @@ class ContactBulkDeleteView(generic.BulkDeleteView):
|
||||
filterset = filtersets.ContactFilterSet
|
||||
table = tables.ContactTable
|
||||
|
||||
|
||||
#
|
||||
# Contact assignments
|
||||
#
|
||||
|
||||
|
||||
class ContactAssignmentListView(generic.ObjectListView):
|
||||
queryset = ContactAssignment.objects.all()
|
||||
filterset = filtersets.ContactAssignmentFilterSet
|
||||
|
Reference in New Issue
Block a user