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) }}%