예제 #1
0
def update_size_placement(id_):
    chart = Chart.find(id_)
    chart.update(json.loads(request.data))
    chart = Chart.find(id_)

    data = {'result': chart.json_full()}
    return Response(to_json(data))
예제 #2
0
def run_query(id_):
    refresh = request.args.get('refresh')
    refresh = True if refresh and refresh == '1' else False
    chart = Chart.find(id_)
    results = chart.run_query(refresh)

    return Response(to_json({'results': results}))
예제 #3
0
def list_all():
    account_id = auth.get_field_from_jwt(request, 'account_id')
    raw_users = User.get_all_for_account_id(account_id)
    users = [u.json() for u in raw_users]

    data = to_json({'results': users})

    return Response(data)
예제 #4
0
    def run_query(self, refresh=False):
        if not refresh:  # pull from cache
            result = database.redis_get(self.id_)
            if result:
                return json.loads(result)

        dbc = database_connection.DatabaseConnection.find(self.dbc_id)
        result = dbc.run_query(self.query)
        database.redis_set(self.id_, utils.to_json(result))

        return result
예제 #5
0
def get_charts(id_):
    account_id = auth.get_field_from_jwt(request, 'account_id')
    raw_charts = Dashboard.get_all_charts(account_id, id_)
    charts = [c.json_full() for c in raw_charts]

    return Response(utils.to_json({'charts': charts}))
예제 #6
0
def unauthenticated():
    res_json = to_json({'Success': False, 'Error': 'Unauthenticated'})
    return Response(res_json, status=401, mimetype='application/json')
예제 #7
0
def query_success_result(results: list):
    res_json = to_json({'success': True, 'status': 200, 'results': results})

    return Response(res_json, status=200, mimetype='application/json')
예제 #8
0
def success():
    res_json = to_json(dict(Success=True, Status=200))
    return Response(res_json, status=200, mimetype='application/json')
예제 #9
0
def created(record: dict):
    res_json = to_json(dict(Success=True, Status=201, record=record))
    resp = Response(res_json)
    resp.status_code = 201
    resp.mimetype = 'application/json'
    return resp
예제 #10
0
def not_found():
    res_json = to_json({'Success': False, 'Error': 'Not Found'})
    resp = Response(res_json)
    resp.status_code = 404
    resp.mimetype = 'application/json'
    return resp
예제 #11
0
def unauthorized():
    print('returning unauthorized')
    res_json = to_json({'Success': False, 'Error': 'Unauthorized'})
    return Response(res_json, status=403, mimetype='application/json')
예제 #12
0
def get(id_):
    chart = Chart.find(id_)
    if chart:
        return Response(to_json({'record': chart.json_full()}))
    else:
        return http_responses.not_found()