forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-09-01 21:03:05 +02:00
parent 05b7438e1d
commit a7ada023c9
3 changed files with 48 additions and 0 deletions

View File

@ -347,6 +347,18 @@ class User(Base, Stndrd, Age_times):
return sorted(list(awards.values()), key=lambda x: x['kind'], reverse=True)
@property
@lazy
def received_awards_num(self):
posts_idlist = g.db.query(Submission.id).filter_by(author_id=self.id).subquery()
comments_idlist = g.db.query(Comment.id).filter_by(author_id=self.id).subquery()
post_awards = g.db.query(AwardRelationship).filter(AwardRelationship.submission_id.in_(posts_idlist)).count()
comment_awards = g.db.query(AwardRelationship).filter(AwardRelationship.comment_id.in_(comments_idlist)).count()
return post_awards + comment_awards
@property
@lazy
def post_notifications_count(self):

View File

@ -142,6 +142,13 @@ def leaderboard(v):
users4 = users.order_by(User.comment_count.desc()).limit(10).all()
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4)
@app.get("/award_leaderboard")
@auth_desired
def award_leaderboard(v):
users = g.db.query(User).options(lazyload('*')).all()
users = sorted(users, key=lambda x: x.received_awards_num)
return render_template("award_leaderboard.html", v=v, users=users)
@app.get("/@<username>/css")
def get_css(username):
user = get_user(username)

View File

@ -0,0 +1,29 @@
{% extends "settings2.html" %}
{% block pagetitle %}Leaderboard{% endblock %}
{% block content %}
<pre class="d-none d-md-inline-block"></pre>
<h5 style="font-weight:bold;text-align: center;">Top 10 by awards received</h5>
<pre></pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th style="font-weight:bold;">#</th>
<th style="font-weight:bold;">Name</th>
<th style="font-weight:bold; text-align:right;">Coins</th>
</tr>
</thead>
{% for user in users %}
<tr>
<td style="font-weight:bold;">{{users.index(user)+1}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img src="/uid/{{user.id}}/pic/profile" class="profile-pic-20 mr-1"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.received_awards_num}}</td>
</tr>
{% endfor %}
</table>
<pre>
</pre>
{% endblock %}