1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #1884: Provide additional context to identify devices when creating/editing avirtual chassis

This commit is contained in:
Jeremy Stretch
2018-02-14 11:14:04 -05:00
parent 28ea06a8bc
commit e653f35bf1
6 changed files with 34 additions and 5 deletions

View File

@ -17,8 +17,8 @@ from utilities.forms import (
APISelect, APISelectMultiple, add_blank_choice, ArrayFieldSelectMultiple, BootstrapMixin, BulkEditForm,
BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, ChainedModelMultipleChoiceField,
CommentField, ComponentForm, ConfirmationForm, CSVChoiceField, ExpandableNameField, FilterChoiceField,
FlexibleModelChoiceField, Livesearch, SelectWithDisabled, SmallTextarea, SlugField,
FilterTreeNodeMultipleChoiceField,
FilterTreeNodeMultipleChoiceField, FlexibleModelChoiceField, Livesearch, SelectWithDisabled, SelectWithPK,
SmallTextarea, SlugField,
)
from virtualization.models import Cluster
from .constants import (
@ -2272,6 +2272,9 @@ class VirtualChassisForm(BootstrapMixin, forms.ModelForm):
class Meta:
model = VirtualChassis
fields = ['master', 'domain']
widgets = {
'master': SelectWithPK,
}
class VCMemberSelectForm(BootstrapMixin, ChainedFieldsMixin, forms.Form):

View File

@ -7,7 +7,7 @@
{{ pk_form.pk }}
{{ formset.management_form }}
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="col-md-8 col-md-offset-2">
<h3>{% block title %}{% if vc_form.instance %}Editing {{ vc_form.instance }}{% else %}New Virtual Chassis{% endif %}{% endblock %}</h3>
{% if vc_form.non_field_errors %}
<div class="panel panel-danger">
@ -29,6 +29,9 @@
<thead>
<tr>
<th>Device</th>
<th>ID</th>
<th>Rack/Unit</th>
<th>Serial</th>
<th>Position</th>
<th>Priority</th>
<th></th>
@ -44,6 +47,21 @@
<td>
<a href="{{ device.get_absolute_url }}">{{ device }}</a>
</td>
<td>{{ device.pk }}</td>
<td>
{% if device.rack %}
{{ device.rack }} / {{ device.position }}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
<td>
{% if device.serial %}
{{ device.serial }}}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
<td>{{ form.vc_position }}</td>
<td>{{ form.vc_priority }}</td>
<td>

View File

@ -119,7 +119,7 @@ class ColorSelect(forms.Select):
"""
Extends the built-in Select widget to colorize each <option>.
"""
option_template_name = 'colorselect_option.html'
option_template_name = 'widgets/colorselect_option.html'
def __init__(self, *args, **kwargs):
kwargs['choices'] = COLOR_CHOICES
@ -144,7 +144,14 @@ class SelectWithDisabled(forms.Select):
Modified the stock Select widget to accept choices using a dict() for a label. The dict for each option must include
'label' (string) and 'disabled' (boolean).
"""
option_template_name = 'selectwithdisabled_option.html'
option_template_name = 'widgets/selectwithdisabled_option.html'
class SelectWithPK(forms.Select):
"""
Include the primary key of each option in the option label (e.g. "Router7 (4721)").
"""
option_template_name = 'widgets/select_option_with_pk.html'
class ArrayFieldSelectMultiple(SelectWithDisabled, forms.SelectMultiple):

View File

@ -0,0 +1 @@
<option value="{{ widget.value|stringformat:'s' }}"{% include "django/forms/widgets/attrs.html" %}>{{ widget.label }}{% if widget.value %} ({{ widget.value }}){% endif %}</option>