Просмотр исходного кода

Fixes #2639: Fix preservation of length/dimensions unit for racks and cables

Jeremy Stretch 7 лет назад
Родитель
Сommit
a3ade01224

+ 1 - 0
CHANGELOG.md

@@ -45,6 +45,7 @@ NetBox now supports modeling physical cables for console, power, and interface c
 * [#2622](https://github.com/digitalocean/netbox/issues/2622) - Enable filtering cables by multiple types/colors
 * [#2624](https://github.com/digitalocean/netbox/issues/2624) - Delete associated content type and permissions when removing InterfaceConnection model
 * [#2616](https://github.com/digitalocean/netbox/issues/2616) - Convert Rack `outer_unit` and Cable `length_unit` to integer-based choice fields
+* [#2639](https://github.com/digitalocean/netbox/issues/2639) - Fix preservation of length/dimensions unit for racks and cables
 
 ## API Changes
 

+ 2 - 2
netbox/dcim/models.py

@@ -554,7 +554,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
         # Validate outer dimensions and unit
         if (self.outer_width is not None or self.outer_depth is not None) and self.outer_unit is None:
             raise ValidationError("Must specify a unit when setting an outer width/depth")
-        else:
+        elif self.outer_width is None and self.outer_depth is None:
             self.outer_unit = None
 
         if self.pk:
@@ -2586,7 +2586,7 @@ class Cable(ChangeLoggedModel):
         # Validate length and length_unit
         if self.length is not None and self.length_unit is None:
             raise ValidationError("Must specify a unit when setting a cable length")
-        else:
+        elif self.length is None:
             self.length_unit = None
 
     def save(self, *args, **kwargs):

+ 1 - 1
netbox/templates/dcim/cable_trace.html

@@ -31,7 +31,7 @@
                     </h4>
                     {{ cable.get_status_display }}<br />
                     {{ cable.get_type_display|default:"" }}
-                    {% if cable.length %}- {{ cable.length }}{{ cable.length_unit }}{% endif %}
+                    {% if cable.length %}- {{ cable.length }}{{ cable.get_length_unit_display }}{% endif %}
                     <span class="label color-block center-block" style="background-color: #{{ cable.color }}">&nbsp;</span>
                 {% else %}
                     <h4 class="text-muted">No Cable</h4>

+ 2 - 2
netbox/templates/dcim/rack.html

@@ -158,7 +158,7 @@
                     <td>Outer Width</td>
                     <td>
                         {% if rack.outer_width %}
-                            <span>{{ rack.outer_width }}{{ rack.outer_unit }}</span>
+                            <span>{{ rack.outer_width }} {{ rack.get_outer_unit_display }}</span>
                         {% else %}
                             <span class="text-muted">&mdash;</span>
                         {% endif %}
@@ -168,7 +168,7 @@
                     <td>Outer Depth</td>
                     <td>
                         {% if rack.outer_depth %}
-                            <span>{{ rack.outer_depth }}{{ rack.outer_unit }}</span>
+                            <span>{{ rack.outer_depth }} {{ rack.get_outer_unit_display }}</span>
                         {% else %}
                             <span class="text-muted">&mdash;</span>
                         {% endif %}