當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.RegexField方法代碼示例

本文整理匯總了Python中django.forms.RegexField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.RegexField方法的具體用法?Python forms.RegexField怎麽用?Python forms.RegexField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.RegexField方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_regexfield_4

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_regexfield_4(self):
        f = RegexField('^[0-9]+$', min_length=5, max_length=10)
        with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 5 characters (it has 3).'"):
            f.clean('123')
        with self.assertRaisesMessage(
            ValidationError,
            "'Ensure this value has at least 5 characters (it has 3).', "
            "'Enter a valid value.'",
        ):
            f.clean('abc')
        self.assertEqual('12345', f.clean('12345'))
        self.assertEqual('1234567890', f.clean('1234567890'))
        with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 10 characters (it has 11).'"):
            f.clean('12345678901')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('12345a') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_regexfield.py

示例2: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def __init__(self, regex, required=True, help_text=None, max_length=None, min_length=None,
                 error_messages=None, validators=(), *args, **kwargs):
        self.field = forms.RegexField(
            regex=regex,
            required=required,
            help_text=help_text,
            max_length=max_length,
            min_length=min_length,
            error_messages=error_messages,
            validators=validators,
        )
        super().__init__(*args, **kwargs) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:14,代碼來源:field_block.py

示例3: test_validators_fail

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_validators_fail(self):
        field = SimpleListField(forms.RegexField("[a-e]{2}"))
        with pytest.raises(exceptions.ValidationError) as excinfo:
            field.clean("a,bc,de")
        assert (
            excinfo.value.messages[0]
            == "Item 1 in the list did not validate: Enter a valid value."
        ) 
開發者ID:adamchainz,項目名稱:django-mysql,代碼行數:10,代碼來源:test_forms.py

示例4: test_should_regex_convert_string

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_should_regex_convert_string():
    assert_conversion(forms.RegexField, String, "[0-9]+") 
開發者ID:graphql-python,項目名稱:graphene-django,代碼行數:4,代碼來源:test_converter.py

示例5: test_regexfield_1

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_regexfield_1(self):
        f = RegexField('^[0-9][A-F][0-9]$')
        self.assertEqual('2A2', f.clean('2A2'))
        self.assertEqual('3F3', f.clean('3F3'))
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('3G3')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean(' 2A2')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('2A2 ')
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean('') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:test_regexfield.py

示例6: test_regexfield_2

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_regexfield_2(self):
        f = RegexField('^[0-9][A-F][0-9]$', required=False)
        self.assertEqual('2A2', f.clean('2A2'))
        self.assertEqual('3F3', f.clean('3F3'))
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('3G3')
        self.assertEqual('', f.clean('')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:test_regexfield.py

示例7: test_regexfield_3

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_regexfield_3(self):
        f = RegexField(re.compile('^[0-9][A-F][0-9]$'))
        self.assertEqual('2A2', f.clean('2A2'))
        self.assertEqual('3F3', f.clean('3F3'))
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('3G3')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean(' 2A2')
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('2A2 ') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:test_regexfield.py

示例8: test_regexfield_unicode_characters

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_regexfield_unicode_characters(self):
        f = RegexField(r'^\w+$')
        self.assertEqual('éèøçÎÎ你好', f.clean('éèøçÎÎ你好')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:test_regexfield.py

示例9: test_validators_fail

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_validators_fail(self):
        field = SimpleArrayField(forms.RegexField('[a-e]{2}'))
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean('a,bc,de')
        self.assertEqual(cm.exception.messages[0], 'Item 1 in the array did not validate: Enter a valid value.') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_array.py

示例10: test_change_regex_after_init

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def test_change_regex_after_init(self):
        f = RegexField('^[a-z]+$')
        f.regex = '^[0-9]+$'
        self.assertEqual('1234', f.clean('1234'))
        with self.assertRaisesMessage(ValidationError, "'Enter a valid value.'"):
            f.clean('abcd') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:test_regexfield.py

示例11: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import RegexField [as 別名]
def __init__(self, regex, max_length=None, min_length=None, *args, **kwargs):
        super(RegexField, self).__init__(max_length, min_length, *args, **kwargs)
        self.regex = regex 
開發者ID:erigones,項目名稱:esdc-ce,代碼行數:5,代碼來源:fields.py


注:本文中的django.forms.RegexField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。