vote relationships

master
Aevann1 2022-03-22 02:01:21 +02:00
parent 9e48134f78
commit b36f085a51
5 changed files with 262 additions and 3 deletions

View File

@ -70,6 +70,169 @@ def leaderboard_thread():
stdout.flush()
gevent.spawn(leaderboard_thread())
@app.get("/@<username>/upvoters/<uid>/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("/@<username>/upvoters/<uid>/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("/@<username>/downvoters/<uid>/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("/@<username>/downvoters/<uid>/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("/@<username>/upvoting/<uid>/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("/@<username>/upvoting/<uid>/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("/@<username>/downvoting/<uid>/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("/@<username>/downvoting/<uid>/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("/@<username>/downvoters")
@auth_required
def downvoters(v, username):

View File

@ -1,6 +1,8 @@
{% extends "admin/reported_posts.html" %}
{% block title %}
<title>Comments</title>
{% endblock %}
{% block listing %}

View File

@ -0,0 +1,27 @@
{% extends "voted_posts.html" %}
{% block title %}
<title>Comments</title>
{% endblock %}
{% block listing %}
<div class="posts">
{% with comments=listing %}
{% include "comments.html" %}
{% endwith %}
{% if not listing %}
<div class="row no-gutters">
<div class="col">
<div class="text-center py-7">
<div class="h4 p-2">There are no comments here (yet).</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock %}

View File

@ -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 %}
<title>Posts</title>
{% endblock %}
{% block content %}
<ul class="nav post-nav py-2">
<li class="nav-item">
<a class="nav-link {% if request.path.endswith('/posts') %}active" href="{{request.path}}"{% else %}" href="{{request.path.replace('comments','posts')}}"{% endif %}>
Posts
</a>
</li>
<li class="nav-item">
<a class="nav-link {% if request.path.endswith('/comments') %}active" href="{{request.path}}"{% else %}" href="{{request.path.replace('posts','comments')}}"{% endif %}>
Comments
</a>
</li>
</ul>
<div class="row no-gutters">
<div class="col">
{% block listing %}
<div class="posts">
{% include "submission_listing.html" %}
</div>
{% endblock %}
</div>
</div>
{% endblock %}
{% block pagenav %}
<nav aria-label="Page navigation">
<ul class="pagination pagination-sm py-3 pl-3 mb-0">
{% if page>1 %}
<li class="page-item">
<small><a class="page-link" href="?page={{page-1}}" tabindex="-1">Prev</a></small>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Prev</span></li>
{% endif %}
{% if next_exists %}
<li class="page-item">
<small><a class="page-link" href="?page={{page+1}}">Next</a></small>
</li>
{% else %}
<li class="page-item disabled"><span class="page-link">Next</span></li>
{% endif %}
</ul>
</nav>
{% endblock %}

View File

@ -19,14 +19,14 @@
<tr {% if v.id == user[0].id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td><a style="color:#{{user[0].namecolor}}" href="/@{{user[0].username}}"><img loading="lazy" src="{{user[0].profile_url}}" class="pp20"><span {% if user[0].patron %}class="patron" style="background-color:#{{user[0].namecolor}}"{% endif %}>{{user[0].username}}</span></a></td>
<td>{{user[1]}}</td>
<td><a href="{{request.path}}/{{user[0].id}}/posts">{{user[1]}}</a></td>
</tr>
{% endfor %}
{% if pos and (pos[0] > 25 or not pos[1]) %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos[0]}}</td>
<td><a style="color:#{{v.namecolor}};font-weight:bold" href="/@{{v.username}}"><img loading="lazy" src="{{v.profile_url}}" class="pp20"><span {% if v.patron %}class="patron" style="background-color:#{{v.namecolor}}"{% endif %}>{{v.username}}</span></a></td>
<td>{{pos[1]}}</td>
<td><a href="{{request.path}}/{{v.id}}/posts">{{pod[1]}}</a></td>
</tr>
{% endif %}
</tbody>