Fixes: #18305 make contacts mixin available for plugins (#19029)

This commit is contained in:
Renato Almeida de Oliveira
2025-04-01 10:03:25 -03:00
committed by GitHub
parent 1508e3a770
commit 864db469ba
9 changed files with 38 additions and 131 deletions

View File

@@ -1,31 +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.get_contacts().count(),
permission='tenancy.view_contactassignment',
weight=5000
)
def get_children(self, request, parent):
return parent.get_contacts().restrict(request.user, 'view').order_by('priority', 'contact', 'role')
#
# Tenant groups
#
@@ -156,11 +138,6 @@ class TenantBulkDeleteView(generic.BulkDeleteView):
table = tables.TenantTable
@register_model_view(Tenant, 'contacts')
class TenantContactsView(ObjectContactsView):
queryset = Tenant.objects.all()
#
# Contact groups
#