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


Python PageData.limit方法代码示例

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


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

示例1: search

# 需要导入模块: from main import PageData [as 别名]
# 或者: from main.PageData import limit [as 别名]
def search():
    """
    :URL: /item/search?page=<page>&type=<query type>&limit=<max results>&query=<search query>&sort=<sort type>

    :Method: GET

    :Query Types:
        * item - Item Search
        * user - User Search

    :Sort Types:
        * name - Alphabetical by name
        * added - By added date, latest first
        * modified - Last modified

    :Sample Response: Setting the accept:application/json header will return JSON. 

    .. code-block:: javascript

    {
        "limit": 2,
        "num_pages": 4,
        "num_results": 8,
        "query": "Cascadia",
        "results": [
            {
                "added": "2016-05-22 17:52:36",
                "body": "Blue/White (Cascadia Fringe, Gisele Currier Memorial Fundraiser)",
                "description": 460,
                "images": [
                    388,
                    389
                ],
                "modified": "2016-05-24 22:45:33",
                "name": "No Pity MLS Blue White Fringe (Cascadia Fringe) 2012",
                "uid": 362
            },
            {
                "added": "2016-05-22 17:02:15",
                "body": "",
                "description": 317,
                "images": [
                    364,
                    365
                ],
                "modified": "2016-05-22 17:02:15",
                "name": "Cascadia",
                "uid": 350
            }
        ]
    }
    """

    pd = PageData()
    pd.search_type = request.args.get('type')
    pd.query = request.args.get('query')
    pd.limit = request.args.get('limit')
    pd.page = request.args.get('page')
    pd.sort = request.args.get('sort')

    try:
        if not pd.limit:
            pd.limit = 20
        else:
            pd.limit = int(pd.limit)

        if not pd.page:
            pd.page = 1
        else:
            pd.page = int(pd.page)
    except ValueError:
        return page_not_found()

    if pd.search_type == "items":
        return item_search(pd)
    elif pd.search_type == "users":
        return user_search(pd)
    elif pd.search_type == "tags":
        return tag_search(pd)
    else:
        pd.search_type = "items"
        return item_search(pd)
开发者ID:cmazuc,项目名称:scarfage,代码行数:84,代码来源:search.py


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