Fixes #12715: Use contact assignments table to display the contacts assigned to an object

This commit is contained in:
jeremystretch 2023-05-30 14:51:16 -04:00
parent 18c863e393
commit b3bd03a1e9
2 changed files with 18 additions and 10 deletions

View File

@ -12,9 +12,10 @@
* [#11539](https://github.com/netbox-community/netbox/issues/11539) - Fix exception when applying "empty" filter lookup with invalid value
* [#11934](https://github.com/netbox-community/netbox/issues/11934) - Prevent reassignment of an IP address designated as primary for its parent object
* [#12370](https://github.com/netbox-community/netbox/issues/12370) - Fix extraneous contacts listed in object contact assignments view
* [#12730](https://github.com/netbox-community/netbox/issues/12730) - Fix extraneous contacts listed in object contact assignments view
* [#12627](https://github.com/netbox-community/netbox/issues/12627) - Restore hover preview for embedded image attachment tables
* [#12694](https://github.com/netbox-community/netbox/issues/12694) - Strip leading & trailing whitespace from custom link URL & text
* [#12715](https://github.com/netbox-community/netbox/issues/12715) - Use contact assignments table to display the contacts assigned to an object
* [#12745](https://github.com/netbox-community/netbox/issues/12745) - Escape display text in API-backed selection widgets
---

View File

@ -15,25 +15,32 @@ from .models import *
class ObjectContactsView(generic.ObjectChildrenView):
child_model = Contact
table = tables.ContactTable
filterset = filtersets.ContactFilterSet
child_model = ContactAssignment
table = tables.ContactAssignmentTable
filterset = filtersets.ContactAssignmentFilterSet
template_name = 'tenancy/object_contacts.html'
tab = ViewTab(
label=_('Contacts'),
badge=lambda obj: obj.contacts.count(),
permission='tenancy.view_contact',
permission='tenancy.view_contactassignment',
weight=5000
)
def get_children(self, request, parent):
return Contact.objects.annotate(
assignment_count=count_related(ContactAssignment, 'contact')
).restrict(request.user, 'view').filter(
assignments__content_type=ContentType.objects.get_for_model(parent),
assignments__object_id=parent.pk
return ContactAssignment.objects.restrict(request.user, 'view').filter(
content_type=ContentType.objects.get_for_model(parent),
object_id=parent.pk
)
def get_table(self, *args, **kwargs):
table = super().get_table(*args, **kwargs)
# Hide object columns
table.columns.hide('content_type')
table.columns.hide('object')
return table
def get_extra_context(self, request, instance):
return {
'base_template': f'{instance._meta.app_label}/{instance._meta.model_name}.html',