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
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
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)
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()
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')
class MyForm(Form): foo = Field() bar = Field()
class SinkForm(Form): class Meta: name = 'sink' foo = Field()
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
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