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


Python Location.objects方法代码示例

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


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

示例1: search

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import objects [as 别名]
def search():
    if 'query' not in request.args or not request.args['query']:
        return json.dumps({
            'meta': {
                'code': 400,
                'errorType': 'param_error',
                'errorDetail': 'Missing or empty query parameter'
            },
        }), 400

    limit = 10
    if 'limit' in request.args and request.args['limit'] and request.args['limit'].isdigit():
        limit = int(request.args['limit'])

    # Replacing whitespace with .* to offer more flexibility in what schools get
    # returned in the search. ex: If the query is "Belleville High School", we'd
    # still want it to return "Belleville Senior High School" as a result.
    name_regex = request.args['query'];
    name_regex = name_regex.replace(' ', '.*');

    query = {'name':{'$regex': '%s' % name_regex, '$options': 'i'}};

    if 'state' in request.args:
        query['state'] = request.args['state'];

    total_results = Location.objects(__raw__=query).count()
    locations = Location.objects(__raw__=query).limit(limit)
    results = []
    for location in locations:
        results.append(
            {
                'name': location.name,
                'street': location.street,
                'city': location.city,
                'state': location.state,
                'zip': location.zip,
                'lat': location.lat,
                'lon': location.lon,
                'country': location.country,
                'gsid': location.gsid
            }
        )
    return json.dumps({
        'meta': {
            'code': 200,
            'more_results': len(results) < total_results,
            'total_results': total_results
        },
        'results': results
    }), 200
开发者ID:DoSomething,项目名称:lofi-schools-flask,代码行数:52,代码来源:main.py

示例2: search

# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import objects [as 别名]
def search():
    if 'query' not in request.args or not request.args['query']:
        return json.dumps({
            'meta': {
                'code': 400,
                'errorType': 'param_error',
                'errorDetail': 'Missing or empty query parameter'
            },
        }), 400

    limit = 10
    if 'limit' in request.args and request.args['limit'] and request.args['limit'].isdigit():
        limit = int(request.args['limit'])

    query = {'name':{'$regex': '%s' % request.args['query'], '$options': 'i'}};

    if 'state' in request.args:
        query['state'] = request.args['state']; 

    locations = Location.objects(__raw__=query).limit(limit)
    results = []
    for location in locations:
        results.append(
            {
                'name': location.name,
                'street': location.street,
                'city': location.city,
                'state': location.state,
                'zip': location.zip,
                'lat': location.lat,
                'lon': location.lon,
                'country': location.country,
                'gsid': location.gsid
            }
        )
    return json.dumps({
        'meta': {
            'code': 200
        },
        'results': results
    }), 200
开发者ID:desmondmorris,项目名称:lofi,代码行数:43,代码来源:main.py


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