Skip to content

Fixes #3310: Preselect cable fields #3893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
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
8 changes: 8 additions & 0 deletions docs/release-notes/version-2.7.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v2.7.3 (FUTURE)

## Enhancements

* [#3310](https://github.com/netbox-community/netbox/issues/3310) - Preselect site and rack when connecting cable

---

# v2.7.2 (2020-01-21)

## Enhancements
Expand Down
22 changes: 22 additions & 0 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,23 @@ class Meta:
'termination_b_site', 'termination_b_rack', 'termination_b_device', 'termination_b_id', 'type', 'status',
'label', 'color', 'length', 'length_unit',
]
widgets = {
'type': StaticSelect2(),
'status': StaticSelect2(),
'length_unit': StaticSelect2(),
}

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

super().__init__(*args, **kwargs)

# Initialize site and rack fields to match that of the existing temination
if self.instance and self.instance.termination_a:
termination_a_parent = self.instance.termination_a.parent
if hasattr(termination_a_parent, 'site'):
self.initial['termination_b_site'] = self.initial.get('termination_b_site', termination_a_parent.site)
if hasattr(termination_a_parent, 'rack'):
self.initial['termination_b_rack'] = self.initial.get('termination_b_rack', termination_a_parent.rack)


class ConnectCableToConsolePortForm(ConnectCableToDeviceForm):
Expand Down Expand Up @@ -3363,6 +3380,11 @@ class Meta:
fields = [
'type', 'status', 'label', 'color', 'length', 'length_unit',
]
widgets = {
'type': StaticSelect2(),
'status': StaticSelect2(),
'length_unit': StaticSelect2(),
}


class CableCSVForm(forms.ModelForm):
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/dcim/cable_connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ <h3>{% block title %}Connect {{ termination_a.device }} {{ termination_a }} to {
{% render_field form.color %}
<div class="form-group">
<label class="col-md-3 control-label" for="id_length">{{ form.length.label }}</label>
<div class="col-md-6">
<div class="col-md-5">
{{ form.length }}
</div>
<div class="col-md-3">
<div class="col-md-4">
{{ form.length_unit }}
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions netbox/templates/dcim/cable_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
{% render_field form.color %}
<div class="form-group">
<label class="col-md-3 control-label" for="id_length">{{ form.length.label }}</label>
<div class="col-md-6">
<div class="col-md-5">
{{ form.length }}
</div>
<div class="col-md-3">
<div class="col-md-4">
{{ form.length_unit }}
</div>
</div>
Expand Down