aboutsummaryrefslogtreecommitdiff
path: root/api/user/preferences.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-11 17:50:58 +0200
commit28f104de9ae9abe4b42abafbf3865ede5687996c (patch)
tree65e651f09d8fbf81380384692e45803cb4f9d61c /api/user/preferences.py
parent7b4859059b3bbabf4139ccdf3270a82c094f5d8e (diff)
dprint yapf python formatting
Diffstat (limited to 'api/user/preferences.py')
-rw-r--r--api/user/preferences.py51
1 files changed, 31 insertions, 20 deletions
diff --git a/api/user/preferences.py b/api/user/preferences.py
index d4e27c9..2feaade 100644
--- a/api/user/preferences.py
+++ b/api/user/preferences.py
@@ -4,38 +4,49 @@ from ruleset import resolve_ruleset
from hierarchy import auth_required
import json
+
# fill missing dict keys in preferences object
def format_preferences(prefs):
- 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 ""
- }
- }
+ 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__)
-@preferences.route('/preferences', methods = ["GET"])
+
+@preferences.route('/preferences', methods=["GET"])
@auth_required("user")
def get_preferences(login):
- user_prefs = cursor.execute("select preferences from users where user_id = ?", [login]).fetchone()
- return { "preferences": format_preferences(json.loads(user_prefs[0])) }, 200
+ user_prefs = cursor.execute(
+ "select preferences from users where user_id = ?", [login]
+ ).fetchone()
+ return {"preferences": format_preferences(json.loads(user_prefs[0]))}, 200
-@preferences.route('/preferences', methods = ["POST"])
+
+@preferences.route('/preferences', methods=["POST"])
@auth_required("user")
def index(login):
- data = request.get_json()
- new_preferences = data.get("newPreferences") or ""
+ data = request.get_json()
+ new_preferences = data.get("newPreferences") or ""
- formatted_json = format_preferences(new_preferences)
+ formatted_json = format_preferences(new_preferences)
- cursor.execute("update users set preferences = ? where user_id = ?", [json.dumps(formatted_json), login])
- connection.commit()
+ cursor.execute(
+ "update users set preferences = ? where user_id = ?",
+ [json.dumps(formatted_json), login]
+ )
+ connection.commit()
- return "", 200
+ return "", 200
-dynamic_route = ["/user", preferences]
+dynamic_route = ["/user", preferences]