示例#1
0
def search(field=None, action=None, value=None):
    '''Plugin search
    A generalized search system that accepts both single-criteria get requests
    as well as multi-criteria posts.
    '''
    filters = []
    if request.method == 'GET':
        fields = bleach.clean(request.query.fields or 'slug,plugin_name,description').split(',')
        start = c.sint(bleach.clean(request.query.start or None))
        size = c.sint(bleach.clean(request.query.size or None))
        sort = bleach.clean(request.query.sort or 'slug')
        field = bleach.clean(field)
        value = bleach.clean(value)
        filters = [
            {'field': field, 'action': action, 'value': value}
        ]
    else:
        req = json.dumps(request.forms.get('search'))
        fields = req['fields'] if 'fields' in req else ['slug', 'plugin_name', 'description']
        start = req['start'] if 'sort' in req else None
        size = req['size'] if 'size' in req else None
        sort = req['sort'] if 'sort' in req else 'slug'
        filters = req['filters'] if 'filters' in req else []
    try:
        data = c.plugin_search(filters, fields, sort)
    except:
        raise bottle.HTTPError(400, '{"error": "invalid post"}')
    else:
        if start is not None and size is not None:
            return c.jsonify(data[start:start+size])
        return c.jsonify(data)
示例#2
0
def search(base=None, field=None, action=None, value=None):
    '''Plugin search
    A generalized search system that accepts both single-criteria get requests
    as well as multi-criteria posts.
    '''
    fields = bleach.clean(request.query.fields or 'name,plugname,description').split(',')
    fields = v2to3(fields)
    start = c.sint(bleach.clean(request.query.start or None))
    size = c.sint(bleach.clean(request.query.size or None))
    sort = bleach.clean(request.query.sort or 'slug')
    field = bleach.clean(field)
    value = bleach.clean(value)
    base = bleach.clean(base)
    if base == 'version':
        field = 'versions.%s' % field
    filters = [
        {'field': field, 'action': action, 'value': value}
    ]
    try:
        data = c.plugin_search(filters, fields, sort)
    except:
        raise bottle.HTTPError(400, '{"error": "invalid search"}')
    else:
        if start is not None and size is not None:
            return c.jsonify(v3to2(data[start:start+size]))
        return c.jsonify(v3to2(data))
示例#3
0
def search(field=None, action=None, value=None):
    '''Plugin search
    A generalized search system that accepts both single-criteria get requests
    as well as multi-criteria posts.
    '''
    fields = ['slug',]
    start = c.sint(bleach.clean(request.query.start or None))
    size = c.sint(bleach.clean(request.query.size or None))
    sort = bleach.clean(request.query.sort or 'slug')
    field = bleach.clean(field)
    value = bleach.clean(value)
    filters = [
        {'field': field, 'action': action, 'value': value}
    ]
    try:
        data = c.plugin_search(filters, fields, sort)
    except:
        raise bottle.HTTPError(400, '{"error": "invalid search"}')
    else:
        if start is not None and size is not None:
            return c.jsonify([a['slug'] for a in data[start:start+size]])
        return c.jsonify([a['slug'] for a in data])