From a99d14c13ffa68096073091372bae1ba170e9f5e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 3 Dec 2021 11:00:00 -0500 Subject: [PATCH] Closes #7924: Include child groups on contact group view --- docs/release-notes/version-3.1.md | 1 + netbox/templates/tenancy/contactgroup.html | 21 ++++++++++++++++++--- netbox/tenancy/views.py | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 11e034fca..86058f6e3 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -15,6 +15,7 @@ * [#7812](https://github.com/netbox-community/netbox/issues/7812) - Enable change logging for image attachments * [#7858](https://github.com/netbox-community/netbox/issues/7858) - Standardize the representation of content types across import & export functions * [#7884](https://github.com/netbox-community/netbox/issues/7884) - Add FHRP groups column to interface tables +* [#7924](https://github.com/netbox-community/netbox/issues/7924) - Include child groups on contact group view * [#7925](https://github.com/netbox-community/netbox/issues/7925) - Linkify contact phone and email attributes ### Bug Fixes diff --git a/netbox/templates/tenancy/contactgroup.html b/netbox/templates/tenancy/contactgroup.html index efb86af91..05ec88022 100644 --- a/netbox/templates/tenancy/contactgroup.html +++ b/netbox/templates/tenancy/contactgroup.html @@ -50,15 +50,30 @@
{% include 'inc/panels/custom_fields.html' %} +
+
+ Child Groups +
+
+ {% include 'inc/table.html' with table=child_groups_table %} +
+ {% if perms.tenancy.add_contactgroup %} + + {% endif %} +
{% plugin_right_page object %}
-
- Tenants -
+
+ Contacts +
{% include 'inc/table.html' with table=contacts_table %}
diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index a3e680401..5991d34d9 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -168,6 +168,17 @@ class ContactGroupView(generic.ObjectView): queryset = ContactGroup.objects.all() def get_extra_context(self, request, instance): + child_groups = ContactGroup.objects.add_related_count( + ContactGroup.objects.all(), + Contact, + 'group', + 'contact_count', + cumulative=True + ).restrict(request.user, 'view').filter( + parent__in=instance.get_descendants(include_self=True) + ) + child_groups_table = tables.ContactGroupTable(child_groups) + contacts = Contact.objects.restrict(request.user, 'view').filter( group=instance ) @@ -175,6 +186,7 @@ class ContactGroupView(generic.ObjectView): paginate_table(contacts_table, request) return { + 'child_groups_table': child_groups_table, 'contacts_table': contacts_table, }