Skip to content

Commit

Permalink
Closes #11584: Add a list view for contact assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jan 26, 2023
1 parent 0ad163e commit 9ff14e4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

* [#11584](https://github.com/netbox-community/netbox/issues/11584) - Add a list view for contact assignments
* [#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
* [#11440](https://github.com/netbox-community/netbox/issues/11440) - Add an `enabled` field for device type interfaces

Expand Down
1 change: 1 addition & 0 deletions netbox/netbox/navigation/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
get_model_item('tenancy', 'contact', _('Contacts')),
get_model_item('tenancy', 'contactgroup', _('Contact Groups')),
get_model_item('tenancy', 'contactrole', _('Contact Roles')),
get_model_item('tenancy', 'contactassignment', _('Contact Assignments'), actions=[]),
),
),
),
Expand Down
41 changes: 40 additions & 1 deletion netbox/tenancy/forms/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext as _

from extras.utils import FeatureQuery
from netbox.forms import NetBoxModelFilterSetForm
from tenancy.choices import *
from tenancy.models import *
from tenancy.forms import ContactModelFilterForm
from utilities.forms import DynamicModelMultipleChoiceField, TagFilterField
from utilities.forms.fields import (
ContentTypeMultipleChoiceField, DynamicModelMultipleChoiceField, MultipleChoiceField, TagFilterField,
)

__all__ = (
'ContactAssignmentFilterForm',
'ContactFilterForm',
'ContactGroupFilterForm',
'ContactRoleFilterForm',
Expand Down Expand Up @@ -71,3 +77,36 @@ class ContactFilterForm(NetBoxModelFilterSetForm):
label=_('Group')
)
tag = TagFilterField(model)


class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
model = ContactAssignment
fieldsets = (
(None, ('q', 'filter_id')),
('Assignment', ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
)
content_type_id = ContentTypeMultipleChoiceField(
queryset=ContentType.objects.all(),
limit_choices_to=FeatureQuery('custom_fields'),
required=False,
label=_('Object type')
)
group_id = DynamicModelMultipleChoiceField(
queryset=ContactGroup.objects.all(),
required=False,
label=_('Group')
)
contact_id = DynamicModelMultipleChoiceField(
queryset=Contact.objects.all(),
required=False,
label=_('Contact')
)
role_id = DynamicModelMultipleChoiceField(
queryset=ContactRole.objects.all(),
required=False,
label=_('Role')
)
priority = MultipleChoiceField(
choices=ContactPriorityChoices,
required=False
)
1 change: 1 addition & 0 deletions netbox/tenancy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
path('contacts/<int:pk>/', include(get_model_urls('tenancy', 'contact'))),

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

Expand Down
7 changes: 7 additions & 0 deletions netbox/tenancy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ class ContactBulkDeleteView(generic.BulkDeleteView):
# Contact assignments
#

class ContactAssignmentListView(generic.ObjectListView):
queryset = ContactAssignment.objects.all()
filterset = filtersets.ContactAssignmentFilterSet
filterset_form = forms.ContactAssignmentFilterForm
table = tables.ContactAssignmentTable


@register_model_view(ContactAssignment, 'edit')
class ContactAssignmentEditView(generic.ObjectEditView):
queryset = ContactAssignment.objects.all()
Expand Down

0 comments on commit 9ff14e4

Please sign in to comment.