Пример #1
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)
Пример #2
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
Пример #3
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()
Пример #4
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
Пример #5
0
class StyleSelector(Form):
    class Meta:
        actions__submit__post_handler = select_style_post_handler

    style = Field.choice(
        choices=[
            k for k in keys(iommi.style._styles)
            if k not in ('test', 'base', 'bootstrap_horizontal')
        ],
        initial=lambda form, field, **_: iommi.style.DEFAULT_STYLE,
    )
Пример #6
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')
Пример #7
0
class StyleSelector(Form):
    class Meta:
        @staticmethod
        def actions__submit__post_handler(request, form, **_):
            style = form.fields.style.value
            settings.IOMMI_DEFAULT_STYLE = style
            return HttpResponseRedirect(request.get_full_path())

    style = Field.choice(
        choices=[k for k, v in items(iommi.style._styles) if not v.internal],
        initial=lambda form, field, **_: getattr(
            settings, 'IOMMI_DEFAULT_STYLE', iommi.style.DEFAULT_STYLE),
    )
Пример #8
0
class ShortcutSelectorForm(Form):
    class Meta:
        attrs__method = 'get'

    shortcut = Field.multi_choice(choices=[
        t for t in keys(
            get_members(
                cls=Column, member_class=Shortcut, is_member=is_shortcut))
        if t not in [
            'icon',
            'foreign_key',
            'many_to_many',
            'choice_queryset',
            'multi_choice_queryset',
        ]
    ])
Пример #9
0
class StyleSelector(Form):
    class Meta:
        @staticmethod
        def actions__submit__post_handler(request, form, **_):
            style = form.fields.style.value
            settings.IOMMI_DEFAULT_STYLE = style
            return HttpResponseRedirect(request.get_full_path())

    style = Field.choice(
        choices=[
            k for k in keys(iommi.style._styles)
            if k not in ('test', 'base') and not k.endswith('_horizontal')
        ],
        initial=lambda form, field, **_: getattr(
            settings, 'IOMMI_DEFAULT_STYLE', iommi.style.DEFAULT_STYLE),
    )
Пример #10
0
 class MyForm(Form):
     foo = Field()
     bar = Field()
Пример #11
0
class SinkForm(Form):
    class Meta:
        name = 'sink'

    foo = Field()
Пример #12
0
 class MyQuery(Query):
     bazaar = Field.boolean_tristate(attr='quux__bar__bazaar')
Пример #13
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
Пример #14
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