remotes/1693045480750635534/spooky-22
Aevann1 2021-11-15 03:01:23 +02:00
parent 387bcc2233
commit e9050b5fbb
2 changed files with 15 additions and 7 deletions

View File

@ -16,6 +16,7 @@ from flask import *
from files.__main__ import app, cache, limiter
from .front import frontlist
from files.helpers.discord import add_role
from collections import Counter
SITE_NAME = environ.get("SITE_NAME", "").strip()
@ -24,16 +25,21 @@ SITE_NAME = environ.get("SITE_NAME", "").strip()
def votes2(v, id):
try: id = int(id)
except: abort(400)
username = g.db.query(User.username).filter(User.id==7).first()[0]
votes = g.db.query(Vote.user_id, func.count(Vote.user_id)).join(Submission, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Submission.author_id==id).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).limit(25).all()
voters=[x[0] for x in votes]
counts=[x[1] for x in votes]
users = g.db.query(User).filter(User.id.in_(voters)).all()
users = sorted(users, key=lambda x: voters.index(x.id))
users2 = []
for idx, user in enumerate(users): users2.append((user, counts[idx]))
votes2 = g.db.query(CommentVote.user_id, func.count(CommentVote.user_id)).join(Comment, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, Comment.author_id==id).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).limit(25).all()
return render_template("upvoters.html", v=v, users=users2)
votes = Counter(dict(votes)) + Counter(dict(votes2))
users = g.db.query(User).filter(User.id.in_(votes.keys())).all()
users2 = []
for user in users: users2.append((user, votes[user.id]))
users = sorted(users2, key=lambda x: x[1], reverse=True)
return render_template("upvoters.html", v=v, users=users, username=username)
@app.get("/name/<id>/<name>")

View File

@ -4,6 +4,8 @@
</pre>
<h5>@{{username}}'s biggest simps</h5>
<pre></pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>