本文整理汇总了Python中webhelpers.html.HTML.th方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.th方法的具体用法?Python HTML.th怎么用?Python HTML.th使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webhelpers.html.HTML
的用法示例。
在下文中一共展示了HTML.th方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_user_list
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import th [as 别名]
def display_user_list(self, users, user):
page = context.page
request = context.request
page.title = "User List"
page.heading = "User List"
page.add_block(NavBlock(force_pager=True))
headers = []
tds = [
HTML.th("ID", width="16"),
HTML.th("Av.", width="16", title="Avatar"),
HTML.th("Username"),
HTML.th("Join Date"),
HTML.th("Ps.", width="16", title="Post Count"),
HTML.th("Cs.", width="16", title="Comment Count"),
]
if user.can("view_user_email"):
tds.append(HTML.th("Email Address"))
tds.append(HTML.th("Action"))
headers.append(HTML.tr(*tds))
tds = [
"", # HTML.input(name="page", type="hidden", value=request.args.get("page", "1")),
tags.checkbox("avatar", checked=request.args.get("avatar")),
tags.text("username", value=request.args.get("username")),
"",
tags.checkbox("posts", value="1", checked=request.args.get("posts")),
tags.checkbox("comments", value="1", checked=request.args.get("comments")),
]
if user.can("view_user_email"):
tds.append(tags.text("email", value=request.args.get("email")))
tds.append(tags.submit(name="submit", value="Search"))
headers.append(HTML.tr(HTML.form(*[HTML.td(x) for x in tds], action="#", method="GET")))
rows = []
for duser in users:
assert isinstance(duser, User)
tds = [
duser.id,
duser.get_avatar_html(16),
HTML.a(duser.username, href=make_link("user/"+duser.username)),
str(duser.join_date)[:16],
HTML.a(duser.post_count, href=make_link("post/list/uploaded_by_id=%d/1" % duser.id)),
duser.comment_count,
]
if user.can("view_user_email"):
tds.append(duser.email)
tds.append("")
rows.append(HTML.tr(*[HTML.td(x) for x in tds]))
page.add_block(Block(
"Users",
HTML.table(HTML.thead(*headers), HTML.tbody(*rows), class_="zebra")
))
示例2: display_login_block
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import th [as 别名]
def display_login_block(self):
page = context.page
table = HTML.table(
HTML.tr(
HTML.th("Username"),
HTML.td(tags.text("username")),
),
HTML.tr(
HTML.th("Password"),
HTML.td(tags.password("password")),
),
HTML.tr(
HTML.td(tags.submit(name="submit", value="Log In"), colspan=2)
),
HTML.tr(
HTML.td(HTML.small(HTML.a("Create Account", href=make_link("user_admin/create"))), colspan=2)
),
# class_="form",
)
form = HTML.form(table, action=make_link("user_admin/login"), method="POST")
page.add_block(Block("Login", form, self._user_block_location(), 90))
示例3: th_sortable
# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import th [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)s'<th class="sort">Name</th>')
>>> th_sortable(sort, "date", "Date", "?sort=date")
literal(%(u)s'<th><a href="?sort=date">Date</a></th>')
>>> th_sortable(sort, "date", "Date", None, link_attrs={"onclick": "myfunc()"})
literal(%(u)s'<th><a onclick="myfunc()">Date</a></th>')
"""
from webhelpers.html import HTML
if current_order == column_order:
content = label
class_ = class_if_sort_column
else:
link_attrs = link_attrs or {}
content = HTML.a(label, href=url, **link_attrs)
class_ = class_if_not_sort_column
return HTML.th(content, class_=class_, **attrs)