mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
Fix bulk editing
This commit is contained in:
parent
9937efc4ee
commit
5aee17e998
@ -154,36 +154,31 @@ class MACAddressField(forms.Field):
|
|||||||
|
|
||||||
class MemoryField(forms.MultiValueField):
|
class MemoryField(forms.MultiValueField):
|
||||||
widget = widgets.MemoryWidget
|
widget = widgets.MemoryWidget
|
||||||
empty_values = ['', 'gb', 'mb', 'tb']
|
MULTIPLIERS = {
|
||||||
|
MemoryUnitChoices.UNIT_MB: 1024**0,
|
||||||
|
MemoryUnitChoices.UNIT_GB: 1024**1,
|
||||||
|
MemoryUnitChoices.UNIT_TB: 1024**2,
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
fields = (
|
fields = (
|
||||||
forms.IntegerField(required=False),
|
forms.IntegerField(required=False),
|
||||||
forms.CharField(required=False),
|
forms.ChoiceField(
|
||||||
|
choices=MemoryUnitChoices.CHOICES,
|
||||||
|
required=False
|
||||||
|
),
|
||||||
)
|
)
|
||||||
super(MemoryField, self).__init__(
|
super(MemoryField, self).__init__(
|
||||||
fields=fields, required=False,
|
fields=fields, required=False,
|
||||||
require_all_fields=False, **kwargs
|
require_all_fields=False, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
def compress(self, data):
|
@classmethod
|
||||||
|
def compress(cls, data):
|
||||||
if data:
|
if data:
|
||||||
value = data[0]
|
size, unit = data
|
||||||
unit = data[1]
|
if size:
|
||||||
|
return size * cls.MULTIPLIERS[unit]
|
||||||
defs = {
|
|
||||||
'gb': 1024**1,
|
|
||||||
'tb': 1024**2,
|
|
||||||
}
|
|
||||||
if value:
|
|
||||||
if unit != MemoryUnitChoices.UNIT_MB:
|
|
||||||
return value * defs[unit]
|
|
||||||
else:
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -319,11 +319,11 @@ class MemoryWidget(forms.MultiWidget):
|
|||||||
Memory Widget.
|
Memory Widget.
|
||||||
"""
|
"""
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
widget = (
|
widgets = (
|
||||||
forms.NumberInput(),
|
forms.NumberInput(),
|
||||||
StaticSelect(choices=MemoryUnitChoices.choices)
|
StaticSelect(choices=add_blank_choice(MemoryUnitChoices.CHOICES))
|
||||||
)
|
)
|
||||||
super(MemoryWidget, self).__init__(widget, attrs)
|
super(MemoryWidget, self).__init__(widgets, attrs)
|
||||||
|
|
||||||
def decompress(self, value):
|
def decompress(self, value):
|
||||||
if value:
|
if value:
|
||||||
|
@ -10,12 +10,13 @@ class MemoryUnitChoices(ChoiceSet):
|
|||||||
UNIT_GB = 'gb'
|
UNIT_GB = 'gb'
|
||||||
UNIT_TB = 'tb'
|
UNIT_TB = 'tb'
|
||||||
|
|
||||||
choices = (
|
CHOICES = (
|
||||||
(UNIT_MB, 'MB'),
|
(UNIT_MB, 'MB'),
|
||||||
(UNIT_GB, 'GB'),
|
(UNIT_GB, 'GB'),
|
||||||
(UNIT_TB, 'TB'),
|
(UNIT_TB, 'TB'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachineStatusChoices(ChoiceSet):
|
class VirtualMachineStatusChoices(ChoiceSet):
|
||||||
|
|
||||||
STATUS_OFFLINE = 'offline'
|
STATUS_OFFLINE = 'offline'
|
||||||
|
Loading…
Reference in New Issue
Block a user