Esempio n. 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)
Esempio n. 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))
Esempio n. 3
0
def plugin_list(server=None):
    '''Plugin Listing
    Returns the plugin listing.  Can optionally be limited to a specific server
    binary compatability type.
    '''
    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')
    data = c.list_plugins(server, fields, sort)
    if size is not None and start is not None:
        return c.jsonify(data[start:start+size])
    return c.jsonify(data)
Esempio n. 4
0
def category_plugins(name, server=None):
    '''Category Plugin listing
    returns the list of plugins that match a specific category.  Optionally a
    specific server binary compatability can be specified.
    '''
    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')
    data = c.list_category_plugins(server, name, fields, sort)
    if size is not None and start is not None:
        return c.jsonify(data[start:start+size])
    return c.jsonify(data)
Esempio n. 5
0
def author_plugins(name, server=None):
    '''Author Plugin Listing
    Returns the plugins associated with a specific author.  Optionally can also
    be restricted to a specific server binary compatability.
    '''
    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')
    data = c.list_author_plugins(server, name, fields, sort)
    if size is not None and start is not None:
        return c.jsonify(data[start:start+size])
    return c.jsonify(data)
Esempio n. 6
0
def generation_info():
    '''Generation Information
    Returns the generation information as requested.  User can optionall request
    to look X number of versions back.
    '''
    size = c.sint(bleach.clean(request.query.size or None))
    return c.jsonify(c.list_geninfo(size))
Esempio n. 7
0
def plugin_details(server, slug, version=None):
    '''Plugin Details 
    Returns the document for a specific plugin.  Optionally can return only a
    specific version as part of the data as well.
    '''
    fields = bleach.clean(request.query.fields or '').split(',')
    size = c.sint(bleach.clean(request.query.size or None))
    data = c.plugin_details(server, slug, version, fields)
    if size is not None:
        data['versions'] = data['versions'][:size]
    return c.jsonify(data)
Esempio n. 8
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])