aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-15 21:40:12 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-15 21:40:12 +0100
commit078636cfc6d8b76064ad4a8d1dbe4023749342ad (patch)
treeef9d701ac5a301480ae2b5153fcc0f2dc1ca5a44
parent1c5ee061f745b6ea1ea584a0047c99e88a5d3fcb (diff)
preferences working again :tada:
-rw-r--r--api/user/preferences.py30
1 files 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