本文整理匯總了Python中webhelpers2.html.HTML.tag方法的典型用法代碼示例。如果您正苦於以下問題:Python HTML.tag方法的具體用法?Python HTML.tag怎麽用?Python HTML.tag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類webhelpers2.html.HTML
的用法示例。
在下文中一共展示了HTML.tag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: form
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例2: error_container
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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}
)
示例3: _list
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例4: contact_type_icon
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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')
示例5: _render
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例6: button
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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
示例7: th_sortable
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例8: _input
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例9: auto_discovery_link
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
def auto_discovery_link(url, feed_type="rss", **attrs):
"""Return a link tag allowing auto-detecting of RSS or ATOM feed.
The auto-detection of feed for the current page is only for
browsers and news readers that support it.
``url``
The URL of the feed. (This should be the exact URLs desired. A
previous version of this helper added magic prefixes; this is no longer
the case.)
``feed_type``
The type of feed. Specifying 'rss' or 'atom' automatically
translates to a type of 'application/rss+xml' or
'application/atom+xml', respectively. Otherwise the type is
used as specified. Defaults to 'rss'.
"""
if "href" in attrs:
raise TypeError("keyword arg 'href' is not allowed")
if "type" in attrs:
raise TypeError("keyword arg 'type' is not allowed")
title = ""
if feed_type.lower() in ('rss', 'atom'):
title = feed_type.upper()
feed_type = 'application/{0}+xml'.format(feed_type.lower())
attrs.setdefault("title", title)
return HTML.tag("link", rel="alternate", type=feed_type, href=url, **attrs)
示例10: stylesheet_link
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例11: javascript_link
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
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)
示例12: radio
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
def radio(name, value, checked=False, label=None, label_class=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.
This puts a <label> tag around the input tag.
``label_class`` -- CSS class for <label> tag. This should be a keyword
argument because its position may change in a future version.
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().
"""
if checked:
attrs["checked"] = "checked"
if not "id" in attrs:
attrs["id"] = "{0}_{1}".format(name, _make_safe_id_component(value))
# Pass None as 'id' arg to '_input()' to prevent further modification of
# the 'id' attribute.
widget = _input("radio", name, value, None, attrs)
if label:
widget = HTML.tag("label", widget, " ", label, class_=label_class)
return widget
示例13: image
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
def image(url, alt, width=None, height=None, **attrs):
"""Return an image tag for the specified ``source``.
``url``
The URL of the image. (This must be the exact URL desired. A
previous version of this helper added magic prefixes; this is
no longer the case.)
``alt``
The img's alt tag. Non-graphical browsers and screen readers will
output this instead of the image. If the image is pure decoration
and uninteresting to non-graphical users, pass "". To omit the
alt tag completely, pass None.
``width``
The width of the image, default is not included.
``height``
The height of the image, default is not included.
Note: This version does not support the 'path' and 'use_pil' arguments,
because they depended on the WebHelpers 'media' subpackage which was
dropped in WebHelpers 2.
"""
if "path" in attrs:
raise TypeError("the 'path' arg is not supported in WebHelpers2")
if "use_pil" in attrs:
raise TypeError("the 'use_pil' arg is not supported in WebHelpers2")
if not alt:
alt = ""
if width is not None or height is not None:
attrs['width'] = width
attrs['height'] = height
return HTML.tag("img", src=url, alt=alt, **attrs)
示例14: handle_match
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
def handle_match(matchobj):
all = matchobj.group()
before, prefix, link, after = matchobj.group(1, 2, 3, 4)
if re.match(r'<a\s', before, re.I):
return all
text = literal(prefix + link)
if prefix == "www.":
prefix = "http://www."
a_options = dict(href_attrs)
a_options['href'] = literal(prefix + link)
return literal(before) + HTML.tag("a", text, **a_options) + literal(after)
示例15: textarea
# 需要導入模塊: from webhelpers2.html import HTML [as 別名]
# 或者: from webhelpers2.html.HTML import tag [as 別名]
def textarea(name, content="", id=NotGiven, **attrs):
"""Create a text input area.
Example::
>>> textarea("body", "", cols=25, rows=10)
literal(u'<textarea cols="25" id="body" name="body" rows="10"></textarea>')
"""
attrs["name"] = name
_set_id_attr(attrs, id, name)
return HTML.tag("textarea", content, **attrs)