diff --git a/files/routes/admin.py b/files/routes/admin.py index a9016c2c2..c75abd90b 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -16,48 +16,9 @@ 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() -@app.get("/@/upvoters") -@admin_level_required(6) -def upvoters(v, username): - id = g.db.query(User.id).filter(User.username==username).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() - - 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() - - 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, name='Up', name2='simps') - -@app.get("/@/downvoters") -@admin_level_required(6) -def downvoters(v, username): - id = g.db.query(User.id).filter(User.username==username).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() - - 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() - - 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, name='Down', name2='haters') - @app.get("/name//") @admin_level_required(6) @@ -71,7 +32,6 @@ def changename(v, id, name): return "Username changed!" return "User not found!" - @app.get("/coins//") @admin_level_required(6) def addcoins(v, id, coins): diff --git a/files/routes/users.py b/files/routes/users.py index 2f07adada..a642beeaa 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -11,13 +11,49 @@ from files.mail import * from flask import * from files.__main__ import app, limiter from pusher_push_notifications import PushNotifications +from collections import Counter site = environ.get("DOMAIN").strip() -beams_client = PushNotifications( - instance_id=PUSHER_INSTANCE_ID, - secret_key=PUSHER_KEY, -) +beams_client = PushNotifications(instance_id=PUSHER_INSTANCE_ID, secret_key=PUSHER_KEY) + +@app.get("/@/upvoters") +@auth_desired +def upvoters(v, username): + id = g.db.query(User.id).filter(User.username==username).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() + + 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() + + 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, name='Up', name2='simps') + +@app.get("/@/downvoters") +@auth_desired +def downvoters(v, username): + id = g.db.query(User.id).filter(User.username==username).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() + + 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() + + 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, name='Down', name2='haters') @app.post("/pay_rent") @limiter.limit("1/second")