Example #1
0
def get_list(category_slug, page=1, page_size=20):
    """
    获取指定栏目下的内容列表
    :param category_slug:
    :param page:
    :param page_size:
    :return:
    """
    # GET /entry/1/1_20.html
    # curl 'http://127.0.0.1:5000/software/1_20.json?q=www&s=created_at&o=asc'

    query, sort, order = get_query_info(request)

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    # 通过反射获得数据类
    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[
        category.entry_type.code]]

    _total, _pages, _list = ModelClass.get_page_by_category_id(
        category.id, sort, order, page, page_size)

    return render_json({
        "data_list": _list,
        "total": _total,
        "page": page,
        "page_size": page_size
    })
Example #2
0
def show_list(category_slug, page=1, page_size=20):
    """
    显示指定栏目下的内容列表
    :param category_slug:
    :param page:
    :param page_size:
    :return:
    """
    # GET /software/1/1_20
    # curl 'http://127.0.0.1:5000/software/1_20.html?q=www&s=created_at&o=asc'

    query, sort, order = get_query_info(request)

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[
        category.entry_type.code]]

    _total, _pages, _list = ModelClass.get_page_by_category_id(
        category.id, sort, order, page, page_size)

    return render_html(category.list_template,
                       data_list=_list,
                       category_slug=category_slug,
                       total=_total,
                       page=page,
                       page_size=page_size)
Example #3
0
def show(category_slug, entry_slug):
    """
    显示内容(文章,etc)
    @param slug:
    @return:
    """

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    FormClass = globals()[ENTRY_TYPE_FORM_CLASSNAME[category.entry_type.code]]
    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[
        category.entry_type.code]]

    entry = ModelClass.query.filter_by(slug=entry_slug).first()

    if entry is None:
        abort(404)

    # # todo g.user.is_supervisor
    # if entry.entry_status != EntryStatus.published:
    #     if g.user and not g.user.is_supervisor:
    #         return render_template('common/entry_pending.html')
    #
    # if entry.category.show_role:
    #     if not g.user or entry.category.show_role > g.user.role:
    #         abort(404)
    #
    # query, sort, order, page = query_condition()
    #
    #
    #
    # return render_show(entry, sort, order, page)
    category = entry.category

    show_template = category.show_template

    return render_template(
        show_template,
        current_category=entry.category,
        category_slug=entry.category,
        entry=entry,
        page_url=entry.slug,
    )
Example #4
0
def show(category_slug, entry_slug):
    """
    显示内容(文章,etc)
    @param slug:
    @return:
    """

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    FormClass = globals()[ENTRY_TYPE_FORM_CLASSNAME[category.entry_type.code]]
    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[category.entry_type.code]]

    entry = ModelClass.query.filter_by(slug=entry_slug).first()

    if entry is None:
        abort(404)

    # # todo g.user.is_supervisor
    # if entry.entry_status != EntryStatus.published:
    #     if g.user and not g.user.is_supervisor:
    #         return render_template('common/entry_pending.html')
    #
    # if entry.category.show_role:
    #     if not g.user or entry.category.show_role > g.user.role:
    #         abort(404)
    #
    # query, sort, order, page = query_condition()
    #
    #
    #
    # return render_show(entry, sort, order, page)
    category = entry.category

    show_template = category.show_template

    return render_template(
        show_template,
        current_category=entry.category,
        category_slug=entry.category,
        entry=entry,
        page_url=entry.slug,
    )
Example #5
0
def show_list(category_slug, page=1, page_size=20):
    """
    显示指定栏目下的内容列表
    :param category_slug:
    :param page:
    :param page_size:
    :return:
    """
    # GET /software/1/1_20
    # curl 'http://127.0.0.1:5000/software/1_20.html?q=www&s=created_at&o=asc'

    query, sort, order = get_query_info(request)

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[category.entry_type.code]]

    _total, _pages, _list = ModelClass.get_page_by_category_id(category.id, sort, order, page, page_size)

    return render_html(category.list_template, data_list=_list, category_slug=category_slug, total=_total, page=page, page_size=page_size)
Example #6
0
def get_list(category_slug, page=1, page_size=20):
    """
    获取指定栏目下的内容列表
    :param category_slug:
    :param page:
    :param page_size:
    :return:
    """
    # GET /entry/1/1_20.html
    # curl 'http://127.0.0.1:5000/software/1_20.json?q=www&s=created_at&o=asc'

    query, sort, order = get_query_info(request)

    category = Category.get_by_slug(category_slug)

    if not category:
        abort(404)

    # 通过反射获得数据类
    ModelClass = globals()[ENTRY_TYPE_MODEL_CLASSNAME[category.entry_type.code]]

    _total, _pages, _list = ModelClass.get_page_by_category_id(category.id, sort, order, page, page_size)

    return render_json({"data_list": _list, "total": _total, "page": page, "page_size": page_size})