当前位置: 首页>>代码示例>>Python>>正文


Python HTML.a方法代码示例

本文整理汇总了Python中webhelpers.html.HTML.a方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.a方法的具体用法?Python HTML.a怎么用?Python HTML.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webhelpers.html.HTML的用法示例。


在下文中一共展示了HTML.a方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pagerlink

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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
开发者ID:digideskio,项目名称:sasha,代码行数:60,代码来源:Page.py

示例2: display_user_list

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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")
        ))
开发者ID:shish,项目名称:shimpy,代码行数:57,代码来源:theme.py

示例3: _pagerlink

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
    def _pagerlink(self, pagenr, text):
        """
        Create a URL that links to another page using url_for().

        Parameters:

        pagenr
            Number of the page that the link points to

        text
            Text to be printed in the A-HREF tag
        """
        # 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 'pagenr'. Then you
        # call the navigator method with page_param='pagenr' and
        # the url_for() call will create a link '/foo/bar?pagenr=...'
        # 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] = pagenr

        # Create the URL to load a certain page
        link_url = link_params.get('link', request.path_info)
	if '?' in link_url:
	        link_url = '%s&page=%s'%(link_url, pagenr)
	else:
	        link_url = '%s?page=%s'%(link_url, pagenr)

        # Create the URL to load the page area part of a certain page (AJAX updates)
        #link_params[self.partial_param] = 1
        partial_url = link_params.get('partial', '') #url_for(**link_params)

        if self.onclick: # create link with onclick action for AJAX
            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": pagenr
                })
            return HTML.a(text, href=link_url, onclick=onclick_action, **self.link_attr)
        else: # return static link
            return HTML.a(text, href=link_url, **self.link_attr)
开发者ID:vanecan,项目名称:SGP14,代码行数:50,代码来源:paginate.py

示例4: __init__

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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)
开发者ID:shish,项目名称:shimpy,代码行数:18,代码来源:block.py

示例5: pager

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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)
开发者ID:t-kenji,项目名称:kallithea-mirror,代码行数:49,代码来源:page.py

示例6: test_html

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
def test_html():
    a = HTML.a(href='http://mostlysafe\" <tag', c="Bad <script> tag")
    eq_(a,
        u'<a href="http://mostlysafe&#34; &lt;tag">Bad &lt;script&gt; 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)
开发者ID:gjhiggins,项目名称:WebHelpers2,代码行数:12,代码来源:test_html.py

示例7: handle_match

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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_options)
     a_options['href'] = literal(prefix + link)
     return literal(before) + HTML.a(text, **a_options) + literal(after)
开发者ID:adrianpike,项目名称:wwscc,代码行数:13,代码来源:tools.py

示例8: _range

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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)
开发者ID:fusionx1,项目名称:ckan,代码行数:13,代码来源:helpers.py

示例9: _range

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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)
开发者ID:HHS,项目名称:ckan,代码行数:15,代码来源:helpers.py

示例10: link_to

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
def link_to(label, url='', **attrs):
    """Create a hyperlink with the given text pointing to the URL.

    If the label is ``None`` or empty, the URL will be used as the label.

    This function does not modify the URL in any way.  The label will be
    escaped if it contains HTML markup.  To prevent escaping, wrap the label
    in a ``webhelpers.html.literal()``.
    """
    attrs['href'] = url
    if label == '' or label is None:
        label = url
    return HTML.a(label, **attrs)
开发者ID:gjhiggins,项目名称:WebHelpers2,代码行数:15,代码来源:tags.py

示例11: h1

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
def h1(title, id=None, tag='h1', **attrs):
    """Returns an <h1> tag that links to itself.

    `title` is the text inside the tag.

    `id` is the HTML id to use; if none is provided, `title` will be munged
    into something appropriate.
    """
    if not id:
        id = sanitize_id(title)

    link = HTML.a(title, href='#' + id, class_='subtle')
    return HTML.tag(tag, link, id=id, **attrs)
开发者ID:encukou,项目名称:spline,代码行数:15,代码来源:helpers.py

示例12: test_newline_arg

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
def test_newline_arg():
    eq_(HTML.a(), literal(u'<a></a>'))
    eq_(HTML.a(_nl=True), literal(u'<a>\n</a>\n'))
    eq_(HTML.a(_closed=False), literal(u'<a>'))
    eq_(HTML.a(_closed=False, _nl=True), literal(u'<a>\n'))
    eq_(HTML.a("A", "B", href="/"), literal(u'<a href="/">AB</a>'))
    eq_(HTML.a(
        "A", "B", href="/", _nl=True), literal(u'<a href="/">\nA\nB\n</a>\n'))
开发者ID:gjhiggins,项目名称:WebHelpers2,代码行数:10,代码来源:test_html.py

示例13: _pagerlink

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
        def _pagerlink(pagenr, text):
            """
            Create a URL that links to another page using url_for().

            Parameters:
                
            pagenr
                Number of the page that the link points to

            text
                Text to be printed in the A-HREF tag
            """
            from routes import url_for
            # 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 'pagenr'. Then you
            # call the navigator method with page_param='pagenr' and
            # the url_for() call will create a link '/foo/bar?pagenr=...'
            # 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(kwargs)
            link_params[page_param] = pagenr
            # Create the URL to load a certain page
            link_url = url_for(**link_params)
            # Create the URL to load the page area part of a certain page (AJAX updates)
            link_params[partial_param] = 1
            partial_url = url_for(**link_params)

            if onclick: # create link with onclick action for AJAX
                onclick_action = onclick % (partial_url,)
                return HTML.a(text, href=link_url, onclick=onclick_action, **link_attr)
            else: # return static link
                return HTML.a(text, href=link_url, **link_attr)
开发者ID:jeffreyhsu,项目名称:ogmaster-server,代码行数:39,代码来源:paginate.py

示例14: th_sortable

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [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)
开发者ID:gjhiggins,项目名称:WebHelpers2,代码行数:51,代码来源:tags.py

示例15: handle_match

# 需要导入模块: from webhelpers.html import HTML [as 别名]
# 或者: from webhelpers.html.HTML import a [as 别名]
 def handle_match(matchobj):
     # The pattern contains a space so we only find usernames that 
     # has a whitespace in front, we save the spaced so we can but 
     # it back after the transformation
     space, userid = matchobj.group(1, 2)
     #Force lowercase userid
     userid = userid.lower()
     if userid in users: 
         user = users[userid]
 
         tag = {}
         tag['href'] = request.resource_url(meeting, '_userinfo', query={'userid': userid}).replace(request.application_url, '')
         tag['title'] = user.title
         tag['class'] = "inlineinfo"
         return space + HTML.a('@%s' % userid, **tag)
     else:
         return space + '@' + userid
开发者ID:tobsan,项目名称:voteit.core,代码行数:19,代码来源:helpers.py


注:本文中的webhelpers.html.HTML.a方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。