From 12664a4f41246a1cbc6a4591b1b8ba96e3fafb4b Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 19 Nov 2023 13:49:36 +0000 Subject: [PATCH] Fix crash on review votes page --- app/blueprints/packages/reviews.py | 6 ++++-- app/templates/index.html | 7 ++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/blueprints/packages/reviews.py b/app/blueprints/packages/reviews.py index 133f5a2a..a3d0ba75 100644 --- a/app/blueprints/packages/reviews.py +++ b/app/blueprints/packages/reviews.py @@ -245,15 +245,17 @@ def review_votes(package): else: user_biases[vote.user.username][1] += 1 + reviews = package.reviews.all() + BiasInfo = namedtuple("BiasInfo", "username balance with_ against no_vote perc_with") user_biases_info = [] for username, bias in user_biases.items(): total_votes = bias[0] + bias[1] balance = bias[0] - bias[1] perc_with = round((100 * bias[0]) / total_votes) - user_biases_info.append(BiasInfo(username, balance, bias[0], bias[1], len(package.reviews) - total_votes, perc_with)) + user_biases_info.append(BiasInfo(username, balance, bias[0], bias[1], len(reviews) - total_votes, perc_with)) user_biases_info.sort(key=lambda x: -abs(x.balance)) - return render_template("packages/review_votes.html", package=package, reviews=package.reviews, + return render_template("packages/review_votes.html", package=package, reviews=reviews, user_biases=user_biases_info) diff --git a/app/templates/index.html b/app/templates/index.html index 89fa4665..946dc084 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -77,11 +77,8 @@ - +{{ package.reviews | selectattr("rating", "equalto", 5) | list | length }} - / - {{ package.reviews | selectattr("rating", "equalto", 3) | list | length }} - / - -{{ package.reviews | selectattr("rating", "equalto", 1) | list | length }} + {% set summary = package.get_review_summary() %} + +{{ summary[0] }} / {{ summary[1] }} / -{{ summary[2] }}