• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python html.HTML类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webhelpers2.html.HTML的典型用法代码示例。如果您正苦于以下问题:Python HTML类的具体用法?Python HTML怎么用?Python HTML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HTML类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: radio

def radio(name, value, checked=False, label=None, **attrs):
    """Create a radio button.

    Arguments:
    ``name`` -- the field's name.

    ``value`` -- the value returned to the application if the button is
    pressed.

    ``checked`` -- true if the button should be initially pressed.

    ``label`` -- a text label to display to the right of the button.
    
    The id of the radio button will be set to the name + '_' + value to 
    ensure its uniqueness.  An ``id`` keyword arg overrides this.  (Note
    that this behavior is unique to the ``radio()`` helper.)
    
    To arrange multiple radio buttons in a group, see
    webhelpers2.containers.distribute().
    """
    _set_input_attrs(attrs, "radio", name, value)
    if checked:
        attrs["checked"] = "checked"
    if not "id" in attrs:
        attrs["id"] = '%s_%s' % (name, _make_safe_id_component(value))
    widget = HTML.input(**attrs)
    if label:
        widget = HTML.label(widget, label)
    return widget
开发者ID:aodag,项目名称:WebHelpers2,代码行数:29,代码来源:tags.py


示例2: test_boolean_true

 def test_boolean_true(self):
     a = {"defer": True, "disabled": "1", "multiple": 1, 
         "readonly": "readonly"}
     b = {"defer": "defer", "disabled": "disabled", "multiple": "multiple",
         "readonly": "readonly"}
     HTML.optimize_attrs(a)
     assert a == b
开发者ID:jManji,项目名称:Trivia,代码行数:7,代码来源:test_html.py


示例3: test_unclosed_tag

def test_unclosed_tag():
    result = HTML.form(_closed=False)
    print result
    eq_(u'<form>', result)
    
    result = HTML.form(_closed=False, action="hello")
    eq_(u'<form action="hello">', result)
开发者ID:aodag,项目名称:WebHelpers2,代码行数:7,代码来源:test_html.py


示例4: table_totals

    def table_totals(self, rownum, record, label, numrecords):
        row_hah = self.table_tr_styler(rownum, record)
        row_hah.class_ += 'totals'

        # get the <td>s for this row
        cells = []
        colspan = 0
        firstcol = True
        for col in self.grid.iter_columns('html'):
            if col.key not in list(self.grid.subtotal_cols.keys()):
                if firstcol:
                    colspan += 1
                else:
                    cells.append(_HTML.td(literal('&nbsp;')))
                continue
            if firstcol:
                bufferval = ngettext('{label} ({num} record):',
                                     '{label} ({num} records):',
                                     numrecords,
                                     label=label)
                buffer_hah = HTMLAttributes(
                    colspan=colspan,
                    class_='totals-label'
                )
                if colspan:
                    cells.append(_HTML.td(bufferval, **buffer_hah))
                firstcol = False
                colspan = 0
            cells.append(self.table_td(col, record))

        return self.table_tr_output(cells, row_hah)
开发者ID:level12,项目名称:webgrid,代码行数:31,代码来源:renderers.py


示例5: form

def form(url, method="post", multipart=False, hidden_fields=None, **attrs):
    """An open tag for a form that will submit to ``url``.

    You must close the form yourself by calling ``end_form()`` or outputting
    </form>.
    
    Options:

    ``method``
        The method to use when submitting the form, usually either 
        "GET" or "POST". If "PUT", "DELETE", or another verb is used, a
        hidden input with name _method is added to simulate the verb
        over POST.
    
    ``multipart``
        If set to True, the enctype is set to "multipart/form-data".
        You must set it to true when uploading files, or the browser will
        submit the filename rather than the file.

    ``hidden_fields``
        Additional hidden fields to add to the beginning of the form.  It may
        be a dict or an iterable of key-value tuples. This is implemented by
        calling the object's ``.items()`` method if it has one, or just
        iterating the object.  (This will successfuly get multiple values for
        the same key in WebOb MultiDict objects.)

    Because input tags must be placed in a block tag rather than directly
    inside the form, all hidden fields will be put in a 
    '<div style="display:none">'.  The style prevents the <div> from being
    displayed or affecting the layout.

    Changed in WebHelpers 1.0b2: add <div> and ``hidden_fields`` arg.

    Changed in WebHelpers 1.2: don't add an "id" attribute to hidden tags
    generated by this helper; they clash if there are multiple forms on the
    page.
    """
    fields = []
    attrs["action"] = url
    if multipart:
        attrs["enctype"] = "multipart/form-data"
    if method.lower() in ['post', 'get']:
        attrs['method'] = method
    else:
        attrs['method'] = "post"
        field = hidden("_method", method, id=None)
        fields.append(field)
    if hidden_fields is not None:
        try:
            it = hidden_fields.items()
        except AttributeError:
            it = hidden_fields
        for name, value in it:
            field = hidden(name, value, id=None)
            fields.append(field)
    if fields:
        div = HTML.tag("div", style="display:none", _nl=True, *fields)
    else:
        div = None
    return HTML.tag("form", div, _closed=False, **attrs)
开发者ID:smurfix,项目名称:WebHelpers2,代码行数:60,代码来源:tags.py


示例6: error_container

def error_container(name, as_text=False):
    return HTML.tag(
        'span',
        class_='error %s hidden'
        % ('fa fa-arrow-circle-down as-text' if as_text else 'fa fa-exclamation-circle'),
        c=HTML.tag('span'),
        **{'data-name': name}
    )
开发者ID:mazvv,项目名称:travelcrm,代码行数:8,代码来源:common.py


示例7: _list

def _list(tag, items, default, attrs, li_attrs):
    content = [HTML.tag("li", x, **li_attrs) for x in items]
    if content:
        content = [""] + content + [""]
    elif default is not None:
        return default
    content = literal("\n").join(content)
    return HTML.tag(tag, content, **attrs)
开发者ID:jManji,项目名称:Trivia,代码行数:8,代码来源:tags.py


示例8: test_html

 def test_html(self):
     a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
     assert a == '<a href="http://mostlysafe&#34; &lt;tag">Bad &lt;script&gt; tag</a>'
     
     img = HTML.img(src="http://some/image.jpg")
     assert img == '<img src="http://some/image.jpg" />'
     
     br = HTML.br()
     assert "<br />" == br
开发者ID:jManji,项目名称:Trivia,代码行数:9,代码来源:test_html.py


示例9: contact_type_icon

def contact_type_icon(contact_type):
    assert contact_type.key in (u'phone', u'email', u'skype'), \
        u"wrong contact type"
    if contact_type.key == u'phone':
        return HTML.tag('span', class_='fa fa-phone')
    elif contact_type.key == u'email':
        return HTML.tag('span', class_='fa fa-envelope')
    else:
        return HTML.tag('span', class_='fa fa-skype')
开发者ID:mazvv,项目名称:travelcrm,代码行数:9,代码来源:common.py


示例10: test_html

def test_html():
    a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
    eq_(a, u'<a href="http://mostlysafe&#34; &lt;tag">Bad &lt;script&gt; tag</a>')
    
    img = HTML.img(src='http://some/image.jpg')
    eq_(img, u'<img src="http://some/image.jpg" />')
    
    br = HTML.br()
    eq_(u'<br />', br)
开发者ID:aodag,项目名称:WebHelpers2,代码行数:9,代码来源:test_html.py


示例11: options_td

 def options_td(col_num, i, item):
     href = self.request.route_url(
         "admin_object", object="users", object_id=item.id, verb="GET"
     )
     edit_link = HTML.a(translate(_("Edit")), class_="btn btn-info", href=href)
     delete_href = self.request.route_url(
         "admin_object", object="users", object_id=item.id, verb="DELETE"
     )
     delete_link = HTML.a(
         translate(_("Delete")), class_="btn btn-danger", href=delete_href
     )
     return HTML.td(edit_link, " ", delete_link, class_="c{}".format(col_num))
开发者ID:ergo,项目名称:testscaffold,代码行数:12,代码来源:grids.py


示例12: _render

 def _render(self, options, selected_values):
     tags = []
     for opt in options:
         if isinstance(opt, OptGroup):
             content = self._render(opt, selected_values)
             tag = HTML.tag("optgroup", NL, content, label=opt.label)
             tags.append(tag)
         else:
             value = opt.value if opt.value is not None else opt.label
             selected = value in selected_values
             tag = HTML.tag("option", opt.label, value=opt.value,
                 selected=selected)
             tags.append(tag)
     return HTML(*tags, nl=True)
开发者ID:jManji,项目名称:Trivia,代码行数:14,代码来源:tags.py


示例13: js_obfuscate

def js_obfuscate(content):
    """Obfuscate data in a Javascript tag.
    
    Example::
        
        >>> js_obfuscate("<input type='hidden' name='check' value='valid' />")
        literal(u'<script type="text/javascript">\\n//<![CDATA[\\neval(unescape(\\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%69%6e%70%75%74%20%74%79%70%65%3d%27%68%69%64%64%65%6e%27%20%6e%61%6d%65%3d%27%63%68%65%63%6b%27%20%76%61%6c%75%65%3d%27%76%61%6c%69%64%27%20%2f%3e%27%29%3b\\'))\\n//]]>\\n</script>')
        
    """
    doc_write = "document.write('%s');" % content
    obfuscated = ''.join(['%%%x' % ord(x) for x in doc_write])
    complete = "eval(unescape('%s'))" % obfuscated
    cdata = HTML.cdata("\n", complete, "\n//")
    return HTML.script("\n//", cdata, "\n", type="text/javascript")
开发者ID:aodag,项目名称:WebHelpers2,代码行数:14,代码来源:tools.py


示例14: button

def button(context, permision, caption, **kwargs):
    html = ''
    if context.has_permision(permision):
        caption = HTML.tag('span', c=caption)
        icon = ''
        if 'icon' in kwargs:
            icon = HTML.tag('span', class_=kwargs.pop('icon'))
        button_class = "button _action " + kwargs.pop('class', '')
        button_class = button_class.strip()
        html = HTML.tag(
            'a', class_=button_class,
            c=HTML(icon, caption), **kwargs
        )
    return html
开发者ID:mazvv,项目名称:travelcrm,代码行数:14,代码来源:common.py


示例15: title

def title(title, required=False, label_for=None):
    """Format the user-visible title for a form field.

    Use this for forms that have a text title above or next to each
    field.

    ``title`` -- the name of the field; e.g., "First Name".

    ``required`` -- if true, append a \*" to the title and use the
    'required' HTML format (see example); otherwise use the 'not
    required' format.

    ``label_for`` -- if provided, put ``<label for="ID">`` around the
    title.  The value should be the HTML ID of the input field related
    to this title.  Per the HTML standard, the ID should point to a
    single control (input, select, textarea), not to multiple controls
    (fieldset, group of checkboxes, group of radio buttons).  ID's are
    set by passing the keyword arg ``id`` to the appropriate helper.
    
    Note that checkboxes and radio buttions typically have their own
    individual labels in addition to the title.  You can set these with
    the ``label`` argument to ``checkbox()`` and ``radio()``.

    This helper does not accept other keyword arguments.

    See webhepers2/static/stylesheets/webhelpers2.css for suggested styles.

    >>> title("First Name")
    literal(u'<span class="not-required">First Name</span>')
    >>> title("Last Name", True)
    literal(u'<span class="required">Last Name <span class="required-symbol">*</span></span>')
    >>> title("First Name", False, "fname")
    literal(u'<span class="not-required"><label for="fname">First Name</label></span>')
    >>> title("Last Name", True, label_for="lname")
    literal(u'<span class="required"><label for="lname">Last Name</label> <span class="required-symbol">*</span></span>')
    """
    title_html = title
    required_html = literal("")
    if label_for:
        title_html = HTML.label(title_html, for_=label_for)
    if required:
        required_symbol = HTML.span("*", class_="required-symbol")
        return HTML.span(
            title_html, 
            " ",
            required_symbol,
            class_="required")
    else:
        return HTML.span(title_html, class_="not-required")
开发者ID:aodag,项目名称:WebHelpers2,代码行数:49,代码来源:tags.py


示例16: th_sortable

def th_sortable(current_order, column_order, label, url,
    class_if_sort_column="sort", class_if_not_sort_column=None, 
    link_attrs=None, name="th", **attrs):
    """<th> for a "click-to-sort-by" column.

    Convenience function for a sortable column.  If this is the current sort
    column, just display the label and set the cell's class to
    ``class_if_sort_column``.
    
    ``current_order`` is the table's current sort order.  ``column_order`` is
    the value pertaining to this column.  In other words, if the two are equal,
    the table is currently sorted by this column.

    If this is the sort column, display the label and set the <th>'s class to
    ``class_if_sort_column``.

    If this is not the sort column, display an <a> hyperlink based on
    ``label``, ``url``, and ``link_attrs`` (a dict), and set the <th>'s class
    to ``class_if_not_sort_column``.  
    
    ``url`` is the literal href= value for the link.  Pylons users would
    typically pass something like ``url=h.url_for("mypage", sort="date")``.

    ``**attrs`` are additional attributes for the <th> tag.

    If you prefer a <td> tag instead of <th>, pass ``name="td"``.

    To change the sort order via client-side Javascript, pass ``url=None`` and
    the appropriate Javascript attributes in ``link_attrs``.

    Examples:

    >>> sort = "name"
    >>> th_sortable(sort, "name", "Name", "?sort=name")
    literal(u'<th class="sort">Name</th>')
    >>> th_sortable(sort, "date", "Date", "?sort=date")
    literal(u'<th><a href="?sort=date">Date</a></th>')
    >>> th_sortable(sort, "date", "Date", None, link_attrs={"onclick": "myfunc()"})
    literal(u'<th><a onclick="myfunc()">Date</a></th>')
    """
    from webhelpers2.html import HTML
    if current_order == column_order:
        content = label
        class_ = class_if_sort_column
    else:
        link_attrs = link_attrs or {}
        content = HTML.tag("a", label, href=url, **link_attrs)
        class_ = class_if_not_sort_column
    return HTML.tag("th", content, class_=class_, **attrs)
开发者ID:lxrave,项目名称:WebHelpers2,代码行数:49,代码来源:tags.py


示例17: stylesheet_link

def stylesheet_link(*urls, **attrs):
    """Return CSS link tags for the specified stylesheet URLs.

    ``urls`` should be the exact URLs desired.  A previous version of this
    helper added magic prefixes; this is no longer the case.

    Examples::

        >>> stylesheet_link('/stylesheets/style.css')
        literal(u'<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />')

        >>> stylesheet_link('/stylesheets/dir/file.css', media='all')
        literal(u'<link href="/stylesheets/dir/file.css" media="all" rel="stylesheet" type="text/css" />')

    """
    if "href" in attrs:
        raise TypeError("keyword arg 'href' not allowed")
    attrs.setdefault("rel", "stylesheet")
    attrs.setdefault("type", "text/css")
    attrs.setdefault("media", "screen")
    tags = []
    for url in urls:
        tag = HTML.tag("link", href=url, **attrs)
        tags.append(tag)
    return literal('\n').join(tags)
开发者ID:lxrave,项目名称:WebHelpers2,代码行数:25,代码来源:tags.py


示例18: date_field

def date_field(name, value=None, data_options=None, **kwargs):
    id = gen_id()
    format = get_date_format()
    
    # this hack is need for datebox correct working
    format = format.replace('yy', 'yyyy')

    _data_options = """
        editable:false,
        formatter:function(date){return dt_formatter(date, %s);},
        parser:function(s){return dt_parser(s, %s);}
        """ % (
       jsonify(format),
       jsonify(format)
    )
    if data_options:
        _data_options += ",%s" % data_options
    if value:
        value = format_date(value, format)
    html = tags.text(
        name, value, class_="easyui-datebox text w10",
        id=id, data_options=_data_options, **kwargs
    )
    return html + HTML.literal("""
        <script type="text/javascript">
            add_datebox_clear_btn("#%s");
        </script>
    """) % id
开发者ID:mazvv,项目名称:travelcrm,代码行数:28,代码来源:fields.py


示例19: javascript_link

def javascript_link(*urls, **attrs):
    """Return script include tags for the specified javascript URLs.
    
    ``urls`` should be the exact URLs desired.  A previous version of this
    helper added magic prefixes; this is no longer the case.

    Specify the keyword argument ``defer=True`` to enable the script 
    defer attribute.

    Examples::
    
        >>> print javascript_link('/javascripts/prototype.js', '/other-javascripts/util.js')
        <script src="/javascripts/prototype.js" type="text/javascript"></script>
        <script src="/other-javascripts/util.js" type="text/javascript"></script>

        >>> print javascript_link('/app.js', '/test/test.1.js')
        <script src="/app.js" type="text/javascript"></script>
        <script src="/test/test.1.js" type="text/javascript"></script>
        
    """
    tags = []
    for url in urls:
        tag = HTML.tag("script", "", type="text/javascript", src=url, **attrs)
        tags.append(tag)
    return literal("\n").join(tags)
开发者ID:lxrave,项目名称:WebHelpers2,代码行数:25,代码来源:tags.py


示例20: _input

def _input(type, name, value, id, attrs):
    """Finish rendering an input tag."""
    attrs["type"] = type
    attrs["name"] = name
    attrs["value"] = value
    _set_id_attr(attrs, id, name)
    return HTML.tag("input", **attrs)
开发者ID:jManji,项目名称:Trivia,代码行数:7,代码来源:tags.py



注:本文中的webhelpers2.html.HTML类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python terraform_runner.TerraformRunner类代码示例发布时间:2022-05-26
下一篇:
Python html.literal函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap