Parcourir la source

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

Jeremy Stretch il y a 7 ans
Parent
commit
e653f35bf1

+ 5 - 2
netbox/dcim/forms.py

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

+ 19 - 1
netbox/templates/dcim/virtualchassis_edit.html

@@ -7,7 +7,7 @@
         {{ pk_form.pk }}
         {{ pk_form.pk }}
         {{ formset.management_form }}
         {{ formset.management_form }}
         <div class="row">
         <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>
                 <h3>{% block title %}{% if vc_form.instance %}Editing {{ vc_form.instance }}{% else %}New Virtual Chassis{% endif %}{% endblock %}</h3>
                 {% if vc_form.non_field_errors %}
                 {% if vc_form.non_field_errors %}
                     <div class="panel panel-danger">
                     <div class="panel panel-danger">
@@ -29,6 +29,9 @@
                         <thead>
                         <thead>
                             <tr>
                             <tr>
                                 <th>Device</th>
                                 <th>Device</th>
+                                <th>ID</th>
+                                <th>Rack/Unit</th>
+                                <th>Serial</th>
                                 <th>Position</th>
                                 <th>Position</th>
                                 <th>Priority</th>
                                 <th>Priority</th>
                                 <th></th>
                                 <th></th>
@@ -44,6 +47,21 @@
                                         <td>
                                         <td>
                                             <a href="{{ device.get_absolute_url }}">{{ device }}</a>
                                             <a href="{{ device.get_absolute_url }}">{{ device }}</a>
                                         </td>
                                         </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_position }}</td>
                                         <td>{{ form.vc_priority }}</td>
                                         <td>{{ form.vc_priority }}</td>
                                         <td>
                                         <td>

+ 9 - 2
netbox/utilities/forms.py

@@ -119,7 +119,7 @@ class ColorSelect(forms.Select):
     """
     """
     Extends the built-in Select widget to colorize each <option>.
     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):
     def __init__(self, *args, **kwargs):
         kwargs['choices'] = COLOR_CHOICES
         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
     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).
     '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):
 class ArrayFieldSelectMultiple(SelectWithDisabled, forms.SelectMultiple):

netbox/utilities/templates/colorselect_option.html → netbox/utilities/templates/widgets/colorselect_option.html


+ 1 - 0
netbox/utilities/templates/widgets/select_option_with_pk.html

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

netbox/utilities/templates/selectwithdisabled_option.html → netbox/utilities/templates/widgets/selectwithdisabled_option.html