当前位置: 首页>>代码示例>>Python>>正文


Python forms.GenericIPAddressField方法代码示例

本文整理汇总了Python中django.forms.GenericIPAddressField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.GenericIPAddressField方法的具体用法?Python forms.GenericIPAddressField怎么用?Python forms.GenericIPAddressField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.GenericIPAddressField方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_generic_ipaddress_as_ipv4_only

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def test_generic_ipaddress_as_ipv4_only(self):
        f = GenericIPAddressField(protocol="IPv4")
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean('')
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean(None)
        self.assertEqual(f.clean(' 127.0.0.1 '), '127.0.0.1')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('foo')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('127.0.0.')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('1.2.3.4.5')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('256.125.1.5')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('fe80::223:6cff:fe8a:2e8a')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 address.'"):
            f.clean('2a02::223:6cff:fe8a:2e8a') 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_genericipaddressfield.py

示例2: test_generic_ipaddress_as_generic_not_required

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def test_generic_ipaddress_as_generic_not_required(self):
        f = GenericIPAddressField(required=False)
        self.assertEqual(f.clean(''), '')
        self.assertEqual(f.clean(None), '')
        self.assertEqual(f.clean('127.0.0.1'), '127.0.0.1')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 or IPv6 address.'"):
            f.clean('foo')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 or IPv6 address.'"):
            f.clean('127.0.0.')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 or IPv6 address.'"):
            f.clean('1.2.3.4.5')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv4 or IPv6 address.'"):
            f.clean('256.125.1.5')
        self.assertEqual(f.clean(' fe80::223:6cff:fe8a:2e8a '), 'fe80::223:6cff:fe8a:2e8a')
        self.assertEqual(f.clean(' 2a02::223:6cff:fe8a:2e8a '), '2a02::223:6cff:fe8a:2e8a')
        with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
            f.clean('12345:2:3:4')
        with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
            f.clean('1::2:3::4')
        with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
            f.clean('foo::223:6cff:fe8a:2e8a')
        with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
            f.clean('1::2:3:4:5:6:7:8')
        with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
            f.clean('1:2') 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:test_genericipaddressfield.py

示例3: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def __init__(self, verbose_name=None, name=None, protocol='both',
                 unpack_ipv4=False, *args, **kwargs):
        self.unpack_ipv4 = unpack_ipv4
        self.protocol = protocol
        self.default_validators, invalid_error_message = \
            validators.ip_address_validators(protocol, unpack_ipv4)
        self.default_error_messages['invalid'] = invalid_error_message
        kwargs['max_length'] = 39
        super(GenericIPAddressField, self).__init__(verbose_name, name, *args,
                                                    **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:__init__.py

示例4: check

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def check(self, **kwargs):
        errors = super(GenericIPAddressField, self).check(**kwargs)
        errors.extend(self._check_blank_and_null_values(**kwargs))
        return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:__init__.py

示例5: deconstruct

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def deconstruct(self):
        name, path, args, kwargs = super(GenericIPAddressField, self).deconstruct()
        if self.unpack_ipv4 is not False:
            kwargs['unpack_ipv4'] = self.unpack_ipv4
        if self.protocol != "both":
            kwargs['protocol'] = self.protocol
        if kwargs.get("max_length", None) == 39:
            del kwargs['max_length']
        return name, path, args, kwargs 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:__init__.py

示例6: get_internal_type

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def get_internal_type(self):
        return "GenericIPAddressField" 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:__init__.py

示例7: get_prep_value

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def get_prep_value(self, value):
        value = super(GenericIPAddressField, self).get_prep_value(value)
        if value is None:
            return None
        if value and ':' in value:
            try:
                return clean_ipv6_address(value, self.unpack_ipv4)
            except exceptions.ValidationError:
                pass
        return six.text_type(value) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:__init__.py

示例8: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def formfield(self, **kwargs):
        defaults = {
            'protocol': self.protocol,
            'form_class': forms.GenericIPAddressField,
        }
        defaults.update(kwargs)
        return super().formfield(**defaults) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:9,代码来源:__init__.py

示例9: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def formfield(self, **kwargs):
        return super().formfield(**{
            'protocol': self.protocol,
            'form_class': forms.GenericIPAddressField,
            **kwargs,
        }) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:8,代码来源:__init__.py

示例10: create_ipaddress_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def create_ipaddress_field(self, field, options):
        return forms.GenericIPAddressField(**options) 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:models.py

示例11: test_adding_custom_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def test_adding_custom_field(self):
        """Tests that we can add the ipaddress field, which is an extended choice."""
        ExtendedFormField.objects.create(
            page=self.form_page,
            sort_order=1,
            label='Device IP Address',
            field_type='ipaddress',
            required=True,
        )
        form_class = self.form_page.get_form_class()
        form = form_class()
        # check ip address field used
        self.assertIsInstance(
            form.base_fields['device-ip-address'], forms.GenericIPAddressField) 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_forms.py

示例12: deconstruct

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def deconstruct(self):
        name, path, args, kwargs = super(GenericIPAddressField, self).deconstruct()
        if self.unpack_ipv4 is not False:
            kwargs['unpack_ipv4'] = self.unpack_ipv4
        if self.protocol != "both":
            kwargs['protocol'] = self.protocol
        if kwargs.get("max_length") == 39:
            del kwargs['max_length']
        return name, path, args, kwargs 
开发者ID:Yeah-Kun,项目名称:python,代码行数:11,代码来源:__init__.py

示例13: formfield

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import GenericIPAddressField [as 别名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.GenericIPAddressField}
        defaults.update(kwargs)
        return super(GenericIPAddressField, self).formfield(**defaults) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:6,代码来源:__init__.py


注:本文中的django.forms.GenericIPAddressField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。