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))
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}))
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)
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
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}))
def unauthenticated(): res_json = to_json({'Success': False, 'Error': 'Unauthenticated'}) return Response(res_json, status=401, mimetype='application/json')
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')
def success(): res_json = to_json(dict(Success=True, Status=200)) return Response(res_json, status=200, mimetype='application/json')
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
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
def unauthorized(): print('returning unauthorized') res_json = to_json({'Success': False, 'Error': 'Unauthorized'}) return Response(res_json, status=403, mimetype='application/json')
def get(id_): chart = Chart.find(id_) if chart: return Response(to_json({'record': chart.json_full()})) else: return http_responses.not_found()