1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Arthur Hanson af27bf5eff 15094 Add missing gettext to error strings for internationalization (#15155)
* 15049 add missing gettext to error strings

* 15049 add missing gettext to error strings

* 15094 review change

* 15094 review change

* Formatting cleanup

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-02-20 09:44:02 -05:00

29 lines
802 B
Python

from decimal import Decimal
from django.utils.translation import gettext_lazy as _
from .choices import WirelessChannelChoices
__all__ = (
'get_channel_attr',
)
def get_channel_attr(channel, attr):
"""
Return the specified attribute of a given WirelessChannelChoices value.
"""
if channel not in WirelessChannelChoices.values():
raise ValueError(_("Invalid channel value: {channel}").format(channel=channel))
channel_values = channel.split('-')
attrs = {
'band': channel_values[0],
'id': int(channel_values[1]),
'frequency': Decimal(channel_values[2]),
'width': Decimal(channel_values[3]),
}
if attr not in attrs:
raise ValueError(_("Invalid channel attribute: {name}").format(name=attr))
return attrs[attr]