Beispiel #1
0
def format_profile(self, request, obj, fieldname, *args, **kwargs):
    """IF user has a profile page return a link to it"""
    existing_profile = current_app.db.index.find_one(
        {'content_type': 'block', 'slug': slugify(obj.get('fullname'))}
    )
    if existing_profile:
        edit_url = url_for(
            'quokka.core.content.admin.blockview.edit_view',
            id=existing_profile['_id']
        )
        view_url = url_for(
            'quokka.core.content.author',
            author=existing_profile['slug']
        )
        edit_link = html.a(href=edit_url, target='_blank')(
            html.i(class_="icon fa fa-pencil glyphicon glyphicon-pencil",
                   style="margin-right: 5px;")(),
            'Edit Profile'
        )
        view_link = html.a(href=view_url, target='_blank')(
            html.i(class_="icon fa fa-globe glyphicon glyphicon-globe",
                   style="margin-right: 5px;")(),
            'View Profile'
        )
        return html.div()(
            html.span()(edit_link),
            Markup(' '),
            html.span()(view_link)
        )
Beispiel #2
0
def format_link(self, request, obj, fieldname, *args, **kwars):
    """Format a link from the model"""
    model = make_model(obj)
    value = getattr(model, fieldname)
    return html.a(href=value, title=value,
                  target='_blank')(html.i(class_="icon  icon-resize-small",
                                          style="margin-right: 5px;")())
Beispiel #3
0
def format_link(self, request, obj, fieldname, *args, **kwars):
    """Format a link from the model"""
    model = make_model(obj)
    value = getattr(model, fieldname)
    return html.a(href=value, title=value, target='_blank')(
        html.i(class_="icon  icon-resize-small",
               style="margin-right: 5px;")()
    )
Beispiel #4
0
def test_markup():
    assert Markup(html.a(name='value')(html.b(first='one'), 'Text', html.c())) == '<a name="value"><b first="one" />Text<c></c></a>'
    assert Markup(html.p(html.comment('Comment'))) == '<p><!--Comment--></p>'
    assert Markup(html.p(html.safe('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert Markup(html.safe('<strong>&nbsp;Text&nbsp;</strong>')) == '<strong>&nbsp;Text&nbsp;</strong>'

    assert rn(html.p(Markup('<strong>&nbsp;Text&nbsp;</strong>'))) == '<p><strong>&nbsp;Text&nbsp;</strong></p>'
    assert rn(html.p(Markup('&nbsp; '), Markup('<strong>One</strong>'))) == '<p>&nbsp; <strong>One</strong></p>'
    assert render(html.p(Markup('&nbsp; '), Markup('<strong>One</strong>'))) == u'<p>\n  &nbsp; \n  <strong>One</strong>\n</p>\n'
Beispiel #5
0
def format_view_on_site(self, request, obj, fieldname, *args, **kwargs):
    """Returns button to view or preview depending on content status"""
    model = make_model(obj)
    return html.a(
        href=model.external_url,
        target='_blank',
    )(html.i(class_="icon fa fa-globe glyphicon glyphicon-globe",
             style="margin-right: 5px;")(),
      'View' if model.published else 'Preview')
Beispiel #6
0
def view_on_site(self, request, obj, fieldname, *args, **kwargs):
    available = obj.is_available
    endpoint = kwargs.pop(
        'endpoint',
        'flaskpress.core.detail' if available else 'flaskpress.core.preview')
    return html.a(
        href=obj.get_absolute_url(endpoint),
        target='_blank',
    )(html.i(class_="icon icon-eye-open", style="margin-right: 5px;")(),
      _l('View on site') if available else _l('Preview on site'))
Beispiel #7
0
def view_on_site(self, request, obj, fieldname, *args, **kwargs):
    available = obj.is_available
    endpoint = kwargs.pop(
        'endpoint',
        'quokka.core.detail' if available else 'quokka.core.preview'
    )
    return html.a(
        href=obj.get_absolute_url(endpoint),
        target='_blank',
    )(html.i(class_="icon icon-eye-open", style="margin-right: 5px;")(),
      _l('View on site') if available else _l('Preview on site'))
Beispiel #8
0
def get_url(self, request, obj, fieldname, *args, **kwargs):
    column_formatters_args = getattr(self, 'column_formatters_args', {})
    _args = column_formatters_args.get('get_url', {}).get(fieldname, {})
    attribute = _args.get('attribute')
    method = _args.get('method', 'get_absolute_url')
    text = getattr(obj, fieldname, '')
    if attribute:
        target = getattr(obj, attribute, None)
    else:
        target = obj

    url = getattr(target, method, lambda: '#')()

    return html.a(href=url)(text if text not in [None, 'None'] else '')
Beispiel #9
0
def get_url(self, request, obj, fieldname, *args, **kwargs):
    column_formatters_args = getattr(self, 'column_formatters_args', {})
    _args = column_formatters_args.get('get_url', {}).get(fieldname, {})
    attribute = _args.get('attribute')
    method = _args.get('method', 'get_absolute_url')
    text = getattr(obj, fieldname, '')
    if attribute:
        target = getattr(obj, attribute, None)
    else:
        target = obj

    url = getattr(target, method, lambda: '#')()

    return html.a(href=url)(text if text not in [None, 'None'] else '')
Beispiel #10
0
def format_url(self, request, obj, fieldname, *args, **kwargs):
    """Get the url of a content object"""
    column_formatters_args = getattr(self, 'column_formatters_args', {})
    _args = column_formatters_args.get('get_url', {}).get(fieldname, {})
    attribute = _args.get('attribute', 'url')
    method = _args.get('method', 'url')
    model = make_model(obj)
    text = getattr(model, fieldname, '')
    if attribute:
        target = getattr(model, attribute, None)
    else:
        target = model

    url = getattr(target, method, lambda: '#')()

    return html.a(href=url)(text if text not in [None, 'None'] else '')
Beispiel #11
0
def test_escape_numbers():
    render(html.a(5))
Beispiel #12
0
def test_unicode_attribute_values():
    assert rn(html.a(chars=u'\u03a0\u03a3\u03a9')) == u'<a chars="\u03a0\u03a3\u03a9" />'
Beispiel #13
0
def test_multiple_attribute():
    result = rn(html.a(first='one', second='two'))
    assert result in ['<a first="one" second="two" />', '<a second="two" first="one" />']
Beispiel #14
0
def test_python_keyword_unmangling():
    assert rn(html.a(class_='value')) == '<a class="value" />'
    assert rn(html.a(else_='value')) == '<a else="value" />'
    assert rn(html.a(id_='value')) == '<a id-="value" />'

    assert rn(html.del_('Text')) == '<del>Text</del>'
Beispiel #15
0
def test_many_child_indenting():
    assert render(html.a(name='value')(html.b(first='one'), 'Text', html.c())) == '<a name="value">\n  <b first="one" />\n  Text\n  <c></c>\n</a>\n'
Beispiel #16
0
def test_render_level():
    assert render(html.p(html.a('Text')), level=1) == '  <p>\n    <a>Text</a>\n  </p>\n'
    assert render(html.p(html.a('Text')), level=2) == '    <p>\n      <a>Text</a>\n    </p>\n'
Beispiel #17
0
def format_link(self, request, obj, fieldname, *args, **kwars):
    value = getattr(obj, fieldname)
    return html.a(href=value, title=value, target='_blank')(
        html.i(class_="icon  icon-resize-small",
               style="margin-right: 5px;")()
    )
Beispiel #18
0
def test_text_escaping():
    assert rn(html.a('aaa<aaa"aaa&nbsp;aaa>')) == '<a>aaa&lt;aaa"aaa&amp;nbsp;aaa&gt;</a>'
Beispiel #19
0
def test_single_element_indenting():
    assert render(html.a) == '<a />\n'
    assert render(html.a()) == '<a></a>\n'
    assert render(html.a(name='value')) == '<a name="value" />\n'
    assert render(html.a(name='value')()) == '<a name="value"></a>\n'
Beispiel #20
0
def test_one_text_child():
    assert rn(html.a(name='value')('Text')) == '<a name="value">Text</a>'
    assert rn(html.a('Text')) == '<a>Text</a>'
Beispiel #21
0
def test_none_attribute_values():
    assert rn(html.a(id=None)) == u'<a />'
    assert rn(html.a(a=None, b='b', c=None)) == u'<a b="b" />'
Beispiel #22
0
def test_empty_children():
    assert rn(html.a(name='value')()) == '<a name="value"></a>'
    assert rn(html.a()) == '<a></a>'
Beispiel #23
0
def test_void_elements():
    assert rn(html.a(name='value')) == '<a name="value" />'
    assert rn(html.a) == '<a />'
Beispiel #24
0
def test_attribute_value_escaping():
    assert rn(html.a(chars='<"&>')) == '<a chars="&lt;&quot;&amp;&gt;" />'
Beispiel #25
0
def format_link(self, request, obj, fieldname, *args, **kwars):
    value = getattr(obj, fieldname)
    return html.a(href=value, title=value,
                  target='_blank')(html.i(class_="icon  icon-resize-small",
                                          style="margin-right: 5px;")())
Beispiel #26
0
def test_one_text_child_indenting():
    assert render(html.a(name='value')('Text')) == '<a name="value">Text</a>\n'
    assert render(html.a('Text')) == '<a>Text</a>\n'
Beispiel #27
0
def test_escape_attribute_numbers():
    render(html.a(x=5))
Beispiel #28
0
def test_one_non_text_child_indenting():
    assert render(html.a(html.b)) == '<a>\n  <b />\n</a>\n'
Beispiel #29
0
def test_single_attribute():
    assert rn(html.a(name='value')) == '<a name="value" />'
Beispiel #30
0
def test_many_text_child_indenting():
    assert render(html.a('One', 'Two')) == '<a>\n  One\n  Two\n</a>\n'
Beispiel #31
0
def test_many_children():
    assert rn(html.a(name='value')(html.b(first='one'), 'Text', html.c())) == '<a name="value"><b first="one" />Text<c></c></a>'
Beispiel #32
0
def test_colon_unmangling():
    assert rn(html.a(first__second='value')) == '<a first:second="value" />'
Beispiel #33
0
def test_nesting():
    assert rn(html.a(name='value')(html.b('Text'), html.c(html.d, html.e()))) == '<a name="value"><b>Text</b><c><d /><e></e></c></a>'
Beispiel #34
0
def test_unicode_text():
    assert rn(html.a(u'\u03a0\u03a3\u03a9')) == u'<a>\u03a0\u03a3\u03a9</a>'