From 7404d94610f00c3bc6215fdc32caf32f3570b4d1 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 5 Sep 2022 22:37:38 +0200 Subject: [PATCH] fix issues for new instances --- files/helpers/get.py | 4 ++-- files/helpers/wrappers.py | 7 +++++-- files/routes/users.py | 2 ++ readme.md | 3 +-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/files/helpers/get.py b/files/helpers/get.py index 76f55e03e..5b8345458 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -89,13 +89,13 @@ def get_users(usernames, graceful=False): return users -def get_account(id, v=None): +def get_account(id, v=None, graceful=False): try: id = int(id) except: abort(404) user = g.db.get(User, id) - if not user: abort(404) + if not user and not graceful: abort(404) if v: block = g.db.query(UserBlock).filter( diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 669710925..0c1661401 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -26,8 +26,11 @@ def get_logged_in_user(): lo_user = session.get("lo_user") if lo_user: id = int(lo_user) - v = get_account(id) - if v: + v = get_account(id, graceful=True) + if not v: + session.clear() + return None + else: nonce = session.get("login_nonce", 0) if nonce < v.login_nonce or v.id != id: abort(401) diff --git a/files/routes/users.py b/files/routes/users.py index 4fdf2106d..95ef62a78 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -30,6 +30,7 @@ def leaderboard_thread(): users9 = [] for user in users8: users9.append((user.id, votes3[user.id])) + if not users9: users9 = [(None,None)] users9 = sorted(users9, key=lambda x: x[1], reverse=True) users9_1, users9_2 = zip(*users9[:25]) @@ -41,6 +42,7 @@ def leaderboard_thread(): users13 = [] for user in users14: users13.append((user.id, votes3[user.id]-user.post_count-user.comment_count)) + if not users13: users13 = [(None,None)] users13 = sorted(users13, key=lambda x: x[1], reverse=True) users13_1, users13_2 = zip(*users13[:25]) diff --git a/readme.md b/readme.md index 9060b56b2..44a7a3017 100644 --- a/readme.md +++ b/readme.md @@ -29,5 +29,4 @@ docker-compose up For returning contributors, we have noticed the following issues (if you can help fix them, we will be very grateful!): 1. Docker doesn't know when we add a new Python dependency, `docker-compose build` is needed. -2. DB schema changes are not applied automatically, the easiest way to deal with that is to delete the entire environment from the Docker GUI and do `docker-compose up`. Also wait five minutes for a "sneed" commit from Aevann meaning that the sql file was regenerated. -3. Old authorization cookies from the previous instance cause a weird 404 error, clear cookies for localhost to fix. +2. DB schema changes are not applied automatically, the easiest way to deal with that is to delete the entire environment from the Docker GUI and do `docker-compose up`. Also wait five minutes for a "sneed" commit from Aevann meaning that the sql file was regenerated. \ No newline at end of file