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


Python Post.load_by_date方法代码示例

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


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

示例1: find_target_post

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_date [as 别名]
def find_target_post(target_url):
    current_app.logger.debug("looking for target post at %s", target_url)

    # follow redirects if necessary
    redirect_url = urllib.request.urlopen(target_url).geturl()
    if redirect_url and redirect_url != target_url:
        current_app.logger.debug("followed redirection to %s", redirect_url)
        target_url = redirect_url

    parsed_url = urllib.parse.urlparse(target_url)

    if not parsed_url:
        current_app.logger.warn("Could not parse target_url of received webmention: %s", target_url)
        return None

    try:
        # FIXME this is a less-than-perfect fix for hosting from a
        # subdirectory. The url_map may have some clever work-around.
        parsed_site_root = urllib.parse.urlparse(get_settings().site_url)
        site_prefix = parsed_site_root.path
        if site_prefix.endswith("/"):
            site_prefix = site_prefix[:-1]
        if not parsed_url.path.startswith(parsed_site_root.path):
            raise NotFound

        urls = current_app.url_map.bind(get_settings().site_url)
        path = parsed_url.path[len(site_prefix) :]
        current_app.logger.debug("target path with no prefix %s", path)
        endpoint, args = urls.match(path)
        current_app.logger.debug("found match for target url %r: %r", endpoint, args)
    except NotFound:
        current_app.logger.warn("Webmention could not find target for %s", parsed_url.path)
        return None

    post = None
    if endpoint == "views.post_by_path":
        year = args.get("year")
        month = args.get("month")
        slug = args.get("slug")
        post = Post.load_by_path("{}/{:02d}/{}".format(year, month, slug))

    elif endpoint == "views.post_by_date":
        post_type = args.get("post_type")
        year = args.get("year")
        month = args.get("month")
        day = args.get("day")
        index = args.get("index")
        post = Post.load_by_date(post_type, year, month, day, index)

    elif endpoint == "views.post_by_old_date":
        post_type = args.get("post_type")
        yymmdd = args.get("yymmdd")
        year = int("20" + yymmdd[0:2])
        month = int(yymmdd[2:4])
        day = int(yymmdd[4:6])
        post = Post.load_by_date(post_type, year, month, day, index)

    elif endpoint == "views.post_by_id":
        dbid = args.get("dbid")
        post = Post.load_by_id(dbid)

    if not post:
        current_app.logger.warn("Webmention target points to unknown post: {}".format(args)),

    return post
开发者ID:mongolsamurai,项目名称:redwind,代码行数:67,代码来源:wm_receiver.py


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