Example #1
0
def collections():
    # pylint: disable=no-member
    q = Collection.query

    if request.method == 'PUT':
        c = q.get_or_404(Collection.create(_get_json_or_400()))
        return jsonify(collection_to_resource(c)), 201

    # Treat all other methods as "GET"

    # Where do we start?
    page_start = request.args.get('after')

    q = q.with_permission(Permission.READ).order_by(Collection.id)
    if page_start is not None and page_start != '':
        q = q.filter(Collection.id > Collection.decode_key(page_start))
    q = q.limit(current_app.config['PAGE_SIZE'])

    cs = list(q)
    page_end = cs[-1].encoded_key if len(cs) > 0 else page_start

    resources = [collection_to_resource(c) for c in cs]
    next_url = url_for('api.collections', after=page_end)

    return jsonify(dict(
        resources=resources, next=next_url,
    ))
Example #2
0
def collection_delete(key):
    # pylint: disable=no-member
    c = Collection.query.get_for_current_user_or_404(Collection.decode_key(key))
    try:
        c.delete()
    except ModelError:
        raise Unauthorized('no delete permission')
    return redirect(url_for('ui.index'))
Example #3
0
def collection(key):
    # pylint: disable=no-member
    c = Collection.query.get_for_current_user_or_404(
        Collection.decode_key(key)
    )

    resource = dict(name=c.name)

    return jsonify(resource)
Example #4
0
def collection(key):
    # pylint: disable=no-member
    c = Collection.query.get_for_current_user_or_404(Collection.decode_key(key))
    return render_template('collection.html', collection=c)