Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbox/netbox/navigation/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +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=[]),
get_model_item('tenancy', 'contactassignment', _('Contact Assignments'), actions=['import']),
),
),
),
Expand Down
28 changes: 27 additions & 1 deletion netbox/tenancy/forms/bulk_import.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import gettext as _
from netbox.forms import NetBoxModelImportForm
from tenancy.models import *
from utilities.forms.fields import CSVModelChoiceField, SlugField
from utilities.forms.fields import CSVContentTypeField, CSVModelChoiceField, SlugField

__all__ = (
'ContactAssignmentImportForm',
'ContactImportForm',
'ContactGroupImportForm',
'ContactRoleImportForm',
Expand Down Expand Up @@ -81,3 +83,27 @@ class ContactImportForm(NetBoxModelImportForm):
class Meta:
model = Contact
fields = ('name', 'title', 'phone', 'email', 'address', 'link', 'group', 'description', 'comments', 'tags')


class ContactAssignmentImportForm(NetBoxModelImportForm):
content_type = CSVContentTypeField(
queryset=ContentType.objects.all(),
help_text=_("One or more assigned object types")
)
contact = CSVModelChoiceField(
queryset=Contact.objects.all(),
to_field_name='name',
help_text=_('Assigned contact')
)
role = CSVModelChoiceField(
queryset=ContactRole.objects.all(),
to_field_name='name',
help_text=_('Assigned role')
)

# Remove the tags field added by NetBoxModelImportForm (unsupported by ContactAssignment)
tags = None

class Meta:
model = ContactAssignment
fields = ('content_type', 'object_id', 'contact', 'priority', 'role')
1 change: 1 addition & 0 deletions netbox/tenancy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# 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/import/', views.ContactAssignmentBulkImportView.as_view(), name='contactassignment_import'),
path('contact-assignments/edit/', views.ContactAssignmentBulkEditView.as_view(), name='contactassignment_bulk_edit'),
path('contact-assignments/delete/', views.ContactAssignmentBulkDeleteView.as_view(), name='contactassignment_bulk_delete'),
path('contact-assignments/<int:pk>/', include(get_model_urls('tenancy', 'contactassignment'))),
Expand Down
5 changes: 5 additions & 0 deletions netbox/tenancy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ class ContactAssignmentBulkEditView(generic.BulkEditView):
form = forms.ContactAssignmentBulkEditForm


class ContactAssignmentBulkImportView(generic.BulkImportView):
queryset = ContactAssignment.objects.all()
model_form = forms.ContactAssignmentImportForm


class ContactAssignmentBulkDeleteView(generic.BulkDeleteView):
queryset = ContactAssignment.objects.all()
filterset = filtersets.ContactAssignmentFilterSet
Expand Down