本文整理汇总了Python中webhelpers.html.HTML.li方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.li方法的具体用法?Python HTML.li怎么用?Python HTML.li使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.li方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: company_choice
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def company_choice(request, companies, cid):
"""
Add the company choose menu
"""
options = []
for company in companies:
if request.context.__name__ == 'company':
url = request.current_route_path(id=company.id)
else:
url = request.route_path("company", id=company.id)
name = company.name
if not company.active:
name += " (désactivée)"
options.append((url, name))
if request.context.__name__ == 'company':
default = request.current_route_path(id=cid)
else:
default = request.route_path("company", id=cid)
html_attrs = {
'class': 'company-search',
'id': "company-select-menu",
}
html_code = HTML.li(
tags.select("companies", default, options, **html_attrs)
)
return HtmlItem(html=html_code)
示例2: pager
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def pager(self, format='<ul class="pagination">$link_previous ~2~ $link_next</ul>', page_param='page', partial_param='partial',
show_if_single_page=False, separator=' ', onclick=None,
symbol_first='<<', symbol_last='>>',
symbol_previous='<', symbol_next='>',
link_attr=None,
curpage_attr=None,
dotdot_attr=None, **kwargs):
self.curpage_attr = curpage_attr or {'class': 'active'}
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 or {'class': 'pager_link', 'rel': 'prerender'}
self.dotdot_attr = dotdot_attr or {'class': 'pager_dotdot'}
# 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': HTML.li(self.previous_page and \
self._pagerlink(self.previous_page, symbol_previous) \
or HTML.a(symbol_previous)),
'link_next': HTML.li(self.next_page and \
self._pagerlink(self.next_page, symbol_next) \
or HTML.a(symbol_next))
})
return literal(result)
示例3: _list
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def _list(tag, items, default, attrs, li_attrs):
content = [HTML.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 getattr(HTML, tag)(content, **attrs)
示例4: _pagerlink
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
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
示例5: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [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)
示例6: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [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)
示例7: company_choice
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def company_choice(request, companies, cid):
"""
Add the company choose menu
"""
if request.context.__name__ == 'company':
options = ((request.current_route_path(id=company.id),
company.name) for company in companies)
default = request.current_route_path(id=cid)
else:
options = ((request.route_path("company", id=company.id),
company.name) for company in companies)
default = request.route_path("company", id=cid)
html_attrs = {'class': 'pull-left company-search',
'id': "company-select-menu"}
html_code = HTML.li(
tags.select("companies", default, options, **html_attrs))
return HtmlItem(html=html_code)
示例8: _pagerlink
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def _pagerlink(self, page, text, extra_attributes=None):
anchor = super(Page, self)._pagerlink(page, text)
extra_attributes = extra_attributes or {}
return HTML.li(anchor, **extra_attributes)
示例9: _pagerlink
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [as 别名]
def _pagerlink(self, page, text, link_attr=None):
link_attr = link_attr or {}
if not page:
link_attr = {'class': 'disabled'}
return HTML.li(super(BootStrapPage, self)._pagerlink(page, text), **link_attr)
示例10: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [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 function 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)
text = HTML.li(text, **{'class': 'disabled'})
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)
text = HTML.li(text, **{'class': 'active'})
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)
text = HTML.li(text, **{'class': 'disabled'})
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)
示例11: _range
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import li [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 function 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, _cur, rightmost_page = self._get_pos(self.page,
self.last_page,
(radius * 2) + 1)
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(HTML.li(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(HTML.li(text_))
for thispage in xrange(leftmost_page, rightmost_page + 1):
# Highlight the current page number and do not use a link
text_ = str(thispage)
if thispage == self.page:
# Wrap in a SPAN tag if nolink_attr is set
if self.curpage_attr:
text_ = HTML.li(HTML.span(c=text_), **self.curpage_attr)
nav_items.append(text_)
# Otherwise create just a link to that page
else:
nav_items.append(HTML.li(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(HTML.li(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(HTML.li(self._pagerlink(self.last_page, self.last_page)))
#_page_link = url.current()
#nav_items.append(literal('<link rel="prerender" href="%s?page=%s">' % (_page_link, str(int(self.page)+1))))
#nav_items.append(literal('<link rel="prefetch" href="%s?page=%s">' % (_page_link, str(int(self.page)+1))))
return self.separator.join(nav_items)