From dbfd9adda72aa97dd29898a92818f4587f8e7466 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 17 Apr 2024 22:18:36 +0200 Subject: [PATCH] fix 500 error --- files/routes/awards.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/files/routes/awards.py b/files/routes/awards.py index 3677ee6a0..db140a1a6 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -233,7 +233,19 @@ def award_thing(v, thing_type, id): if kind == 'spider' and author.spider == 1: abort(409, f"{safe_username} already best friends with a spider!") + awards = g.db.query(AwardRelationship).filter( + AwardRelationship.kind == kind, + AwardRelationship.user_id == v.id, + AwardRelationship.post_id == None, + AwardRelationship.comment_id == None + ).order_by(AwardRelationship.id).limit(quantity).all() + num_owned = len(awards) + if quantity > num_owned: + bought = buy_awards(v, kind, AWARDS, quantity-num_owned) + if isinstance(bought, dict): + return bought + awards.extend(bought) if v.id != author.id: if author.deflector and v.deflector and AWARDS[kind]['deflectable']: @@ -271,20 +283,6 @@ def award_thing(v, thing_type, id): can_alter_body = not obj.author.deflector or v == obj.author - awards = g.db.query(AwardRelationship).filter( - AwardRelationship.kind == kind, - AwardRelationship.user_id == v.id, - AwardRelationship.post_id == None, - AwardRelationship.comment_id == None - ).order_by(AwardRelationship.id).limit(quantity).all() - num_owned = len(awards) - - if quantity > num_owned: - bought = buy_awards(v, kind, AWARDS, quantity-num_owned) - if isinstance(bought, dict): - return bought - awards.extend(bought) - for award in awards: if isinstance(obj, Post): award.post_id = obj.id else: award.comment_id = obj.id