1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #4857: Drop support for legacy numeric choice field values

This commit is contained in:
Jeremy Stretch
2020-07-15 16:54:33 -04:00
parent 7461e76606
commit 19d0d6ff10
9 changed files with 4 additions and 337 deletions

View File

@@ -103,18 +103,11 @@ class ChoiceField(serializers.Field):
def to_representation(self, obj):
if obj is '':
return None
data = OrderedDict([
return OrderedDict([
('value', obj),
('label', self._choices[obj])
])
# TODO: Remove in v2.8
# Include legacy numeric ID (where applicable)
if hasattr(self.choiceset, 'LEGACY_MAP') and obj in self.choiceset.LEGACY_MAP:
data['id'] = self.choiceset.LEGACY_MAP.get(obj)
return data
def to_internal_value(self, data):
if data is '':
if self.allow_blank:
@@ -140,14 +133,10 @@ class ChoiceField(serializers.Field):
try:
if data in self._choices:
return data
# Check if data is a legacy numeric ID
slug = self.choiceset.id_to_slug(data)
if slug is not None:
return slug
except TypeError: # Input is an unhashable type
pass
raise ValidationError("{} is not a valid choice.".format(data))
raise ValidationError(f"{data} is not a valid choice.")
@property
def choices(self):