From 078636cfc6d8b76064ad4a8d1dbe4023749342ad Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 15 Mar 2021 21:40:12 +0100 Subject: preferences working again :tada: --- api/user/preferences.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/api/user/preferences.py b/api/user/preferences.py index cb3bf5e..057bf41 100644 --- a/api/user/preferences.py +++ b/api/user/preferences.py @@ -4,18 +4,16 @@ from auth.login_token import token_login from ruleset import resolve_ruleset import json -class preferences_class: - def __init__(self, preferences): - self.darkMode = preferences.get("darkMode") or False - self.ruleset = resolve_ruleset(json.dumps(preferences.get("ruleset") or {}) or "default") - self.userColors = { - "diskA": preferences.get("userColors", {}).get("diskA") or "", - "diskB": preferences.get("userColors", {}).get("diskB") or "", - "background": preferences.get("userColors", {}).get("background") or "" - } - def format_preferences(prefs): - return json.dumps((preferences_class(prefs)).__dict__) + return { + "darkMode": prefs.get("darkMode") or False, + "ruleset": resolve_ruleset(json.dumps(prefs.get("ruleset") or {}) or "default"), + "userColors": { + "diskA": prefs.get("userColors", {}).get("diskA") or "", + "diskB": prefs.get("userColors", {}).get("diskB") or "", + "background": prefs.get("userColors", {}).get("background") or "" + } + } preferences = Blueprint('preferences', __name__) @@ -45,15 +43,9 @@ def index(): if not login: return "", 403 - preferences_json = {} - try: - preferences_json = json.loads(new_preferences) - except ValueError as e: - return "", 400 - - formatted_json = format_preferences(preferences_json) + formatted_json = format_preferences(new_preferences) - cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login]) + cursor.execute("update users set preferences = ? where user_id = ?", [json.dumps(formatted_json), login]) connection.commit() return "", 200 -- cgit v1.2.3