forked from rDrama/rDrama
Leaderboard: fix user join for ea48c46b0f
.
After ea48c46b0f
adds the leaderboard table for most blocked user,
it appeared that the user profile links did not appear correctly.
As such, it was necessary to join on the appropriate information.
This has been (mostly) resolved, excluding the removal of profile
picture because profile_url has logic in Python.
If someone knows SQLAlchemy better than I do, please redo this and
add the profile pictures back into the template. However, I got tired
of fighting with the ORM when I already knew the damn query.
master
parent
ea48c46b0f
commit
42d810a5e7
|
@ -10,6 +10,7 @@ from files.mail import *
|
||||||
from flask import *
|
from flask import *
|
||||||
from files.__main__ import app, limiter, db_session
|
from files.__main__ import app, limiter, db_session
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
from sqlalchemy import text
|
||||||
from pusher_push_notifications import PushNotifications
|
from pusher_push_notifications import PushNotifications
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
import gevent
|
import gevent
|
||||||
|
@ -538,8 +539,10 @@ def leaderboard(v):
|
||||||
sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery()
|
sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery()
|
||||||
pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
|
pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
|
||||||
|
|
||||||
usersBlk = g.db.query(UserBlock.target_id, func.count().label('blocked_by')) \
|
usersBlk = g.db.execute(text('SELECT \
|
||||||
.group_by(UserBlock.target_id).order_by(sqlalchemy.desc('blocked_by')).limit(25).all()
|
blk.target_id, blk.n, users.username, users.namecolor, users.patron \
|
||||||
|
FROM (SELECT target_id, count(target_id) AS n FROM userblocks GROUP BY target_id) AS blk \
|
||||||
|
JOIN users ON users.id = blk.target_id ORDER BY blk.n DESC LIMIT 25'))
|
||||||
|
|
||||||
return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2,
|
return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2,
|
||||||
users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5,
|
users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5,
|
||||||
|
|
|
@ -510,10 +510,10 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for user in usersBlk %}
|
{% for user in usersBlk %}
|
||||||
<tr {% if v.id == user.id %}class="self"{% endif %}>
|
<tr {% if v.id == user.target_id %}class="self"{% endif %}>
|
||||||
<td>{{loop.index}}</td>
|
<td>{{loop.index}}</td>
|
||||||
<td><a style="color:#{{user.namecolor}};font-weight:bold" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
|
<td><a style="color:#{{user.namecolor}};font-weight:bold" href="/@{{user.username}}"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
|
||||||
<td>{{user.blocked_by}}</td>
|
<td>{{user.n}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue