From 206c1acee4cc7c76edaa7871edaf8c9803a1320d Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 19 Jun 2020 18:08:35 -0500 Subject: [PATCH] implemented refresh with custom namedtuple json serialization workaround, changed switch to jsonify --- trivia/api.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/trivia/api.py b/trivia/api.py index 7626669..949cfc4 100644 --- a/trivia/api.py +++ b/trivia/api.py @@ -5,7 +5,7 @@ Handles backend routes assisting """ import json -from flask import request +from flask import request, jsonify, make_response from trivia import app from trivia.utils import lastModified @@ -23,7 +23,7 @@ def changed(): """ from trivia.utils import lastChange time = int(request.args.get('last') or lastModified()) - return json.dumps(lastChange < time) + return jsonify(lastChange < time) @app.route("/api/refresh") @@ -32,3 +32,8 @@ def refresh(): """ Used for refreshing client-side table data. Returns a JSON response with all data necessary to build the table. """ + from trivia.utils import teams + r = make_response(json.dumps([team._asdict() for team in teams])) + print(r) + r.mimetype = 'application/json' + return r