Skip to content
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

Fixes #13649: Permit zero-length cables #14592

Merged
merged 1 commit into from
Dec 26, 2023
Merged
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
22 changes: 22 additions & 0 deletions netbox/dcim/migrations/0182_zero_length_cable_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import migrations


def update_cable_lengths(apps, schema_editor):
Cable = apps.get_model('dcim', 'Cable')

# Set the absolute length for any zero-length Cables
Cable.objects.filter(length=0).update(_abs_length=0)


class Migration(migrations.Migration):

dependencies = [
('dcim', '0181_rename_device_role_device_role'),
]

operations = [
migrations.RunPython(
code=update_cable_lengths,
reverse_code=migrations.RunPython.noop
),
]
2 changes: 1 addition & 1 deletion netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def save(self, *args, **kwargs):
_created = self.pk is None

# Store the given length (if any) in meters for use in database ordering
if self.length and self.length_unit:
if self.length is not None and self.length_unit:
self._abs_length = to_meters(self.length, self.length_unit)
else:
self._abs_length = None
Expand Down
4 changes: 2 additions & 2 deletions netbox/dcim/svg/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def draw_cable(self, cable, terminations, cable_count=0):
if cable.type:
# Include the cable type in the tooltip
description.append(cable.get_type_display())
if cable.length and cable.length_unit:
if cable.length is not None and cable.length_unit:
# Include the cable length in the tooltip
description.append(f'{cable.length} {cable.get_length_unit_display()}')
else:
Expand All @@ -285,7 +285,7 @@ def draw_cable(self, cable, terminations, cable_count=0):
description = []
if cable.type:
labels.append(cable.get_type_display())
if cable.length and cable.length_unit:
if cable.length is not None and cable.length_unit:
# Include the cable length in the tooltip
labels.append(f'{cable.length} {cable.get_length_unit_display()}')

Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/dcim/cable.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h5 class="card-header">{% trans "Cable" %}</h5>
<tr>
<th scope="row">{% trans "Length" %}</th>
<td>
{% if object.length %}
{% if object.length is not None %}
{{ object.length|floatformat }} {{ object.get_length_unit_display }}
{% else %}
{{ ''|placeholder }}
Expand Down