mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 11:42:52 -06:00
Closes #5806: Add kilometer and mile as choices for cable length unit
This commit is contained in:
parent
22e484edd4
commit
a6d937b366
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## v2.12-beta1 (FUTURE)
|
## v2.12-beta1 (FUTURE)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#5806](https://github.com/netbox-community/netbox/issues/5806) - Add kilometer and mile as choices for cable length unit
|
||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
|
||||||
* [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6
|
* [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6
|
||||||
|
@ -1064,14 +1064,21 @@ class CableStatusChoices(ChoiceSet):
|
|||||||
|
|
||||||
class CableLengthUnitChoices(ChoiceSet):
|
class CableLengthUnitChoices(ChoiceSet):
|
||||||
|
|
||||||
|
# Metric
|
||||||
|
UNIT_KILOMETER = 'km'
|
||||||
UNIT_METER = 'm'
|
UNIT_METER = 'm'
|
||||||
UNIT_CENTIMETER = 'cm'
|
UNIT_CENTIMETER = 'cm'
|
||||||
|
|
||||||
|
# Imperial
|
||||||
|
UNIT_MILE = 'mi'
|
||||||
UNIT_FOOT = 'ft'
|
UNIT_FOOT = 'ft'
|
||||||
UNIT_INCH = 'in'
|
UNIT_INCH = 'in'
|
||||||
|
|
||||||
CHOICES = (
|
CHOICES = (
|
||||||
|
(UNIT_KILOMETER, 'Kilometers'),
|
||||||
(UNIT_METER, 'Meters'),
|
(UNIT_METER, 'Meters'),
|
||||||
(UNIT_CENTIMETER, 'Centimeters'),
|
(UNIT_CENTIMETER, 'Centimeters'),
|
||||||
|
(UNIT_MILE, 'Miles'),
|
||||||
(UNIT_FOOT, 'Feet'),
|
(UNIT_FOOT, 'Feet'),
|
||||||
(UNIT_INCH, 'Inches'),
|
(UNIT_INCH, 'Inches'),
|
||||||
)
|
)
|
||||||
|
@ -198,15 +198,19 @@ def to_meters(length, unit):
|
|||||||
"Unknown unit {}. Must be one of the following: {}".format(unit, ', '.join(valid_units))
|
"Unknown unit {}. Must be one of the following: {}".format(unit, ', '.join(valid_units))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if unit == CableLengthUnitChoices.UNIT_KILOMETER:
|
||||||
|
return length * 1000
|
||||||
if unit == CableLengthUnitChoices.UNIT_METER:
|
if unit == CableLengthUnitChoices.UNIT_METER:
|
||||||
return length
|
return length
|
||||||
if unit == CableLengthUnitChoices.UNIT_CENTIMETER:
|
if unit == CableLengthUnitChoices.UNIT_CENTIMETER:
|
||||||
return length / 100
|
return length / 100
|
||||||
|
if unit == CableLengthUnitChoices.UNIT_MILE:
|
||||||
|
return length * 1609.344
|
||||||
if unit == CableLengthUnitChoices.UNIT_FOOT:
|
if unit == CableLengthUnitChoices.UNIT_FOOT:
|
||||||
return length * 0.3048
|
return length * 0.3048
|
||||||
if unit == CableLengthUnitChoices.UNIT_INCH:
|
if unit == CableLengthUnitChoices.UNIT_INCH:
|
||||||
return length * 0.3048 * 12
|
return length * 0.3048 * 12
|
||||||
raise ValueError("Unknown unit {}. Must be 'm', 'cm', 'ft', or 'in'.".format(unit))
|
raise ValueError(f"Unknown unit {unit}. Must be 'km', 'm', 'cm', 'mi', 'ft', or 'in'.")
|
||||||
|
|
||||||
|
|
||||||
def render_jinja2(template_code, context):
|
def render_jinja2(template_code, context):
|
||||||
|
Loading…
Reference in New Issue
Block a user