本文整理汇总了Python中tri.form.Field类的典型用法代码示例。如果您正苦于以下问题:Python Field类的具体用法?Python Field怎么用?Python Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Field类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_field_from_model_supports_all_types
def test_field_from_model_supports_all_types():
from django.db.models import fields
not_supported = []
blacklist = {
'AutoField',
'Field',
'BigAutoField',
'BinaryField',
'FilePathField',
'GenericIPAddressField',
'IPAddressField',
'NullBooleanField',
'SlugField',
'DurationField',
'UUIDField'
}
field_type_names = [x for x in dir(fields) if x.endswith('Field') and x not in blacklist]
for name in field_type_names:
field_type = getattr(fields, name)
try:
Field.from_model(model=Foo, model_field=field_type())
except AssertionError: # pragma: no cover
not_supported.append(name)
assert not_supported == []
开发者ID:TriOptima,项目名称:tri.form,代码行数:26,代码来源:test_forms.py
示例2: test_field_from_model_blank_handling
def test_field_from_model_blank_handling():
from django.db.models import CharField
subject = Field.from_model(model=Foo, model_field=CharField(blank=False))
assert True is subject.parse_empty_string_as_none
subject = Field.from_model(model=Foo, model_field=CharField(blank=True))
assert False is subject.parse_empty_string_as_none
开发者ID:TriOptima,项目名称:tri.form,代码行数:8,代码来源:test_forms.py
示例3: test_field_from_model_many_to_many
def test_field_from_model_many_to_many():
Foo.objects.create(foo=2)
Foo.objects.create(foo=3)
Foo.objects.create(foo=5)
choices = Field.from_model(FieldFromModelManyToManyTest, 'foo_many_to_many').choices
assert isinstance(choices, QuerySet)
assert set(choices) == set(Foo.objects.all())
开发者ID:TriOptima,项目名称:tri.form,代码行数:7,代码来源:test_forms.py
示例4: test_comma_separated_errors_on_validation
def test_comma_separated_errors_on_validation():
assert Form(
data=dict(foo='5, 7'),
fields=[Field.comma_separated(Field(name='foo', is_valid=lambda parsed_data, **_: (False, 'foo %s!' % parsed_data)))]).fields[0].errors == {
u'Invalid value "5": foo 5!',
u'Invalid value "7": foo 7!',
}
开发者ID:TriOptima,项目名称:tri.form,代码行数:7,代码来源:test_forms.py
示例5: test_field_from_model_foreign_key
def test_field_from_model_foreign_key():
Foo.objects.create(foo=2)
Foo.objects.create(foo=3)
Foo.objects.create(foo=5)
choices = Field.from_model(FieldFromModelForeignKeyTest, 'foo_fk').choices
assert isinstance(choices, QuerySet)
assert set(choices) == set(Foo.objects.all())
开发者ID:pombredanne,项目名称:tri.form,代码行数:7,代码来源:test_forms.py
示例6: test_render_datetime_iso
def test_render_datetime_iso():
table = Form(fields=[
Field.datetime(
name='foo',
initial=datetime(2001, 2, 3, 12, 13, 14, 7777))
]).table()
assert '2001-02-03 12:13:14' in table
assert '7777' not in table
开发者ID:Haggen-,项目名称:tri.form,代码行数:8,代码来源:test_forms.py
示例7: test_radio
def test_radio():
choices = [
'a',
'b',
'c',
]
soup = BeautifulSoup(Form(data=Data(foo='a'), fields=[Field.radio(name='foo', choices=choices)]).validate().table())
assert len(soup.find_all('input')) == len(choices) + 1 # +1 for AVOID_EMPTY_FORM
assert [x.attrs['value'] for x in soup.find_all('input') if 'checked' in x.attrs] == ['a']
开发者ID:pombredanne,项目名称:tri.form,代码行数:9,代码来源:test_forms.py
示例8: test_comma_separated_errors_on_parse
def test_comma_separated_errors_on_parse():
def raise_always_value_error(string_value, **_):
raise ValueError('foo %s!' % string_value)
def raise_always_validation_error(string_value, **_):
raise ValidationError(['foo %s!' % string_value, 'bar %s!' % string_value])
assert Form(
data=Data(foo='5, 7'),
fields=[Field.comma_separated(Field(name='foo', parse=raise_always_value_error))]).validate().fields[0].errors == {
u'Invalid value "5": foo 5!',
u'Invalid value "7": foo 7!'}
assert Form(
data=Data(foo='5, 7'),
fields=[Field.comma_separated(Field(name='foo', parse=raise_always_validation_error))]).validate().fields[0].errors == {
u'Invalid value "5": foo 5!',
u'Invalid value "5": bar 5!',
u'Invalid value "7": foo 7!',
u'Invalid value "7": bar 7!'}
开发者ID:pombredanne,项目名称:tri.form,代码行数:20,代码来源:test_forms.py
示例9: test_boolean_initial_true
def test_boolean_initial_true():
fields = [Field.boolean(name='foo', initial=True), Field(name='bar', required=False)]
form = Form(data=Data(), fields=fields).validate()
assert form.fields_by_name['foo'].value is True
# If there are arguments, but not for key foo it means checkbox for foo has been unchecked.
# Field foo should therefore be false.
form = Form(data=Data(bar='baz'), fields=fields).validate()
assert form.fields_by_name['foo'].value is False
form = Form(data=Data(foo='on', bar='baz'), fields=fields).validate()
assert form.fields_by_name['foo'].value is True
开发者ID:pombredanne,项目名称:tri.form,代码行数:13,代码来源:test_forms.py
示例10: test_choices_from_query_set
def test_choices_from_query_set():
user = User.objects.create(username='foo')
assert [x.pk for x in Form(fields=[Field.multi_choice_queryset(name='foo', model=User, choices=User.objects.all())]).validate().fields[0].choices] == [user.pk]
开发者ID:pombredanne,项目名称:tri.form,代码行数:3,代码来源:test_forms.py
示例11: test_help_text_from_model
def test_help_text_from_model():
assert Form(data=Data(foo='1'), fields=[Field.from_model(model=Foo, field_name='foo')], model=Foo).validate().fields[0].help_text == 'foo_help_text'
开发者ID:pombredanne,项目名称:tri.form,代码行数:2,代码来源:test_forms.py
示例12: test_multi_choice
def test_multi_choice():
soup = BeautifulSoup(Form(data=Data(foo=['0']), fields=[Field.multi_choice(name='foo', choices=['a'])]).validate().table())
assert [x.attrs['multiple'] for x in soup.find_all('select')] == ['']
开发者ID:pombredanne,项目名称:tri.form,代码行数:3,代码来源:test_forms.py
示例13: test_password
def test_password():
assert ' type="password" ' in Form(data=Data(foo='1'), fields=[Field.password(name='foo')]).validate().table()
开发者ID:pombredanne,项目名称:tri.form,代码行数:2,代码来源:test_forms.py
示例14: test_hidden
def test_hidden():
soup = BeautifulSoup(Form(data=Data(foo='1'), fields=[Field.hidden(name='foo')]).validate().table())
assert [(x.attrs['type'], x.attrs['value']) for x in soup.find_all('input')] == [('hidden', '1'), ('hidden', '-')]
开发者ID:pombredanne,项目名称:tri.form,代码行数:3,代码来源:test_forms.py
示例15: test_json_parsing
def test_json_parsing():
# NOTE: Parsing json input requires that any numbers that come in must avoid the string strip
f = Form(data={'foo': 1}, fields=[Field.integer(name='foo', strip_input=False)])
assert f.is_valid()
assert f.fields_by_name['foo'].value == 1
开发者ID:TriOptima,项目名称:tri.form,代码行数:5,代码来源:test_forms.py
示例16: test_render_datetime_iso
def test_render_datetime_iso():
assert '2001-02-03 12:13:14' in Form(fields=[
Field.datetime(
name='foo',
initial=datetime(2001, 2, 3, 12, 13, 14))
]).validate().table()
开发者ID:pombredanne,项目名称:tri.form,代码行数:6,代码来源:test_forms.py
示例17: test_multi_select_with_one_value_only
def test_multi_select_with_one_value_only():
assert ['a'] == Form(data=Data(foo=['a']), fields=[Field.multi_choice(name='foo', choices=['a', 'b'])]).validate().fields[0].value_list
开发者ID:pombredanne,项目名称:tri.form,代码行数:2,代码来源:test_forms.py
示例18: test_phone_field
def test_phone_field():
assert Form(data=Data(foo=' asdasd '), fields=[Field.phone_number(name='foo')]).validate().fields[0].errors == {u'Please use format +<country code> (XX) XX XX. Example of US number: +1 (212) 123 4567 or +1 212 123 4567'}
assert Form(data=Data(foo='+1 (212) 123 4567'), fields=[Field.phone_number(name='foo')]).is_valid()
assert Form(data=Data(foo='+46 70 123 123'), fields=[Field.phone_number(name='foo')]).is_valid()
开发者ID:pombredanne,项目名称:tri.form,代码行数:4,代码来源:test_forms.py
示例19: test_datetime_not_required
def test_datetime_not_required():
assert Form(fields=[
Field.datetime(
required=False,
name='foo')
], data={'foo': ''}).is_valid()
开发者ID:Haggen-,项目名称:tri.form,代码行数:6,代码来源:test_forms.py
示例20: test_multi_email
def test_multi_email():
assert Form(data=Data(foo='[email protected], [email protected]'), fields=[Field.comma_separated(Field.email(name='foo'))]).is_valid()
开发者ID:pombredanne,项目名称:tri.form,代码行数:2,代码来源:test_forms.py
注:本文中的tri.form.Field类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论