Skip to content

Commit 43909ee

Browse files
committed
Fixes #13649: Permit zero-length cables
1 parent 99467e8 commit 43909ee

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.db import migrations
2+
3+
4+
def update_cable_lengths(apps, schema_editor):
5+
Cable = apps.get_model('dcim', 'Cable')
6+
7+
# Set the absolute length for any zero-length Cables
8+
Cable.objects.filter(length=0).update(_abs_length=0)
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
dependencies = [
14+
('dcim', '0181_rename_device_role_device_role'),
15+
]
16+
17+
operations = [
18+
migrations.RunPython(
19+
code=update_cable_lengths,
20+
reverse_code=migrations.RunPython.noop
21+
),
22+
]

netbox/dcim/models/cables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def save(self, *args, **kwargs):
201201
_created = self.pk is None
202202

203203
# Store the given length (if any) in meters for use in database ordering
204-
if self.length and self.length_unit:
204+
if self.length is not None and self.length_unit:
205205
self._abs_length = to_meters(self.length, self.length_unit)
206206
else:
207207
self._abs_length = None

netbox/dcim/svg/cables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def draw_cable(self, cable, terminations, cable_count=0):
274274
if cable.type:
275275
# Include the cable type in the tooltip
276276
description.append(cable.get_type_display())
277-
if cable.length and cable.length_unit:
277+
if cable.length is not None and cable.length_unit:
278278
# Include the cable length in the tooltip
279279
description.append(f'{cable.length} {cable.get_length_unit_display()}')
280280
else:
@@ -285,7 +285,7 @@ def draw_cable(self, cable, terminations, cable_count=0):
285285
description = []
286286
if cable.type:
287287
labels.append(cable.get_type_display())
288-
if cable.length and cable.length_unit:
288+
if cable.length is not None and cable.length_unit:
289289
# Include the cable length in the tooltip
290290
labels.append(f'{cable.length} {cable.get_length_unit_display()}')
291291

netbox/templates/dcim/cable.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h5 class="card-header">{% trans "Cable" %}</h5>
5050
<tr>
5151
<th scope="row">{% trans "Length" %}</th>
5252
<td>
53-
{% if object.length %}
53+
{% if object.length is not None %}
5454
{{ object.length|floatformat }} {{ object.get_length_unit_display }}
5555
{% else %}
5656
{{ ''|placeholder }}

0 commit comments

Comments
 (0)