本文整理汇总了Python中webhelpers.html.HTML.span方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.span方法的具体用法?Python HTML.span怎么用?Python HTML.span使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.span方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sa_learned
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
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')
示例2: title
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
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 webhepers/public/stylesheets/webhelpers.css for suggested styles.
>>> title("First Name")
literal(%(u)s'<span class="not-required">First Name</span>')
>>> title("Last Name", True)
literal(%(u)s'<span class="required">Last Name <span class="required-symbol">*</span></span>')
>>> title("First Name", False, "fname")
literal(%(u)s'<span class="not-required"><label for="fname">First Name</label></span>')
>>> title("Last Name", True, label_for="lname")
literal(%(u)s'<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")
示例3: pager
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def pager(self, format='~2~', page_param='page', partial_param='partial',
show_if_single_page=False, separator=' ', onclick=None,
symbol_first='<<', symbol_last='>>',
symbol_previous='<', symbol_next='>',
link_attr={'class': 'pager_link', 'rel': 'prerender'},
curpage_attr={'class': 'pager_curpage'},
dotdot_attr={'class': 'pager_dotdot'}, **kwargs):
self.curpage_attr = curpage_attr
self.separator = separator
self.pager_kwargs = kwargs
self.page_param = page_param
self.partial_param = partial_param
self.onclick = onclick
self.link_attr = link_attr
self.dotdot_attr = dotdot_attr
# Don't show navigator if there is no more than one page
if self.page_count == 0 or (self.page_count == 1 and not show_if_single_page):
return ''
from string import Template
# Replace ~...~ in token format by range of pages
result = re.sub(r'~(\d+)~', self._range, format)
# Interpolate '%' variables
result = Template(result).safe_substitute({
'first_page': self.first_page,
'last_page': self.last_page,
'page': self.page,
'page_count': self.page_count,
'items_per_page': self.items_per_page,
'first_item': self.first_item,
'last_item': self.last_item,
'item_count': self.item_count,
'link_first': self.page > self.first_page and \
self._pagerlink(self.first_page, symbol_first) or '',
'link_last': self.page < self.last_page and \
self._pagerlink(self.last_page, symbol_last) or '',
'link_previous': self.previous_page and \
self._pagerlink(self.previous_page, symbol_previous) \
or HTML.span(symbol_previous, class_="yui-pg-previous"),
'link_next': self.next_page and \
self._pagerlink(self.next_page, symbol_next) \
or HTML.span(symbol_next, class_="yui-pg-next")
})
return literal(result)
示例4: input_area
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def input_area(name, title, value='', cols='50', rows='5', help_text=None, disabled=False, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
if disabled:
kwargs['disabled'] = 'disabled'
kwargs.setdefault('id', name)
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
HTML.textarea(name_=name, cols=cols, rows=rows, c=[value], **kwargs),
])]),
HTML.literal('<form:error name="%s" />' % name),
expl])
示例5: select_radio
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def select_radio(name, title, options, selected=[], help_text=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
radios = []
for value, label in options:
checked = value in selected
radios.append(radio(name, value, checked, label, **kwargs))
return HTML.div(class_='formField',
id='%s-field' % name,
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='radioField', c=radios)]),
HTML.literal('<form:error name="%s" />' % name),
expl])
示例6: input_submit_text_button
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
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)
示例7: input_line
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def input_line(name, title, value='', help_text=None, right_next=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
next = None
if right_next is not None:
next = HTML.span(class_='rightNext', c=right_next)
kwargs.setdefault('id', name)
kwargs.setdefault('type', 'text')
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
HTML.input(value=value, name_=name, **kwargs),
])]),
next,
HTML.literal('<form:error name="%s" />' % name),
expl])
示例8: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
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)
示例9: select_line
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def select_line(name, title, options, selected=[], help_text=None, right_next=None, **kwargs):
expl = None
if help_text is not None:
expl = HTML.span(class_='helpText', c=help_text)
next = None
if right_next is not None:
next = HTML.span(class_='rightNext', c=right_next)
kwargs.setdefault('id', name)
field = select(name, selected, options, **kwargs)
return HTML.div(class_='formField',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.span(class_='labelText', c=[title]),
HTML.span(class_='textField', c=[
field,
])]),
next,
HTML.literal('<form:error name="%s" />' % name),
expl])
示例10: required_legend
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def required_legend():
"""Return an inline HTML snippet explaining which fields are required.
See webhepers/public/stylesheets/webhelpers.css for suggested styles.
>>> required_legend()
literal(%(u)s'<span class="required required-symbol">*</span> = required')
"""
return HTML(
HTML.span("*", class_="required required-symbol"),
" = required",
)
示例11: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def _range(self, regexp_match):
html = super(Page, self)._range(regexp_match)
# Convert ..
dotdot = '<span class="pager_dotdot">..</span>'
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: checkbox
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def checkbox(label, name, checked=False, **kwargs):
kwargs['type'] = 'checkbox'
kwargs['name'] = name
if checked:
kwargs['checked'] = 'checked'
kwargs.setdefault('id', name)
return HTML.div(class_='formField checkbox',
id='%s-field' % kwargs['id'],
c=[HTML.label(for_=name, c=[
HTML.input(**kwargs),
HTML.span(class_='labelText', c=[label])
]),
HTML.literal('<form:error name="%s" />' % name)])
示例13: __init__
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def __init__(self, force_pager=False):
from shimpy.core.context import context
request = context.request
page_num = int(request.args.get("page", 1))
nav = []
if force_pager or "page" in request.args:
nav.append(HTML.a("Prev", href=update_params(request.full_path, page=page_num-1)))
nav.append(HTML.a("Index", href="/"))
if force_pager or "page" in request.args:
nav.append(HTML.a("Next", href=update_params(request.full_path, page=page_num+1)))
Block.__init__(self, "Navigation", HTML.span(literal(" | ").join(nav)), "left", 0)
示例14: field
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def field(
label='',
field='',
required=False,
label_desc='',
field_desc='',
help='',
error='',
field_pre='',
):
"""\
Format a field with a label.
``label``
The label for the field
``field``
The HTML representing the field, wrapped in ``literal()``
``required``
Can be ``True`` or ``False`` depending on whether the label should be
formatted as required or not. By default required fields have an
asterix.
``label_desc``
Any text to appear underneath the label, level with ``field_desc``
``field_desc``
Any text to appear underneath the field
``help``
Any HTML or JavaScript to appear imediately to the right of the field
which could be used to implement a help system on the form
``error``
Any text to appear immediately before the HTML field, usually used for
an error message.
It should be noted that when used with FormEncode's ``htmlfill`` module,
errors appear immediately before the HTML field in the position of the
``error`` argument. No ``<form:error>`` tags are added automatically by
this helper because errors are placed there anyway and adding the tags
would lead to this helper generating invalid HTML.
``field_pre``
Any HTML to appear immediately above the field.
TIP: For future compatibility, always specify arguments explicitly and do
not rely on their order in the function definition.
Here are some examples:
>>> print field('email >', literal('<input type="text" name="test" value="" />'), required=True)
<tr class="field">
<td class="label" valign="top"><span class="required">*</span><label>email >:</label></td>
<td class="field" colspan="2" valign="top"><input type="text" name="test" value="" /></td>
</tr>
>>> print field(
... label='email >',
... field=literal('<input type="text" name="test" value="" />'),
... label_desc='including the @ sign',
... field_desc='Please type your email carefully',
... error='This is an error message <br />',
... help = 'No help available for this field',
... required=True,
... )
...
<tr class="field">
<td class="label" valign="top"><span class="required">*</span><label>email >:</label></td>
<td class="field" valign="top"><div class="error">This is an error message <br /></div><input type="text" name="test" value="" /></td>
<td class="help" valign="top">No help available for this field</td>
</tr>
<tr class="description">
<td class="label_desc" valign="top"><span class="small">including the @ sign</span></td>
<td class="field_desc" colspan="2" valign="top"><span class="small">Please type your email carefully</span></td>
</tr>
An appropriate stylesheet to use to style forms generated with field() when
the table class is specified as "formbuild" would be::
table.formbuild span.error-message, table.formbuild div.error, table.formbuild span.required {
font-weight: bold;
color: #f00;
}
table.formbuild span.small {
font-size: 85%;
}
table.formbuild form {
margin-top: 20px;
}
table.formbuild form table td {
padding-bottom: 3px;
}
"""
if error:
field = HTML.div(class_='error', c=error)+field
if label:
label = label + literal(':')
if field_pre:
#.........这里部分代码省略.........
示例15: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import span [as 别名]
def _range(self, regexp_match):
"""
Return range of linked pages (e.g. '1 2 [3] 4 5 6 7 8').
Arguments:
regexp_match
A "re" (regular expressions) match object containing the
radius of linked pages around the current page in
regexp_match.group(1) as a string
This funtion is supposed to be called as a callable in
re.sub.
"""
radius = int(regexp_match.group(1))
# Compute the first and last page number within the radius
# e.g. '1 .. 5 6 [7] 8 9 .. 12'
# -> leftmost_page = 5
# -> rightmost_page = 9
leftmost_page = max(self.first_page, (self.page-radius))
rightmost_page = min(self.last_page, (self.page+radius))
nav_items = []
# Create a link to the first page (unless we are on the first page
# or there would be no need to insert '..' spacers)
if self.page != self.first_page and self.first_page < leftmost_page:
nav_items.append( self._pagerlink(self.first_page, self.first_page) )
# Insert dots if there are pages between the first page
# and the currently displayed page range
if leftmost_page - self.first_page > 1:
# Wrap in a SPAN tag if nolink_attr is set
text = '..'
if self.dotdot_attr:
text = HTML.span(c=text, **self.dotdot_attr)
nav_items.append(text)
for thispage in xrange(leftmost_page, rightmost_page+1):
# Hilight the current page number and do not use a link
if thispage == self.page:
text = '%s' % (thispage,)
# Wrap in a SPAN tag if nolink_attr is set
if self.curpage_attr:
text = HTML.span(c=text, **self.curpage_attr)
nav_items.append(text)
# Otherwise create just a link to that page
else:
text = '%s' % (thispage,)
nav_items.append( self._pagerlink(thispage, text) )
# Insert dots if there are pages between the displayed
# page numbers and the end of the page range
if self.last_page - rightmost_page > 1:
text = '..'
# Wrap in a SPAN tag if nolink_attr is set
if self.dotdot_attr:
text = HTML.span(c=text, **self.dotdot_attr)
nav_items.append(text)
# Create a link to the very last page (unless we are on the last
# page or there would be no need to insert '..' spacers)
if self.page != self.last_page and rightmost_page < self.last_page:
nav_items.append( self._pagerlink(self.last_page, self.last_page) )
return self.separator.join(nav_items)