From b36f085a51937a840978c420f99d554f88fb5a40 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 22 Mar 2022 02:01:21 +0200 Subject: [PATCH] vote relationships --- files/routes/users.py | 165 +++++++++++++++++++ files/templates/admin/reported_comments.html | 4 +- files/templates/voted_comments.html | 27 +++ files/templates/voted_posts.html | 65 ++++++++ files/templates/voters.html | 4 +- 5 files changed, 262 insertions(+), 3 deletions(-) create mode 100644 files/templates/voted_comments.html create mode 100644 files/templates/voted_posts.html diff --git a/files/routes/users.py b/files/routes/users.py index 6da935e95c..c0405b7b01 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -70,6 +70,169 @@ def leaderboard_thread(): stdout.flush() gevent.spawn(leaderboard_thread()) + + + + + + + + + + + +@app.get("/@/upvoters//posts") +@auth_required +def upvoters_posts(v, username, uid): + id = get_user(username).id + uid = int(uid) + + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [p.id for p in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_posts(listing, v=v) + + return render_template("voted_posts.html", next_exists=next_exists, listing=listing, page=page, v=v) + + +@app.get("/@/upvoters//comments") +@auth_required +def upvoters_comments(v, username, uid): + id = get_user(username).id + uid = int(uid) + + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [c.id for c in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_comments(listing, v=v) + + return render_template("voted_comments.html", next_exists=next_exists, listing=listing, page=page, v=v, standalone=True) + + +@app.get("/@/downvoters//posts") +@auth_required +def downvoters_posts(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [p.id for p in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_posts(listing, v=v) + + return render_template("voted_posts.html", next_exists=next_exists, listing=listing, page=page, v=v) + + +@app.get("/@/downvoters//comments") +@auth_required +def downvoters_comments(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [c.id for c in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_comments(listing, v=v) + + return render_template("voted_comments.html", next_exists=next_exists, listing=listing, page=page, v=v, standalone=True) + + + + + +@app.get("/@/upvoting//posts") +@auth_required +def upvoting_posts(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [p.id for p in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_posts(listing, v=v) + + return render_template("voted_posts.html", next_exists=next_exists, listing=listing, page=page, v=v) + + +@app.get("/@/upvoting//comments") +@auth_required +def upvoting_comments(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [c.id for c in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_comments(listing, v=v) + + return render_template("voted_comments.html", next_exists=next_exists, listing=listing, page=page, v=v, standalone=True) + + +@app.get("/@/downvoting//posts") +@auth_required +def downvoting_posts(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==-1, Vote.user_id==id, Submission.author_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [p.id for p in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_posts(listing, v=v) + + return render_template("voted_posts.html", next_exists=next_exists, listing=listing, page=page, v=v) + + +@app.get("/@/downvoting//comments") +@auth_required +def downvoting_comments(v, username, uid): + id = get_user(username).id + uid = int(uid) + page = max(1, int(request.values.get("page", 1))) + + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==-1, CommentVote.user_id==id, Comment.author_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + + listing = [c.id for c in listing] + next_exists = len(listing) > 25 + listing = listing[:25] + + listing = get_comments(listing, v=v) + + return render_template("voted_comments.html", next_exists=next_exists, listing=listing, page=page, v=v, standalone=True) + + + + + @app.get("/grassed") @auth_required def grassed(v): @@ -108,6 +271,8 @@ def upvoters(v, username): return render_template("voters.html", v=v, users=users[:25], pos=pos, name='Up', name2=f'@{username} biggest simps') + + @app.get("/@/downvoters") @auth_required def downvoters(v, username): diff --git a/files/templates/admin/reported_comments.html b/files/templates/admin/reported_comments.html index fbe556a05e..e9b23d6af5 100644 --- a/files/templates/admin/reported_comments.html +++ b/files/templates/admin/reported_comments.html @@ -1,6 +1,8 @@ {% extends "admin/reported_posts.html" %} - +{% block title %} +Comments +{% endblock %} {% block listing %} diff --git a/files/templates/voted_comments.html b/files/templates/voted_comments.html new file mode 100644 index 0000000000..334b0bc90a --- /dev/null +++ b/files/templates/voted_comments.html @@ -0,0 +1,27 @@ +{% extends "voted_posts.html" %} + + +{% block title %} +Comments +{% endblock %} + +{% block listing %} + + +
+ {% with comments=listing %} + {% include "comments.html" %} + {% endwith %} + {% if not listing %} +
+
+
+
There are no comments here (yet).
+
+
+
+ {% endif %} +
+ +{% endblock %} + diff --git a/files/templates/voted_posts.html b/files/templates/voted_posts.html new file mode 100644 index 0000000000..7a81c2ce39 --- /dev/null +++ b/files/templates/voted_posts.html @@ -0,0 +1,65 @@ +{% extends "userpage.html" %} + +{% block adminpanel %}{% endblock %} +{% block pagetype %}userpage{% endblock %} +{% block banner %}{% endblock %} +{% block mobileBanner %}{% endblock %} +{% block desktopBanner %}{% endblock %} +{% block desktopUserBanner %}{% endblock %} +{% block mobileUserBanner %}{% endblock %} + +{% block fixedMobileBarJS %} +{% endblock %} + +{% block title %} +Posts +{% endblock %} + +{% block content %} + + + +
+ +
+ + {% block listing %} +
+ {% include "submission_listing.html" %} +
+ {% endblock %} +
+
+{% endblock %} + +{% block pagenav %} + +{% endblock %} \ No newline at end of file diff --git a/files/templates/voters.html b/files/templates/voters.html index 9b6cb8ac34..f1eddcc576 100644 --- a/files/templates/voters.html +++ b/files/templates/voters.html @@ -19,14 +19,14 @@ {{loop.index}} {{user[0].username}} - {{user[1]}} + {{user[1]}} {% endfor %} {% if pos and (pos[0] > 25 or not pos[1]) %} {{pos[0]}} {{v.username}} - {{pos[1]}} + {{pod[1]}} {% endif %}