Exemplo n.º 1
0
    def test_can_walk(self):
        elem = div([h1('title'), p('title')])
        items = list(elem.walk())
        assert len(items) == 5

        elem = div([h1('title'), 'title'])
        assert len(list(elem.walk())) == 4
Exemplo n.º 2
0
def popup_content(title, text, action, **kwargs):
    """
    Content of a pop-up window.
    """
    return div(**kwargs)[h1(title), p(text), action].add_class(
        "PopupWindow", first=True
    )
Exemplo n.º 3
0
def popup(title, content, action=None, **kwargs):
    """
    Return a popup screen.

    It does not include positioning and the overlay element.

    Args:
        title: Title of the popup.
        content: HTML or text content of the popup.
        action: Action button. Can be an anchor or other element.
    """
    return div(
        [
            icon("times-circle",
                 class_="popup__close",
                 is_component="popup:close"),
            div(
                [
                    h1([title], class_="title"),
                    p(content), action and div(action)
                ],
                class_="popup__contents",
            ),
        ],
        **kwargs,
    ).add_class("popup")
Exemplo n.º 4
0
def extra_content(title, text, icon=None, **kwargs):
    """
    Simple element with a title and a small paragraph with information.

    Used, for instance, in the detail page of conversations to link the
    comment form or cluster information.

    Args:
        title: Title of the content
        text: Paragraph that follows content.
        icon: Optional icon to be included with title element.

    Returns:

    """
    title = h1([_icon(icon), title]) if icon else h1(title)
    return div([title, text], **kwargs).add_class("extra-content")
Exemplo n.º 5
0
def role_model(model):
    links = []
    cls = get_class(model)
    for role in get_roles(cls):
        href = reverse("role-model-list", kwargs={"model": model, "role": role})
        links.append(a(role, href=href))

    if not links:
        raise Http404
    else:
        return {"data": div([h1(_("List of roles")), html_list(links)])}
Exemplo n.º 6
0
def intro(title, description=None, **kwargs):
    """
    Display a centered title with a small description paragraph.

    This content is wrapped into a div that centers the content into the main
    page layout.
    """
    children = [h1(title)]
    if description:
        children.append(p(description))
    return div(children, **kwargs).add_class("intro-paragraph", first=True)
Exemplo n.º 7
0
def toast(icon, title, description=None, **kwargs):
    """
    Toast component: display some title with a highlighted icon.
    """
    body = [h1(title)]
    if description:
        body.append(p(description))
    return div([
        _icon(icon, class_="toast__icon"),
        div(body, class_="toast__content")
    ], **kwargs).add_class("toast")
Exemplo n.º 8
0
def paragraph(title, description=None, **kwargs):
    """
    Display a centered title with a small description paragraph.

    This content is wrapped into a div that centers the content into the main
    page layout.
    """
    children = [h1(title, class_='Paragraph-title')]
    if description:
        children.append(p(description, class_='Paragraph-text'))
    return div(children, **kwargs).add_class('Paragraph', first=True)
Exemplo n.º 9
0
def role_model(model):
    links = []
    cls = get_class(model)
    for role in get_roles(cls):
        href = reverse('role-model-list',
                       kwargs={'model': model, 'role': role})
        links.append(a(role, href=href))

    if not links:
        raise Http404
    else:
        return {'data': div([h1(_('List of roles')), html_list(links)])}
Exemplo n.º 10
0
def test_json_conversion():
    tag = div(class_='foo')[h1('bar'), safe('foo <b>bar</b>')]
    pprint(tag.json())
    assert tag.json() == {
        'tag':
        'div',
        'attrs': {
            'class': ['foo']
        },
        'children': [
            {
                'tag': 'h1',
                'children': [{
                    'text': 'bar'
                }]
            },
            {
                'raw': 'foo <b>bar</b>'
            },
        ]
    }
Exemplo n.º 11
0
    def test_can_walk_in_tags(self):
        elem = div([h1('title'), p('title')])
        assert len(list(elem.walk_tags())) == 3

        elem = div([h1('title'), 'title'])
        assert len(list(elem.walk_tags())) == 2
Exemplo n.º 12
0
def test_nested_tags():
    tag = div(class_='title')[h1('foobar'), a('bar', href='foo/')]
    html = tag.render()
    assert html == '<div class="title"><h1>foobar</h1><a href="foo/">bar</a></div>'