Пример #1
0
def post_page(post_id):
    """
    GET:
        通用视图函数,那些公共的页面将从此进入
        :param post_id: 文章id
        :return:
    """
    theme_pages = get_config("seo", "THEME_PAGE_FOR_STATIC_PAGE")
    post_url = None
    if "post_page" in theme_pages:
        # 主题post页面路由
        post_url = theme_pages["post_page"].replace("<id>", post_id)

    user_agent = request.headers.get("User-Agent").lower()
    is_spider_bot = False
    for bot in get_config("seo", "SUPPORTED_SPIDERS"):
        if bot.lower() in user_agent:
            # 是搜索引擎蜘蛛
            is_spider_bot = True
            break
    if is_spider_bot:
        # 是搜索引擎蜘蛛
        data = get_post(post_id=post_id)
        absolute_path = os.path.abspath("{}/post.html".format(
            static_html_view.template_folder))
        if not os.path.isfile(absolute_path):
            abort(404)
        # 使用osroom静态页面
        return render_template('post.html', data=data)
    elif post_url:
        # 使用主题动态页面
        return redirect(post_url)

    abort(404)
Пример #2
0
def api_post():

    '''
    GET:
        1.获取一篇文章
        post_id:<str>,post id

        2.根据条件获取文章
        sort:<array>,排序, 1表示升序, -1表示降序.如:
            按时间降序 [{"issue_time":-1},{"update_time":-1}]
            按时间升序 [{"issue_time": 1},{"update_time": 1}]
            先后按赞(like)数降序, 评论数降序,pv降序, 发布时间降序
            [{"like": -1}, {"comment_num": -1}, {"pv": -1},{"issue_time": -1}]
            默认时按时间降序, 也可以用其他字段排序
        status:<int> , "is_issued"(正常发布) or "draft"(草稿) or "not_audit"(等待审核) or "unqualified"(未通过审核) or "recycle"(用户的回收站) or "user_remove"
            (user_remove是指用户永久删除或被管理删除的)

        matching_rec:<str>,可选,提供一段内容, 匹配一些文章推荐
        time_range:<int>,可选,单位为天,比如最近7天的文章
        page:<int>,第几页,默认第1页
        pre:<int>, 每页查询多少条
        keyword:<str>, Search keywords, 搜索使用
        fields:<array>, 需要返回的文章字段,如["title"]
        unwanted_fields:<array>, 不能和fields参数同时使用,不需要返回的文章字段,如["user_id"]
        user_id:<str>, 如需获取指定用户的post时需要此参数
        category_id:<str>, 获取指定文集的post时需要此参数

    '''

    if request.c_method == "GET":
        if request.argget.all('post_id'):
            data = get_post()
        else:
            data = get_posts()
    else:
        data = {"msg_type":"w", "msg":METHOD_WARNING, "http_status":405}
    return response_format(data)