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


Python Post.load_by_path方法代码示例

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


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

示例1: save_post

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [as 别名]

#.........这里部分代码省略.........
        if loc_name is not None:
            post.location['name'] = loc_name
    else:
        post.location = None

    for url_attr, context_attr in (('in_reply_to', 'reply_contexts'),
                                   ('repost_of', 'repost_contexts'),
                                   ('like_of', 'like_contexts'),
                                   ('bookmark_of', 'bookmark_contexts')):
        url_str = request.form.get(url_attr)
        if url_str is not None:
            urls = util.multiline_string_to_list(url_str)
            setattr(post, url_attr, urls)

    # fetch contexts before generating a slug
    contexts.fetch_contexts(post)

    syndication = request.form.get('syndication')
    if syndication is not None:
        post.syndication = util.multiline_string_to_list(syndication)

    audience = request.form.get('audience')
    if audience is not None:
        post.audience = util.multiline_string_to_list(audience)

    tags = request.form.getlist('tags')
    if post.post_type != 'article' and post.content:
        # parse out hashtags as tag links from note-like posts
        tags += util.find_hashtags(post.content)
    tags = list(filter(None, map(util.normalize_tag, tags)))
    post.tags = [Tag.query.filter_by(name=tag).first() or Tag(tag)
                 for tag in tags]

    slug = request.form.get('slug')
    if slug:
        post.slug = util.slugify(slug)
    elif not post.slug or was_draft:
        post.slug = post.generate_slug()

    # events should use their start date for permalinks
    path_date = post.start or post.published

    if post.draft:
        m = hashlib.md5()
        m.update(bytes(path_date.isoformat() + '|' + post.slug,
                       'utf-8'))
        post.path = 'drafts/{}'.format(m.hexdigest())

    elif not post.path or was_draft:
        base_path = '{}/{:02d}/{}'.format(
            path_date.year, path_date.month, post.slug)
        # generate a unique path
        unique_path = base_path
        idx = 1
        while Post.load_by_path(unique_path):
            unique_path = '{}-{}'.format(base_path, idx)
            idx += 1
        post.path = unique_path

    # generate short path
    if not post.short_path:
        short_base = '{}/{}'.format(
            util.tag_for_post_type(post.post_type),
            util.base60_encode(util.date_to_ordinal(path_date)))
        short_paths = set(
            row[0] for row in db.session.query(Post.short_path).filter(
                Post.short_path.startswith(short_base)).all())
        for idx in itertools.count(1):
            post.short_path = short_base + util.base60_encode(idx)
            if post.short_path not in short_paths:
                break

    infiles = request.files.getlist('files') + request.files.getlist('photo')
    current_app.logger.debug('infiles: %s', infiles)
    for infile in infiles:
        if infile and infile.filename:
            current_app.logger.debug('receiving uploaded file %s', infile)
            attachment = create_attachment_from_file(post, infile)
            os.makedirs(os.path.dirname(attachment.disk_path), exist_ok=True)
            infile.save(attachment.disk_path)
            post.attachments.append(attachment)

    # pre-render the post html
    html = util.markdown_filter(post.content, img_path=post.get_image_path())
    html = util.autolink(html)
    if post.post_type == 'article':
        html = util.process_people_to_microcards(html)
    else:
        html = util.process_people_to_at_names(html)
    post.content_html = html

    if not post.id:
        db.session.add(post)
    db.session.commit()

    current_app.logger.debug('saved post %d %s', post.id, post.permalink)
    redirect_url = post.permalink

    hooks.fire('post-saved', post, request.form)
    return redirect(redirect_url)
开发者ID:Lancey6,项目名称:redwind,代码行数:104,代码来源:admin.py

示例2: find_target_post

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [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

示例3: draft_by_hash

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [as 别名]
def draft_by_hash(hash):
    post = Post.load_by_path('drafts/{}'.format(hash))
    return render_post(post)
开发者ID:mongolsamurai,项目名称:redwind,代码行数:5,代码来源:views.py

示例4: post_by_path

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [as 别名]
def post_by_path(year, month, slug):
    post = Post.load_by_path('{}/{:02d}/{}'.format(year, month, slug))
    return render_post(post)
开发者ID:mongolsamurai,项目名称:redwind,代码行数:5,代码来源:views.py

示例5: draft_attachment

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [as 别名]
def draft_attachment(hash, filename):
    post = Post.load_by_path('drafts/{}'.format(hash))
    return render_attachment(post, filename)
开发者ID:mongolsamurai,项目名称:redwind,代码行数:5,代码来源:views.py

示例6: post_attachment

# 需要导入模块: from redwind.models import Post [as 别名]
# 或者: from redwind.models.Post import load_by_path [as 别名]
def post_attachment(year, month, slug, filename):
    post = Post.load_by_path('{}/{:02d}/{}'.format(year, month, slug))
    return render_attachment(post, filename)
开发者ID:mongolsamurai,项目名称:redwind,代码行数:5,代码来源:views.py


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