From 0689565dedbc78c3422001af711d07308a85c8ae Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 23 Apr 2022 21:31:59 +0100 Subject: [PATCH] Fix crash on mentioning user --- app/blueprints/threads/__init__.py | 4 ++-- app/blueprints/users/profile.py | 5 ++++- app/templates/macros/threads.html | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py index 5bdc3832..acc7a6d7 100644 --- a/app/blueprints/threads/__init__.py +++ b/app/blueprints/threads/__init__.py @@ -240,7 +240,7 @@ def view(id): thread.watchers.append(current_user) for mentioned_username in get_user_mentions(render_markdown(comment)): - mentioned = User.query.filter_by(username=mentioned_username) + mentioned = User.query.filter_by(username=mentioned_username).first() if mentioned is None: continue @@ -343,7 +343,7 @@ def new(): package.review_thread = thread for mentioned_username in get_user_mentions(render_markdown(form.comment.data)): - mentioned = User.query.filter_by(username=mentioned_username) + mentioned = User.query.filter_by(username=mentioned_username).first() if mentioned is None: continue diff --git a/app/blueprints/users/profile.py b/app/blueprints/users/profile.py index 8bbb1287..a3f72e88 100644 --- a/app/blueprints/users/profile.py +++ b/app/blueprints/users/profile.py @@ -66,6 +66,9 @@ class Medal: @classmethod def make_locked(cls, description: str, progress: Tuple[int, int]): + if progress[0] is None or progress[1] is None: + raise Exception("Invalid progress") + return Medal(description=description, progress=progress) @@ -127,7 +130,7 @@ def get_user_medals(user: User) -> Tuple[List[Medal], List[Medal]]: unlocked.append(Medal.make_unlocked( place_to_color(review_idx + 1), "fa-star-half-alt", title, description)) - else: + elif review_boundary is not None: description = gettext(u"Consider writing more helpful reviews to get a medal.") if review_idx: description += " " + gettext(u"You are in place %(place)s.", place=review_idx + 1) diff --git a/app/templates/macros/threads.html b/app/templates/macros/threads.html index 518f1fa9..fe833f23 100644 --- a/app/templates/macros/threads.html +++ b/app/templates/macros/threads.html @@ -162,6 +162,11 @@ {% endif %} + {% if thread.private %} +

+ {{ _("You can add someone to a private thread by writing @username.") }} +

+ {% endif %}