Skip to content

Commit

Permalink
Closes #815: Enable specifying terminations when bulk importing circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 18, 2022
1 parent ae11419 commit 46e3883
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes/version-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v3.4.0 (FUTURE)

### Enhancements

* [#815](https://github.com/netbox-community/netbox/issues/815) - Enable specifying terminations when bulk importing circuits

### Bug Fixes

* [#10946](https://github.com/netbox-community/netbox/issues/10946) - Fix AttributeError exception when viewing a device with a primary IP and no platform assigned
Expand Down
26 changes: 25 additions & 1 deletion netbox/circuits/forms/bulk_import.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from django import forms

from circuits.choices import CircuitStatusChoices
from circuits.models import *
from dcim.models import Site
from django.utils.translation import gettext as _
from netbox.forms import NetBoxModelImportForm
from tenancy.models import Tenant
from utilities.forms import CSVChoiceField, CSVModelChoiceField, SlugField
from utilities.forms import BootstrapMixin, CSVChoiceField, CSVModelChoiceField, SlugField

__all__ = (
'CircuitImportForm',
'CircuitTerminationImportForm',
'CircuitTypeImportForm',
'ProviderImportForm',
'ProviderNetworkImportForm',
Expand Down Expand Up @@ -76,3 +80,23 @@ class Meta:
'cid', 'provider', 'type', 'status', 'tenant', 'install_date', 'termination_date', 'commit_rate',
'description', 'comments', 'tags'
]


class CircuitTerminationImportForm(BootstrapMixin, forms.ModelForm):
site = CSVModelChoiceField(
queryset=Site.objects.all(),
to_field_name='name',
required=False
)
provider_network = CSVModelChoiceField(
queryset=ProviderNetwork.objects.all(),
to_field_name='name',
required=False
)

class Meta:
model = CircuitTermination
fields = [
'circuit', 'term_side', 'site', 'provider_network', 'port_speed', 'upstream_speed', 'xconnect_id',
'pp_info', 'description',
]
7 changes: 7 additions & 0 deletions netbox/circuits/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def setUpTestData(cls):
class CircuitTestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = Circuit

def setUp(self):
super().setUp()

self.add_permissions(
'circuits.add_circuittermination',
)

@classmethod
def setUpTestData(cls):

Expand Down
10 changes: 10 additions & 0 deletions netbox/circuits/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ class CircuitBulkImportView(generic.BulkImportView):
queryset = Circuit.objects.all()
model_form = forms.CircuitImportForm
table = tables.CircuitTable
additional_permissions = [
'circuits.add_circuittermination',
]
related_object_forms = {
'terminations': forms.CircuitTerminationImportForm,
}

def prep_related_object_data(self, parent, data):
data.update({'circuit': parent})
return data


class CircuitBulkEditView(generic.BulkEditView):
Expand Down
2 changes: 1 addition & 1 deletion netbox/netbox/views/generic/bulk_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def post(self, request):
'return_url': self.get_return_url(request),
})

except ValidationError:
except (AbortTransaction, ValidationError):
clear_webhooks.send(sender=self)

except (AbortRequest, PermissionsViolation) as e:
Expand Down

0 comments on commit 46e3883

Please sign in to comment.