Remove unpack_ipv4 parameter

This commit is contained in:
Andrea Grandi 2015-04-02 19:40:17 +01:00
parent 466575bee6
commit d6effbf779

View File

@ -661,16 +661,17 @@ class IPAddressField(CharField):
'invalid': _('Enter a valid IPv4 or IPv6 address.'), 'invalid': _('Enter a valid IPv4 or IPv6 address.'),
} }
def __init__(self, protocol='both', unpack_ipv4=False, **kwargs): def __init__(self, protocol='both', **kwargs):
self.protocol = protocol.lower() self.protocol = protocol.lower()
self.unpack_ipv4 = unpack_ipv4 self.unpack_ipv4 = (self.protocol == 'both')
super(IPAddressField, self).__init__(**kwargs) super(IPAddressField, self).__init__(**kwargs)
validators, error_message = ip_address_validators(protocol, unpack_ipv4) validators, error_message = ip_address_validators(protocol, self.unpack_ipv4)
self.validators.extend(validators) self.validators.extend(validators)
def to_internal_value(self, data): def to_internal_value(self, data):
if data and ':' in data: if data and ':' in data:
try: try:
if self.protocol in ('both', 'ipv6'):
return clean_ipv6_address(data, self.unpack_ipv4) return clean_ipv6_address(data, self.unpack_ipv4)
except DjangoValidationError: except DjangoValidationError:
self.fail('invalid', value=data) self.fail('invalid', value=data)