mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 19:47:20 -06:00
minor tweaks to error handling to allow for defaulted values from pre v2.6 data
This commit is contained in:
parent
1a5aaf54dd
commit
625a09785a
@ -1974,8 +1974,8 @@ class PowerPort(CableTermination, ComponentModel):
|
||||
allocated_draw_total=Sum('allocated_draw'),
|
||||
)
|
||||
ret = {
|
||||
'allocated': utilization['allocated_draw_total'],
|
||||
'maximum': utilization['maximum_draw_total'],
|
||||
'allocated': utilization['allocated_draw_total'] or 0,
|
||||
'maximum': utilization['maximum_draw_total'] or 0,
|
||||
'outlet_count': len(outlet_ids),
|
||||
'legs': [],
|
||||
}
|
||||
@ -1990,8 +1990,8 @@ class PowerPort(CableTermination, ComponentModel):
|
||||
)
|
||||
ret['legs'].append({
|
||||
'name': leg_name,
|
||||
'allocated': utilization['allocated_draw_total'],
|
||||
'maximum': utilization['maximum_draw_total'],
|
||||
'allocated': utilization['allocated_draw_total'] or 0,
|
||||
'maximum': utilization['maximum_draw_total'] or 0,
|
||||
'outlet_count': len(outlet_ids),
|
||||
})
|
||||
|
||||
@ -1999,8 +1999,8 @@ class PowerPort(CableTermination, ComponentModel):
|
||||
|
||||
# Default to administratively defined values
|
||||
return {
|
||||
'allocated': self.allocated_draw,
|
||||
'maximum': self.maximum_draw,
|
||||
'allocated': self.allocated_draw or 0,
|
||||
'maximum': self.maximum_draw or 0,
|
||||
'outlet_count': PowerOutlet.objects.filter(power_port=self).count(),
|
||||
'legs': [],
|
||||
}
|
||||
|
@ -171,6 +171,8 @@ def divide(x, y):
|
||||
"""
|
||||
Return x/y (rounded).
|
||||
"""
|
||||
if x is None or y is None:
|
||||
return None
|
||||
return round(x / y)
|
||||
|
||||
|
||||
@ -179,6 +181,8 @@ def percentage(x, y):
|
||||
"""
|
||||
Return x/y as a percentage.
|
||||
"""
|
||||
if x is None or y is None:
|
||||
return None
|
||||
return round(x / y * 100)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user