예제 #1
0
파일: web.py 프로젝트: pombredanne/datahub
def handle_exceptions(exc):
    """ Re-format exceptions to JSON if accept requires that. """
    format = response_format(app, request)
    if format == 'json':
        body = {'status': exc.code,
                'name': exc.name,
                'description': exc.get_description(request.environ)}
        return jsonify(body, status=exc.code,
                       headers=exc.get_headers(request.environ))
    return exc
예제 #2
0
파일: web.py 프로젝트: pombredanne/datahub
def handle_invalid(exc):
    format = response_format(app, request)
    if format == 'json':
        body = {'status': 400,
                'name': 'Invalid Data',
                'description': unicode(exc),
                'errors': exc.unpack_errors()}
        return jsonify(body, status=400)
    return Response(repr(exc.unpack_errors()), status=400, 
                    mimetype='text/plain')
예제 #3
0
def handle_invalid(exc):
    format = response_format(app, request)
    if format == 'json':
        body = {
            'status': 400,
            'name': 'Invalid Data',
            'description': unicode(exc),
            'errors': exc.unpack_errors()
        }
        return jsonify(body, status=400)
    return Response(repr(exc.unpack_errors()),
                    status=400,
                    mimetype='text/plain')
예제 #4
0
def handle_exceptions(exc):
    """ Re-format exceptions to JSON if accept requires that. """
    format = response_format(app, request)
    if format == 'json':
        body = {
            'status': exc.code,
            'name': exc.name,
            'description': exc.get_description(request.environ)
        }
        return jsonify(body,
                       status=exc.code,
                       headers=exc.get_headers(request.environ))
    return exc
예제 #5
0
def index(owner):
    """ List all the datasets of a particular user. """
    result = logic.dataset.list_by_owner(owner)
    return jsonify(list(result))
예제 #6
0
def update(owner, resource):
    """ Update the data of the resource. """
    data = request_content(request)
    resource = logic.resource.update(owner, resource, data)
    return jsonify(resource)
예제 #7
0
def get(owner, resource):
    """ Get a JSON representation of the resource. """
    resource = logic.resource.find(owner, resource)
    return jsonify(resource)
예제 #8
0
def stream(type, id):
    """ Get the latest events on the given event stream. """
    events = logic.event.latest_by_stream(type, id)
    events = Pager(events, '.stream', request.args, limit=50,
                   type=type, id=id)
    return jsonify(events)
예제 #9
0
def get(owner, resource):
    """ Get a JSON representation of the resource. """
    resource = logic.resource.find(owner, resource)
    return jsonify(resource)
예제 #10
0
def update(owner, dataset):
    """ Update the data of the dataset. """
    data = request_content(request)
    dataset = logic.dataset.update(owner, dataset, data)
    return jsonify(dataset)
예제 #11
0
def resources_get(owner, dataset):
    """ Get a JSON representation of the resources in this dataset. """
    resources = logic.dataset.list_resources(owner, dataset)
    return jsonify(resources)
예제 #12
0
def get(owner, dataset):
    """ Get a JSON representation of the dataset. """
    dataset = logic.dataset.find(owner, dataset)
    return jsonify(dataset)
예제 #13
0
def get(account):
    """ Get a JSON representation of the account. """
    account = logic.account.find(account)
    return jsonify(account)
예제 #14
0
def update(account):
    """ Update the data of the account profile. """
    data = request_content(request)
    account = logic.account.update(account, data)
    return jsonify(account)
예제 #15
0
def get(event):
    """ Get a JSON representation of the event. """
    event = logic.event.find(event)
    return jsonify(event)
예제 #16
0
def get(owner, dataset):
    """ Get a JSON representation of the dataset. """
    dataset = logic.dataset.find(owner, dataset)
    return jsonify(dataset)
예제 #17
0
def resources_get(owner, dataset):
    """ Get a JSON representation of the resources in this dataset. """
    resources = logic.dataset.list_resources(owner, dataset)
    return jsonify(resources)
예제 #18
0
def update(owner, dataset):
    """ Update the data of the dataset. """
    data = request_content(request)
    dataset = logic.dataset.update(owner, dataset, data)
    return jsonify(dataset)
예제 #19
0
def index(owner):
    """ List all the resources of a particular user. """
    result = logic.resource.list_by_owner(owner)
    return jsonify(list(result))
예제 #20
0
def index(owner):
    """ List all the datasets of a particular user. """
    result = logic.dataset.list_by_owner(owner)
    return jsonify(list(result))
예제 #21
0
def update(owner, resource):
    """ Update the data of the resource. """
    data = request_content(request)
    resource = logic.resource.update(owner, resource, data)
    return jsonify(resource)
예제 #22
0
def apiroot():
    return jsonify({
        'api': 'ok',
        'version': 1,
        'site_id': app.config.get('SITE_ID', 'datahub.local')
    })
예제 #23
0
def index(owner):
    """ List all the resources of a particular user. """
    result = logic.resource.list_by_owner(owner)
    return jsonify(list(result))
예제 #24
0
def apiroot():
    return jsonify({'api': 'ok', 
                    'version': 1, 
                    'site_id': app.config.get('SITE_ID', 'datahub.local')
                    })