예제 #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
파일: views.py 프로젝트: tltx/iommi
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