fix GET /data
Andronaco Marco marco.andronaco@olivetti.com
Thu, 21 Sep 2023 15:07:33 +0200
2 files changed,
34 insertions(+),
3 deletions(-)
A
.vscode/launch.json
@@ -0,0 +1,27 @@
+{ + // Usare IntelliSense per informazioni sui possibili attributi. + // Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti. + // Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Flask", + "type": "python", + "request": "launch", + "module": "flask", + "env": { + "FLASK_APP": "backend_iot", + "FLASK_DEBUG": "1" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload", + "--port=1111", + "--host=0.0.0.0" + ], + "jinja": true, + "justMyCode": true + } + ] +}
M
backend_iot/views.py
→
backend_iot/views.py
@@ -14,11 +14,16 @@ record.timestamp = datetime.now()
record.aqi = get_aqi(current_latitude, current_longitude) return record +def record_to_dict(record): + temp = model_to_dict(record) + del temp["id"] + return temp + def latest_or_abort(): latest = getLatestRecord() if latest is None: return abort(400) - return latest + return record_to_dict(latest) @app.route("/") def index_route():@@ -44,7 +49,6 @@ continue
latest[key] = form[key] new_record = update_record(latest) - temp = model_to_dict(new_record) - del temp["id"] + temp = record_to_dict(new_record) addRecord(**temp) return temp