本文整理汇总了Python中webhelpers.html.HTML类的典型用法代码示例。如果您正苦于以下问题:Python HTML类的具体用法?Python HTML怎么用?Python HTML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
webhelpers.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
示例2: get_audio_tag
def get_audio_tag(self, request):
from webhelpers.html import HTML
static_path = self.get_static_path(request)
source_tag = HTML.tag('source', type_='audio/mp3', src=static_path)
audio_tag = HTML.tag('audio', controls='controls', c=[source_tag])
div_tag = HTML.tag('div', class_='mp3', c=[audio_tag])
return div_tag
示例3: 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}
)
示例4: _get_update_details
def _get_update_details(self, update):
details = ''
if update['status'] == 'stable':
if update.get('updateid'):
details += HTML.tag('a', c=update['updateid'], href='%s/%s' % (
self._prod_url, update['updateid']))
if update.get('date_pushed'):
details += HTML.tag('br') + update['date_pushed']
else:
details += 'In process...'
elif update['status'] == 'pending' and update.get('request'):
details += 'Pending push to %s' % update['request']
details += HTML.tag('br')
details += HTML.tag('a', c="View update details >",
href="%s/%s" % (self._prod_url,
update['title']))
elif update['status'] == 'obsolete':
for comment in update['comments']:
if comment['author'] == 'bodhi':
if comment['text'].startswith('This update has been '
'obsoleted by '):
details += \
'Obsoleted by %s' % HTML.tag(
'a', href='%s/%s' % (
self._prod_url, update['title']),
c=comment['text'].split()[-1])
return details
示例5: 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)
示例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}
)
示例7: _pagerlink
def _pagerlink(self, page, text):
# Let the url_for() from webhelpers create a new link and set
# the variable called 'page_param'. Example:
# You are in '/foo/bar' (controller='foo', action='bar')
# and you want to add a parameter 'page'. Then you
# call the navigator method with page_param='page' and
# the url_for() call will create a link '/foo/bar?page=...'
# with the respective page number added.
link_params = {}
# Use the instance kwargs from Page.__init__ as URL parameters
link_params.update(self.kwargs)
# Add keyword arguments from pager() to the link as parameters
link_params.update(self.pager_kwargs)
link_params[self.page_param] = page
# Get the URL generator
if self._url_generator is not None:
url_generator = self._url_generator
else:
try:
import pylons
url_generator = pylons.url.current
except (ImportError, AttributeError):
try:
import routes
url_generator = routes.url_for
config = routes.request_config()
except (ImportError, AttributeError):
raise NotImplementedError("no URL generator available")
else:
# if the Mapper is configured with explicit=True we have to fetch
# the controller and action manually
if config.mapper.explicit:
if hasattr(config, 'mapper_dict'):
for k, v in config.mapper_dict.items():
if k != self.page_param:
link_params[k] = v
# Create the URL to load a certain page
link_url = url_generator(**link_params)
if self.onclick: # create link with onclick action for AJAX
# Create the URL to load the page area part of a certain page (AJAX
# updates)
link_params[self.partial_param] = 1
partial_url = url_generator(**link_params)
try: # if '%s' is used in the 'onclick' parameter (backwards compatibility)
onclick_action = self.onclick % (partial_url,)
except TypeError:
onclick_action = Template(self.onclick).safe_substitute({
"partial_url": partial_url,
"page": page
})
a_tag = HTML.a(text, href=link_url, onclick=onclick_action, **self.link_attr)
else: # return static link
a_tag = HTML.a(text, href=link_url, **self.link_attr)
li_tag = HTML.li(a_tag)
return li_tag
示例8: 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')
示例9: input_submit_text_button
def input_submit_text_button(text=None, name=None, **html_options):
if text is None:
from pylons.i18n import _
text = _('Save')
if name is not None:
html_options['name'] = name
html_options.setdefault('class_', "btn-text")
html_options.setdefault('value', text)
return HTML.button(c=[HTML.span(text)], **html_options)
示例10: test_html
def test_html():
a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
eq_(a,
u'<a href="http://mostlysafe" <tag">Bad <script> 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)
示例11: _range
def _range(self, regexp_match):
html = super(Page, self)._range(regexp_match)
# Convert ..
dotdot = "\.\."
dotdot_link = HTML.li(HTML.a("...", href="#"), class_="disabled")
html = re.sub(dotdot, dotdot_link, html)
# Convert current page
text = "%s" % self.page
current_page_span = str(HTML.span(c=text, **self.curpage_attr))
current_page_link = self._pagerlink(self.page, text, extra_attributes=self.curpage_attr)
return re.sub(current_page_span, current_page_link, html)
示例12: sa_learned
def sa_learned(value):
"indicate learning status"
if not value:
HTML.span(_('N'), class_='negative')
match = LEARN_RE.search(value)
if match:
return (HTML.span(_('Y'), class_='positive') +
literal(' ') + '(%s)' % escape(match.group(1)))
else:
return HTML.span(_('N'), class_='negative')
示例13: 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
示例14: boolicon
def boolicon(value):
"""Returns boolean value of a value, represented as small html image of true/false
icons
:param value: value
"""
if value:
return HTML.tag('i', class_="icon-ok")
else:
return HTML.tag('i', class_="icon-minus-circled")
示例15: boolicon
def boolicon(value):
"""Returns boolean value of a value, represented as small html image of true/false
icons
:param value: value
"""
if value:
return HTML.tag('img', src=url("/images/icons/accept.png"),
alt=_('True'))
else:
return HTML.tag('img', src=url("/images/icons/cancel.png"),
alt=_('False'))