Fix crash on review votes page

This commit is contained in:
rubenwardy 2023-11-19 13:49:36 +00:00
parent 2e8ddb8ca4
commit 12664a4f41
2 changed files with 6 additions and 7 deletions

@ -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)

@ -77,11 +77,8 @@
<span class="btn" title="{{ _('Reviews') }}">
<i class="fas fa-star-half-alt"></i>
<span class="count">
+{{ 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] }}
</span>
</span>
</div>