當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。