mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #13649: Permit zero-length cables
This commit is contained in:
22
netbox/dcim/migrations/0182_zero_length_cable_fix.py
Normal file
22
netbox/dcim/migrations/0182_zero_length_cable_fix.py
Normal file
@ -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
|
||||||
|
),
|
||||||
|
]
|
@ -201,7 +201,7 @@ class Cable(PrimaryModel):
|
|||||||
_created = self.pk is None
|
_created = self.pk is None
|
||||||
|
|
||||||
# Store the given length (if any) in meters for use in database ordering
|
# 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)
|
self._abs_length = to_meters(self.length, self.length_unit)
|
||||||
else:
|
else:
|
||||||
self._abs_length = None
|
self._abs_length = None
|
||||||
|
@ -274,7 +274,7 @@ class CableTraceSVG:
|
|||||||
if cable.type:
|
if cable.type:
|
||||||
# Include the cable type in the tooltip
|
# Include the cable type in the tooltip
|
||||||
description.append(cable.get_type_display())
|
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
|
# Include the cable length in the tooltip
|
||||||
description.append(f'{cable.length} {cable.get_length_unit_display()}')
|
description.append(f'{cable.length} {cable.get_length_unit_display()}')
|
||||||
else:
|
else:
|
||||||
@ -285,7 +285,7 @@ class CableTraceSVG:
|
|||||||
description = []
|
description = []
|
||||||
if cable.type:
|
if cable.type:
|
||||||
labels.append(cable.get_type_display())
|
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
|
# Include the cable length in the tooltip
|
||||||
labels.append(f'{cable.length} {cable.get_length_unit_display()}')
|
labels.append(f'{cable.length} {cable.get_length_unit_display()}')
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Length" %}</th>
|
<th scope="row">{% trans "Length" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.length %}
|
{% if object.length is not None %}
|
||||||
{{ object.length|floatformat }} {{ object.get_length_unit_display }}
|
{{ object.length|floatformat }} {{ object.get_length_unit_display }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ ''|placeholder }}
|
{{ ''|placeholder }}
|
||||||
|
Reference in New Issue
Block a user