示例#1
0
    class MyForm(Form):
        name = Field()
        color = Field.choice(choices=['Red', 'Green', 'Blue'])
        in_a_box = html.div(
            children__f1=Field.integer(attrs__class__column=True),
            children__plus=html.span("+",
                                     attrs__class={
                                         'column': True,
                                         'is-narrow': True
                                     }),
            children__f2=Field.integer(attrs__class__column=True, ),
            children__equals=html.span("=",
                                       attrs__class={
                                           'column': True,
                                           'is-narrow': True
                                       }),
            children__f3=Field.integer(attrs__class_column=True),
            iommi_style="bulma_query_form",
            attrs__class={
                'box': True,
                'columns': True,
                'is-vcentered': True
            })

        class Meta:
            iommi_style = "bulma"
            title = "Children that are not fields"
            post_validation = post_valid
            actions__submit__post_handler = on_submit
示例#2
0
def form_example_children_that_are_not_fields(request):
    def on_submit(form, **_):
        if not form.is_valid():
            return
        return html.pre(f"You posted: {form.apply(Struct())}").bind(request=request)

    def post_validation(form, **_):
        if form.is_valid():
            if form.fields.f1.value + form.fields.f2.value != form.fields.f3.value:
                form.add_error("Calculate again!")

    return Form(
        iommi_style="bulma",
        title="Children that are not fields",
        fields__name=Field(),
        fields__color=Field.choice(choices=['Red', 'Green', 'Blue']),
        fields__in_box=html.div(
            children__f1=Field.integer(attrs__class__column=True),
            children__plus=html.span("+", attrs__class={'column': True, 'is-narrow': True}),
            children__f2=Field.integer(attrs__class__column=True,),
            children__equals=html.span("=", attrs__class={'column': True, 'is-narrow': True}),
            children__f3=Field.integer(attrs__class_column=True),
            iommi_style="bulma_query_form",
            attrs__class={'box': True, 'columns': True, 'is-vcentered': True}
        ),
        post_validation=post_validation,
        actions__submit__post_handler=on_submit
    )
示例#3
0
    class IssuePage(Page):
        title = Header(
            issue.name,
            children__number=html.span(
                format_html(
                    f' <a href="{issue.get_absolute_url()}">#{issue.pk}</a>'),
                after=-1,
                attrs__class__faded=True,
            ),
        )

        user_properties = html.ul(
            attrs__class__properties=True,
            children={
                x.name: html.li(
                    f'{x.name}: {x.data}',
                    attrs__class=dict(
                        unread=unread_data.is_unread(x.last_changed_time),
                        unread2=unread_data.is_unread2(x.last_changed_time),
                    ),
                )
                for x in issue.user_properties.all()
            })

        text_properties = html.ul(
            attrs__class__properties=True,
            children={
                x.name: html.li(
                    f'{x.name}: {x.data}',
                    attrs__class=dict(
                        unread=unread_data.is_unread(x.last_changed_time),
                        unread2=unread_data.is_unread2(x.last_changed_time),
                    ),
                )
                for x in issue.text_properties.all()
            })

        comments = RoomPage(room=issue.comments,
                            unread_data=unread_data,
                            parts__header__template='forum/blank.html'
                            ) if issue.comments_id else None
示例#4
0
 class MyPage(Page):
     foo = html.div(
         'foo',
         assets__my_asset=html.span(attrs__href='http://foo.bar/baz'))