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

@ -14,7 +14,6 @@ class ChoiceSetMeta(type):
class ChoiceSet(metaclass=ChoiceSetMeta):
CHOICES = list()
LEGACY_MAP = dict()
@classmethod
def values(cls):
@ -25,25 +24,6 @@ class ChoiceSet(metaclass=ChoiceSetMeta):
# Unpack grouped choices before casting as a dict
return dict(unpack_grouped_choices(cls.CHOICES))
@classmethod
def slug_to_id(cls, slug):
"""
Return the legacy integer value corresponding to a slug.
"""
return cls.LEGACY_MAP.get(slug)
@classmethod
def id_to_slug(cls, legacy_id):
"""
Return the slug value corresponding to a legacy integer value.
"""
if legacy_id in cls.LEGACY_MAP.values():
# Invert the legacy map to allow lookup by integer
legacy_map = dict([
(id, slug) for slug, id in cls.LEGACY_MAP.items()
])
return legacy_map.get(legacy_id)
def unpack_grouped_choices(choices):
"""