physics_workload.app.pages.info

Classes

InfoForm

Describe a Form. Example:

InfoEdit

A page is used to compose iommi parts into a bigger whole.

Module Contents

class physics_workload.app.pages.info.InfoForm(**kwargs)

Bases: iommi.Form

Describe a Form. Example:

class MyForm(Form):
    a = Field()
    b = Field.email()

form = MyForm().bind(request=request)

You can also create an instance of a form with this syntax if it’s more convenient:

form = Form(
    fields=dict(
        a=Field(),
        b=Field.email(),
    ),
).bind(request=request)

In the common case the fields namespace will contain only instances of Field, but iommi actually supports arbitrary Part objects. For example:

form = Form(
    fields=dict(
        # Display a and b inside a box
        box=html.div(
            attrs__class__box=True,
            children__a=Field(),
            children__b=Field.email(),
        ),
        # And c regularly
        c=Field(),
    )
)

So that writing the application logic (e.g. validation and post handlers) is independent of minor changes to the layout, after bind the fields namespace of the form will contain only instances of Field keyed by their _name independently of how deep they are in the hierarchy. Given the above, an appropriate post_handler would be:

def post_handler(form, **_):
    if not form.is_valid():
        return

    print(form.fields.a.value, form.fields.b.value, form.fields.c.value)
    # And not:
    # print(form.fields.box.a.value, form.fields.box.b.value, form.fields.c.value)

# @test
assert post_handler(form=Struct(is_valid=lambda: False)) is None

post_handler(form.bind(request=req('post')))
# @end
class Meta
h_tag = (None,)
instance
auto
fields__text__attrs__class
fields__text__input__attrs__class
assets
class physics_workload.app.pages.info.InfoEdit(**kwargs)

Bases: iommi.Page

A page is used to compose iommi parts into a bigger whole.

See the howto for example usages.

header
form