Skip to content

Commit

Permalink
Fixes #8792: Fix creation of circuit terminations via UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Mar 3, 2022
1 parent 25dc9cc commit a740203
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 38 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Where it is desired to limit the range of available VLANs within a group, users
* [#8763](https://github.com/netbox-community/netbox/issues/8763) - Fix inventory item component assignment
* [#8764](https://github.com/netbox-community/netbox/issues/8764) - Correct view name resolution for dynamic form fields
* [#8791](https://github.com/netbox-community/netbox/issues/8791) - Fix display of form validation failures during device component creation
* [#8792](https://github.com/netbox-community/netbox/issues/8792) - Fix creation of circuit terminations via UI

### Other Changes

Expand Down
24 changes: 16 additions & 8 deletions netbox/circuits/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ class Meta:


class CircuitTerminationForm(BootstrapMixin, forms.ModelForm):
provider = DynamicModelChoiceField(
queryset=Provider.objects.all(),
required=False,
initial_params={
'circuits': '$circuit'
}
)
circuit = DynamicModelChoiceField(
queryset=Circuit.objects.all(),
query_params={
'provider_id': '$provider',
},
)
region = DynamicModelChoiceField(
queryset=Region.objects.all(),
required=False,
Expand Down Expand Up @@ -155,21 +168,16 @@ class CircuitTerminationForm(BootstrapMixin, forms.ModelForm):
class Meta:
model = CircuitTermination
fields = [
'term_side', 'region', 'site_group', 'site', 'provider_network', 'mark_connected', 'port_speed',
'upstream_speed', 'xconnect_id', 'pp_info', 'description',
'provider', 'circuit', 'term_side', 'region', 'site_group', 'site', 'provider_network', 'mark_connected',
'port_speed', 'upstream_speed', 'xconnect_id', 'pp_info', 'description',
]
help_texts = {
'port_speed': "Physical circuit speed",
'xconnect_id': "ID of the local cross-connect",
'pp_info': "Patch panel ID and port number(s)"
}
widgets = {
'term_side': forms.HiddenInput(),
'term_side': StaticSelect(),
'port_speed': SelectSpeedWidget(),
'upstream_speed': SelectSpeedWidget(),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields['provider_network'].widget.add_query_param('provider_id', self.instance.circuit.provider_id)
1 change: 1 addition & 0 deletions netbox/circuits/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def setUpTestData(cls):
CircuitTermination.objects.bulk_create(circuit_terminations)

cls.form_data = {
'circuit': circuits[2].pk,
'term_side': 'A',
'site': sites[2].pk,
'description': 'New description',
Expand Down
2 changes: 1 addition & 1 deletion netbox/circuits/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
path('circuits/<int:pk>/terminations/swap/', views.CircuitSwapTerminations.as_view(), name='circuit_terminations_swap'),

# Circuit terminations
path('circuits/<int:circuit>/terminations/add/', views.CircuitTerminationEditView.as_view(), name='circuittermination_add'),
path('circuit-terminations/add/', views.CircuitTerminationEditView.as_view(), name='circuittermination_add'),
path('circuit-terminations/<int:pk>/edit/', views.CircuitTerminationEditView.as_view(), name='circuittermination_edit'),
path('circuit-terminations/<int:pk>/delete/', views.CircuitTerminationDeleteView.as_view(), name='circuittermination_delete'),
path('circuit-terminations/<int:termination_a_id>/connect/<str:termination_b_type>/', CableCreateView.as_view(), name='circuittermination_connect', kwargs={'termination_a_type': CircuitTermination}),
Expand Down
8 changes: 0 additions & 8 deletions netbox/circuits/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,6 @@ class CircuitTerminationEditView(generic.ObjectEditView):
model_form = forms.CircuitTerminationForm
template_name = 'circuits/circuittermination_edit.html'

def alter_object(self, obj, request, url_args, url_kwargs):
if 'circuit' in url_kwargs:
obj.circuit = get_object_or_404(Circuit, pk=url_kwargs['circuit'])
return obj

def get_return_url(self, request, obj):
return obj.circuit.get_absolute_url()


class CircuitTerminationDeleteView(generic.ObjectDeleteView):
queryset = CircuitTermination.objects.all()
23 changes: 3 additions & 20 deletions netbox/templates/circuits/circuittermination_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,14 @@
{% load static %}
{% load form_helpers %}

{% block title %}{{ object.circuit.provider }} {{ object.circuit }} - Side {{ form.term_side.value }}{% endblock %}

{% block form %}
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">Circuit Termination</h5>
</div>
<div class="row mb-3">
<label class="col-sm-3 col-form-label text-lg-end">Provider</label>
<div class="col">
<input class="form-control" value="{{ object.circuit.provider }}" disabled />
</div>
</div>
<div class="row mb-3">
<label class="col-sm-3 col-form-label text-lg-end">Circuit</label>
<div class="col">
<input class="form-control" value="{{ object.circuit.cid }}" disabled />
</div>
</div>
<div class="row mb-3">
<label class="col-sm-3 col-form-label text-lg-end">Termination</label>
<div class="col">
<input class="form-control" value="{{ form.term_side.value }}" disabled />
</div>
</div>
{% render_field form.provider %}
{% render_field form.circuit %}
{% render_field form.term_side %}
{% render_field form.mark_connected %}
{% with providernetwork_tab_active=form.initial.provider_network %}
<div class="row mb-2">
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/circuits/inc/circuit_termination.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<strong class="d-block d-md-inline mb-3 mb-md-0">Termination - {{ side }} Side</strong>
<div class="float-md-end">
{% if not termination and perms.circuits.add_circuittermination %}
<a href="{% url 'circuits:circuittermination_add' circuit=object.pk %}?term_side={{ side }}" class="btn btn-sm btn-success lh-1">
<a href="{% url 'circuits:circuittermination_add' %}?circuit={{ object.pk }}&term_side={{ side }}&return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-success lh-1">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add
</a>
{% endif %}
Expand Down

0 comments on commit a740203

Please sign in to comment.