From 6aa4fa2c50d19678966e7ac531b43d8804db29c5 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Sat, 14 Sep 2024 08:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dinner.py | 10 ++++++---- templates/dinner.html | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dinner.py b/src/dinner.py index bb18c4e..e4d883e 100644 --- a/src/dinner.py +++ b/src/dinner.py @@ -104,20 +104,22 @@ def dinner_update(): if not is_valid_user(nickname): return make_response(json.dumps(dict(code=-1, data="你不能投票(*^_^*)"))) if not user_menu: - set_user_menu({}, nickname) + set_user_menu({}, nickname, []) return make_response(json.dumps(dict(code=0, data="OK"))) user_menu = json.loads(user_menu) choice = user_menu['choice'] - dislike = user_menu['dislike'] + dislike = user_menu.get('dislike') + if dislike is None: + dislike = [] # 计算总投票数值 summary = sum(abs(int(value)) for value in choice.values()) if summary <= 0: - set_user_menu({}, nickname) + set_user_menu({}, nickname, dislike) return make_response(json.dumps(dict(code=0, data="OK"))) # 投票数归一化 for key in choice: choice[key] = abs(int(choice[key])) / summary - set_user_menu(choice, nickname) + set_user_menu(choice, nickname, dislike) return make_response(json.dumps(dict(code=0, data="OK"))) diff --git a/templates/dinner.html b/templates/dinner.html index 3e0946a..37dfaf5 100644 --- a/templates/dinner.html +++ b/templates/dinner.html @@ -17,7 +17,7 @@
-
@@ -35,7 +35,7 @@ {{ '{:.2f}'.format((user_menu.menu.get(choice.name) or 0) * 100) }}%