Add package downloads badge to profile page

This commit is contained in:
rubenwardy 2021-07-25 16:35:08 +01:00
parent 29bfc91683
commit 94568c851a
2 changed files with 43 additions and 1 deletions

@ -58,6 +58,7 @@ def profile(username):
.select_from(User).join(PackageReview) \
.group_by(User.username).order_by(text("count DESC")).all()
users_by_reviews = [ username for username, _ in users_by_reviews ]
review_idx = None
review_percent = None
try:
@ -66,9 +67,14 @@ def profile(username):
except ValueError:
pass
total_downloads = db.session.query(func.sum(Package.downloads)) \
.select_from(User) \
.join(User.maintained_packages) \
.filter(User.id == user.id, Package.state == PackageState.APPROVED).scalar()
# Process GET or invalid POST
return render_template("users/profile.html", user=user, packages=packages,
review_idx=review_idx, review_percent=review_percent)
total_downloads=total_downloads, review_idx=review_idx, review_percent=review_percent)
@bp.route("/users/<username>/check/", methods=["POST"])

@ -180,6 +180,42 @@
</span>
</div>
{% endif %}
{% if total_downloads >= 50000 %}
{% if total_downloads >= 300000 %}
{% set badge_color = "gold" %}
{% elif total_downloads >= 100000 %}
{% set badge_color = "#888" %}
{% elif total_downloads >= 75000 %}
{% set badge_color = "#cd7f32" %}
{% else %}
{% set badge_color = "white" %}
{% endif %}
<div class="col-md-4">
<div class="card">
<div class="card-body media align-items-center">
<i class="fas fa-users ml-2 mr-4 text-size" style="font-size: 45px; color: {{ badge_color }};"></i>
<div class="media-body">
<h5 class="mt-0">
{% if total_downloads >= 300000 %}
{{ _(">300k downloads") }}
{% elif total_downloads >= 100000 %}
{{ _(">100k downloads") }}
{% elif total_downloads >= 75000 %}
{{ _(">75k downloads") }}
{% else %}
{{ _(">50k downloads") }}
{% endif %}
</h5>
<p class="my-0">
{{ _("Has received %(downloads)d downloads across all packages.",
display_name=user.display_name, downloads=total_downloads) }}
</p>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% if current_user == user or user.checkPerm(current_user, "CHANGE_AUTHOR") %}