mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-16 20:48:17 -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):
|
||||
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):
|
||||
fields = (
|
||||
forms.IntegerField(required=False),
|
||||
forms.CharField(required=False),
|
||||
forms.ChoiceField(
|
||||
choices=MemoryUnitChoices.CHOICES,
|
||||
required=False
|
||||
),
|
||||
)
|
||||
super(MemoryField, self).__init__(
|
||||
fields=fields, required=False,
|
||||
require_all_fields=False, **kwargs
|
||||
)
|
||||
|
||||
def compress(self, data):
|
||||
|
||||
@classmethod
|
||||
def compress(cls, data):
|
||||
if data:
|
||||
value = data[0]
|
||||
unit = data[1]
|
||||
|
||||
defs = {
|
||||
'gb': 1024**1,
|
||||
'tb': 1024**2,
|
||||
}
|
||||
if value:
|
||||
if unit != MemoryUnitChoices.UNIT_MB:
|
||||
return value * defs[unit]
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
|
||||
|
||||
size, unit = data
|
||||
if size:
|
||||
return size * cls.MULTIPLIERS[unit]
|
||||
|
||||
|
||||
#
|
||||
|
@ -319,11 +319,11 @@ class MemoryWidget(forms.MultiWidget):
|
||||
Memory Widget.
|
||||
"""
|
||||
def __init__(self, attrs=None):
|
||||
widget = (
|
||||
widgets = (
|
||||
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):
|
||||
if value:
|
||||
|
@ -10,12 +10,13 @@ class MemoryUnitChoices(ChoiceSet):
|
||||
UNIT_GB = 'gb'
|
||||
UNIT_TB = 'tb'
|
||||
|
||||
choices = (
|
||||
CHOICES = (
|
||||
(UNIT_MB, 'MB'),
|
||||
(UNIT_GB, 'GB'),
|
||||
(UNIT_TB, 'TB'),
|
||||
)
|
||||
|
||||
|
||||
class VirtualMachineStatusChoices(ChoiceSet):
|
||||
|
||||
STATUS_OFFLINE = 'offline'
|
||||
|
Loading…
Reference in New Issue
Block a user