Skip to content

Commit 9ff14e4

Browse files
committed
Closes #11584: Add a list view for contact assignments
1 parent 0ad163e commit 9ff14e4

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

docs/release-notes/version-3.5.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Enhancements
66

7+
* [#11584](https://github.com/netbox-community/netbox/issues/11584) - Add a list view for contact assignments
78
* [#11254](https://github.com/netbox-community/netbox/issues/11254) - Introduce the `X-Request-ID` HTTP header to annotate the unique ID of each request for change logging
89
* [#11440](https://github.com/netbox-community/netbox/issues/11440) - Add an `enabled` field for device type interfaces
910

netbox/netbox/navigation/menu.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
get_model_item('tenancy', 'contact', _('Contacts')),
4747
get_model_item('tenancy', 'contactgroup', _('Contact Groups')),
4848
get_model_item('tenancy', 'contactrole', _('Contact Roles')),
49+
get_model_item('tenancy', 'contactassignment', _('Contact Assignments'), actions=[]),
4950
),
5051
),
5152
),

netbox/tenancy/forms/filtersets.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
from django.contrib.contenttypes.models import ContentType
12
from django.utils.translation import gettext as _
23

4+
from extras.utils import FeatureQuery
35
from netbox.forms import NetBoxModelFilterSetForm
6+
from tenancy.choices import *
47
from tenancy.models import *
58
from tenancy.forms import ContactModelFilterForm
6-
from utilities.forms import DynamicModelMultipleChoiceField, TagFilterField
9+
from utilities.forms.fields import (
10+
ContentTypeMultipleChoiceField, DynamicModelMultipleChoiceField, MultipleChoiceField, TagFilterField,
11+
)
712

813
__all__ = (
14+
'ContactAssignmentFilterForm',
915
'ContactFilterForm',
1016
'ContactGroupFilterForm',
1117
'ContactRoleFilterForm',
@@ -71,3 +77,36 @@ class ContactFilterForm(NetBoxModelFilterSetForm):
7177
label=_('Group')
7278
)
7379
tag = TagFilterField(model)
80+
81+
82+
class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
83+
model = ContactAssignment
84+
fieldsets = (
85+
(None, ('q', 'filter_id')),
86+
('Assignment', ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
87+
)
88+
content_type_id = ContentTypeMultipleChoiceField(
89+
queryset=ContentType.objects.all(),
90+
limit_choices_to=FeatureQuery('custom_fields'),
91+
required=False,
92+
label=_('Object type')
93+
)
94+
group_id = DynamicModelMultipleChoiceField(
95+
queryset=ContactGroup.objects.all(),
96+
required=False,
97+
label=_('Group')
98+
)
99+
contact_id = DynamicModelMultipleChoiceField(
100+
queryset=Contact.objects.all(),
101+
required=False,
102+
label=_('Contact')
103+
)
104+
role_id = DynamicModelMultipleChoiceField(
105+
queryset=ContactRole.objects.all(),
106+
required=False,
107+
label=_('Role')
108+
)
109+
priority = MultipleChoiceField(
110+
choices=ContactPriorityChoices,
111+
required=False
112+
)

netbox/tenancy/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
path('contacts/<int:pk>/', include(get_model_urls('tenancy', 'contact'))),
4848

4949
# Contact assignments
50+
path('contact-assignments/', views.ContactAssignmentListView.as_view(), name='contactassignment_list'),
5051
path('contact-assignments/add/', views.ContactAssignmentEditView.as_view(), name='contactassignment_add'),
5152
path('contact-assignments/<int:pk>/', include(get_model_urls('tenancy', 'contactassignment'))),
5253

netbox/tenancy/views.py

+7
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ class ContactBulkDeleteView(generic.BulkDeleteView):
366366
# Contact assignments
367367
#
368368

369+
class ContactAssignmentListView(generic.ObjectListView):
370+
queryset = ContactAssignment.objects.all()
371+
filterset = filtersets.ContactAssignmentFilterSet
372+
filterset_form = forms.ContactAssignmentFilterForm
373+
table = tables.ContactAssignmentTable
374+
375+
369376
@register_model_view(ContactAssignment, 'edit')
370377
class ContactAssignmentEditView(generic.ObjectEditView):
371378
queryset = ContactAssignment.objects.all()

0 commit comments

Comments
 (0)