Пример #1
0
def test_format_html4():
    form = Form(fields=dict(foo=Field()))
    form.bind(request=req('get'))
    actual = render_template(req('get'), Template('{{form}}'),
                             dict(form=form, ))
    print(actual)
    assert '<input id="id_foo" name="foo" type="text" value="">' in actual
Пример #2
0
def test_format_html5():
    actual = Form(
        fields__foo=Field(),
    ).bind(
        request=req('get'),
    ).__html__()
    assert '<form' in actual
    assert '<input' in actual
    assert type(actual) == SafeText
Пример #3
0
class KitchenForm(Form):
    class Meta:
        name = 'kitchen'

    foo = Field()

    fisk = Field.multi_choice(choices=[1, 2, 3, 4],
                              parse=choice_parse,
                              initial=[1, 2],
                              editable=False)
Пример #4
0
class KitchenForm(Form):
    class Meta:
        _name = 'kitchen'

    kitchen_foo = Field()

    fisk = Field.multi_choice(choices=[1, 2, 3, 4],
                              parse=choice_parse,
                              initial=[1, 2],
                              editable=False)

    textarea = Field.textarea(initial='initial value')

    radio = Field.radio(choices=['foo!!_"', 'bar', 'baz'])

    checkbox = Field.boolean()
Пример #5
0
class LoginForm(Form):
    username = Field()
    password = Field.password()

    class Meta:
        title = 'Login'

        @staticmethod
        def actions__submit__post_handler(form, **_):
            if form.is_valid():
                user = auth.authenticate(
                    username=form.fields.username.value,
                    password=form.fields.password.value,
                )

                if user is not None:
                    request = form.get_request()
                    auth.login(request, user)
                    return HttpResponseRedirect(request.GET.get('next', '/'))

                form.errors.add('Unknown username or password')
Пример #6
0
 class MyForm(Form):
     foo = Field()
     bar = Field()
Пример #7
0
class SinkForm(Form):
    class Meta:
        name = 'sink'

    foo = Field()
Пример #8
0
def test_format_html7():
    form = Form(fields__foo=Field()).bind(request=req('get'))
    actual = str(form.fields.foo)
    print(actual)
    assert '<input' in actual
    assert type(actual) == SafeText
Пример #9
0
def test_format_html6():
    form = Form(fields__foo=Field()).bind(request=req('get'))
    actual = form.fields.foo.__html__()
    assert '<input' in actual
    assert type(actual) == SafeText