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

Remove external macaddress package dependency

This commit is contained in:
Nick Peelman
2016-07-05 10:41:38 -04:00
parent 9da4c28cd5
commit a6d41c95b8
5 changed files with 74 additions and 6 deletions

26
netbox/dcim/formfields.py Normal file
View File

@ -0,0 +1,26 @@
from netaddr import EUI, AddrFormatError
from django import forms
from django.core.exceptions import ValidationError
#
# Form fields
#
class MACAddressFormField(forms.Field):
default_error_messages = {
'invalid': "Enter a valid MAC address.",
}
def to_python(self, value):
if not value:
return None
if isinstance(value, EUI):
return value
try:
return EUI(value)
except AddrFormatError:
raise ValidationError("Please specify a valid MAC address.")