Пример #1
0
def gets():
    appkey = g.appkey
    ids = g.form.ids.data
    query = Content.query.filter(Content.appkey == appkey,
                                 Content.enabled == True)
    if ids:
        query = query.filter(Content.id.in_(ids))
    contents = query.all()
    records = contents_schema.dump(contents).data
    records = add_timestamp(records)
    return return_result(result=records)
Пример #2
0
def published(page, num):
    """List of published resources"""
    appkey = g.appkey
    author = g.form.author.data
    contents = Content.query.filter_by(author=author,
                                       appkey=appkey,
                                       enabled=True).paginate(page,
                                                              num,
                                                              error_out=False)
    total = contents.total
    pages = contents.pages
    records = contents_schema.dump(contents.items).data
    records = add_timestamp(records)
    return return_result(
        result=dict(total=total, pages=pages, records=records))
Пример #3
0
def content_list(page, num):
    """因为price使用了Numeric类型, 在转换为python对象时,对应 Decimal 类型
    Decimal类型,在使用jsonify进行json转换时会发生异常, 这是因为标准库json不支持转换Decimal

    解决办法: 安装simplejson, 此库的dumps有一个use_decimal参数(默认True,可以转换Decimal)
    当你安装了simplejson, flask的jsonify会自动使用它,而放弃系统标准库中的json库
    ref: https://github.com/pallets/flask/issues/835
    """
    appkey = g.appkey
    contents = Content.query.filter(
        Content.appkey == appkey, Content.enabled == True).order_by(
            Content.create_timed.desc()).paginate(page, num, error_out=False)
    total = contents.total
    pages = contents.pages
    result = contents_schema.dump(contents.items).data
    return return_result(result=dict(total=total, pages=pages, data=result))