Пример #1
0
    async def layout(request: web.Request):
        next_url = request.query.get('next_url') or default_redirect
        error = request.query.get('err')

        footer = core.Container(
            'Invalid credentials',
            style={'color': 'red', 'padding': '0.5rem'},
            identity='login-error'
        ) if error else UNDEFINED

        return core.Container([
            auth.Login(
                '/auth/login',
                method='post',
                identity='login-form',
                next_url=next_url,
                bordered=True,
                header=core.Html('h2', 'Please sign in'),
                footer=footer,
                style={
                    'padding': '2rem',
                }
            ),
        ], style={
            'display': 'flex',
            'justifyContent': 'center',
            'alignItems': 'center',
            'width': '100%',
            'marginTop': '4rem'
        })
Пример #2
0
async def layout(request: web.Request):
    user = request.cookies.get('logged-user')
    if user:
        return core.Container([
            core.Html('h1', f'Logged in as {user}', identity='login-label'),
            auth.Logout('/login/logout', identity='logout'),
        ])
    return core.Container([
        auth.Login(
            '/login/login-perform',
            method='post',
            identity='login-form',
            bordered=True,
            header=core.Html('h3', 'Please login', identity='login-label'),
        ),
    ])
Пример #3
0
async def test_html_single(start_page, browser, tag_name, attributes):
    # Test attributes are set and render.
    page = Page(__name__,
                core.Html(tag_name, attributes=attributes, identity='html'))
    await start_page(page)

    component = await browser.wait_for_element_by_id('html')

    for k, v in attributes.items():
        if k == 'children':
            await browser.wait_for_text_to_equal('#html', v)
        else:
            attr = component.get_attribute(k)
            assert attr == str(v)
Пример #4
0
def auth_app():
    app = Dazzler(__name__)
    page = Page('test-auth',
                core.Container([
                    core.Html('h2', 'logged-in', identity='header'),
                    core.Container(identity='username-output'),
                    _auth.Logout('/auth/logout', identity='logout')
                ]),
                url='/',
                require_login=True)

    @page.bind(Trigger('header', 'children'))
    async def on_username(ctx):
        user = ctx.request['user']
        await ctx.set_aspect('username-output', children=user.username)

    app.add_page(page)
    app.config.session.backend = 'Redis'

    DazzlerAuth(app, DummyAuthenticator())

    return app
Пример #5
0
"""
Page page_map of dazzler
Created 2021-06-13
"""
from dazzler.components import core, extra
from dazzler.system import Page

page = Page(__name__,
            core.Container([
                core.Html('h1', 'Dazzler Playground'),
                extra.PageMap(),
            ]),
            url='/')
Пример #6
0
from dazzler.components import core
from dazzler.system import Page, Trigger, BindingContext, State

page = Page(
    __name__,
    core.Container([
        core.Container(core.Container('from children'), identity='component'),
        core.Container(identity='output'),
        core.Container([
            core.Container(str(x)) for x in range(0, 10)
        ], identity='array-components'),
        core.Container(identity='array-output'),

        core.Container(core.Container(core.Container([
            core.Html(
                'div', core.Container('inside html div'),
                identity='inside-html'
            ),
            core.Html(
                'div',
                attributes={'children': core.Html('span', 'attribute')}
            ),
        ])), identity='nested-components'),
        core.Container(identity='nested-output'),

        core.Button('get-aspect-click', identity='get-aspect-trigger'),
        core.Container(
            core.Input(value='input-value'),
            identity='input'
        ),
        core.Container(core.Input(value=4747), identity='as-state'),
        core.Container(identity='get-aspect-output'),
Пример #7
0
text_inputs = ('text', 'search', 'tel', 'password', 'email')

page = Page(
    'input-output',
    core.Container([
        # Textual inputs
        core.Html(
            'form',
            [
                core.Container(
                    list(
                        itertools.chain(
                            *((core.Input(type=text, identity=text, name=text),
                               core.Container(f'{text}-output',
                                              identity=f'{text}-output'))
                              for text in text_inputs)))),
                core.Input(identity='number', type='number', name='num'),
                core.Input(identity='checkbox', type='checkbox'),
                core.Container(identity='number-output'),
                core.Container(identity='checkbox-output'),
                # FIXME Reset doesn't work with controlled components.
                #  Maybe add a proper Form component and reset button?
                # core.Input(type='reset'),
            ]),
    ]))


async def on_value(ctx: BindingContext):
    await ctx.set_aspect(
        f'{ctx.trigger.identity}-output',
        children=f'{ctx.trigger.identity} value {ctx.trigger.value}')
Пример #8
0
"""
Page html of dazzler
Created 2019-06-13
"""
import json
import functools

from dazzler.components import core
from dazzler.system import Page, Trigger, BindingContext

page = Page(
    __name__,
    core.Container([
        core.Html('button', 'click me', events=['click'], identity='click'),
        core.Html('input', events=['focus', 'blur'], identity='focus'),
        core.Html('div',
                  'mouse',
                  events=[
                      'mouseup', 'mouseenter', 'mouseleave', 'mousedown',
                      'mouseover'
                  ],
                  identity='mouse'),
        core.Container(identity='click-output'),
        core.Container(identity='focus-output'),
        core.Container(identity='mouse-output'),
    ]))


async def on_event(ctx: BindingContext, output=''):
    await ctx.set_aspect(output, children=json.dumps(ctx.trigger.value))