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


Python Page.isRedirect方法代码示例

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


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

示例1: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import isRedirect [as 别名]
def execute(macro, args, formatter):
    if not formatter:
        formatter = macro.formatter
    # get number of wanted links        
    try:
        links = max(int(args), 1)
    except StandardError:
        links = 1

    # select the pages from the page list
    random_list = wikiutil.getRandomPages(macro.request)
    pages = []
    while len(pages) < links and random_list:
        pagename = random.choice(random_list)
        page = Page(pagename, macro.request)
        if macro.request.user.may.read(page) and page.exists() and not page.isRedirect():
		if page.proper_name()[0:6] != 'Users/' and page.proper_name()[-5:] != '/Talk':
	            pages.append(page)

    # return a single page link
    if links == 1:
        return pages[0].link_to()

    # return a list of page links
    pages.sort()
    result = [macro.formatter.bullet_list(1)]
    for page in pages:
        result.append("%s%s%s" %
                      (macro.formatter.listitem(1), page.link_to(),
                       macro.formatter.listitem(0)))
    result.append(macro.formatter.bullet_list(0))

    return ''.join(result)
开发者ID:rtucker,项目名称:sycamore,代码行数:35,代码来源:randompage.py

示例2: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import isRedirect [as 别名]
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter

    cursor = macro.request.cursor
    cursor.execute("""
        SELECT c.propercased_name, count(c.source_pagename) as cnt
        FROM (
            SELECT curPages.propercased_name, links.source_pagename
            FROM curPages LEFT JOIN links on
                (links.source_pagename=curPages.name and
                 links.wiki_id=%(wiki_id)s and
                 curPages.wiki_id=%(wiki_id)s)
            WHERE curPages.wiki_id=%(wiki_id)s
        ) as c
        GROUP BY c.propercased_name ORDER BY cnt""",
        {'wiki_id': macro.request.config.wiki_id})
    results = cursor.fetchall()
   
    old_count = -1
    for entry in results:
        name = entry[0] 
        lower_name = name.lower()
        if skip_page(name):
            continue
        
        new_count = entry[1]
        page = Page(name, macro.request)
        if new_count == 0 and page.isRedirect():
            continue

        if new_count != old_count:
            old_count = new_count
            macro.request.write(macro.formatter.heading(2, str(new_count)))
        else:
            macro.request.write(", ")
        macro.request.write(page.link_to(know_status=True,
                                         know_status_exists=True))

    return ''
开发者ID:ivanov,项目名称:sycamore,代码行数:42,代码来源:outgoinglinks.py

示例3: execute

# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import isRedirect [as 别名]
def execute(macro, args, formatter=None):
    if not formatter:
        formatter = macro.formatter
    _ = macro.request.getText

    # prevent recursive calls
    global _guard
    if _guard:
        return ""

    # flush the request output because orphaned may take time to generate
    macro.request.flush()

    # delete all linked pages from a dict of all pages
    _guard = 1
    cursor = macro.request.cursor
    cursor.execute(
        """
        SELECT curPages.propercased_name
        FROM curPages LEFT JOIN links on
            (links.destination_pagename=curPages.name and
             links.wiki_id=%(wiki_id)s and curPages.wiki_id=%(wiki_id)s
            )
        WHERE curPages.wiki_id=%(wiki_id)s and
              links.destination_pagename is NULL""",
        {"wiki_id": macro.request.config.wiki_id},
    )

    orphanednames_result = cursor.fetchall()
    _guard = 0

    # check for the extreme case
    if not orphanednames_result:
        return "<p>%s</p>" % _("No orphaned pages in this wiki.")

    # return a list of page links
    from Sycamore.Page import Page

    redirects = []
    pages = []
    show_users = showUsers(macro.request)
    for entry in orphanednames_result:
        name = entry[0]
        if name.startswith(config.user_page_prefix) and not show_users:
            continue
        page = Page(name, macro.request)
        is_redirect = False
        # if not macro.request.user.may.read(name): continue
        if page.isRedirect():
            redirects.append(page)
        else:
            pages.append(page)

    # usually 'Orphaned Pages' or something such
    pagename = macro.request.getPathinfo()[1:]
    if not show_users:
        macro.request.write(
            '<div style="float: right;">'
            '<div class="actionBoxes"><span>'
            "%s"
            "</span></div></div>" % wikiutil.link_tag(macro.request, pagename + "?show_users=true", "show users")
        )
    else:
        macro.request.write(
            '<div style="float: right;">'
            '<div class="actionBoxes"><span>'
            "%s"
            "</span></div></div>" % wikiutil.link_tag(macro.request, pagename, "hide users")
        )

    macro.request.write(macro.formatter.heading(2, "Orphans"))
    macro.request.write(macro.formatter.bullet_list(1))
    for page in pages:
        macro.request.write(macro.formatter.listitem(1))
        macro.request.write(page.link_to(know_status=True, know_status_exists=True))
        macro.request.write(macro.formatter.listitem(0))
    macro.request.write(macro.formatter.bullet_list(0))

    macro.request.write(macro.formatter.heading(2, "Orphaned Redirects"))
    macro.request.write(macro.formatter.bullet_list(1))
    for page in redirects:
        macro.request.write(macro.formatter.listitem(1))
        macro.request.write(page.link_to(know_status=True, know_status_exists=True))
        macro.request.write(macro.formatter.listitem(0))
    macro.request.write(macro.formatter.bullet_list(0))

    return ""  # macros must return strings
开发者ID:philipn,项目名称:sycamore,代码行数:89,代码来源:orphanedpages.py


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