forked from rDrama/rDrama
1
0
Fork 0

thing -> obj in /votes

master
Aevann 2023-10-29 15:05:47 +03:00
parent 1d477b5c72
commit b10d981609
2 changed files with 69 additions and 74 deletions

View File

@ -190,28 +190,28 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
@auth_required @auth_required
def vote_info_get(v, link): def vote_info_get(v, link):
try: try:
if "p_" in link: thing = get_post(int(link.split("p_")[1]), v=v) if "p_" in link: obj = get_post(int(link.split("p_")[1]), v=v)
elif "c_" in link: thing = get_comment(int(link.split("c_")[1]), v=v) elif "c_" in link: obj = get_comment(int(link.split("c_")[1]), v=v)
else: abort(400) else: abort(400)
except: abort(400) except: abort(400)
if thing.ghost and v.admin_level < PERMS['SEE_GHOST_VOTES']: if obj.ghost and v.admin_level < PERMS['SEE_GHOST_VOTES']:
abort(403) abort(403)
if thing.author.shadowbanned and not (v and v.can_see_shadowbanned): if obj.author.shadowbanned and not (v and v.can_see_shadowbanned):
abort(500) abort(500)
if isinstance(thing, Post): if isinstance(obj, Post):
query = g.db.query(Vote).join(Vote.user).filter( query = g.db.query(Vote).join(Vote.user).filter(
Vote.post_id == thing.id, Vote.post_id == obj.id,
).order_by(Vote.created_utc) ).order_by(Vote.created_utc)
ups = query.filter(Vote.vote_type == 1).all() ups = query.filter(Vote.vote_type == 1).all()
downs = query.filter(Vote.vote_type == -1).all() downs = query.filter(Vote.vote_type == -1).all()
elif isinstance(thing, Comment): elif isinstance(obj, Comment):
query = g.db.query(CommentVote).join(CommentVote.user).filter( query = g.db.query(CommentVote).join(CommentVote.user).filter(
CommentVote.comment_id == thing.id, CommentVote.comment_id == obj.id,
).order_by(CommentVote.created_utc) ).order_by(CommentVote.created_utc)
ups = query.filter(CommentVote.vote_type == 1).all() ups = query.filter(CommentVote.vote_type == 1).all()
@ -221,7 +221,7 @@ def vote_info_get(v, link):
return render_template("votes.html", return render_template("votes.html",
v=v, v=v,
thing=thing, obj=obj,
ups=ups, ups=ups,
downs=downs) downs=downs)

View File

@ -1,72 +1,67 @@
{% extends "default.html" %} {% extends "default.html" %}
{% block pagetitle %}Votes on {{thing.shortlink}}{% endblock %} {% block pagetitle %}Votes on {{obj.shortlink}}{% endblock %}
{% block content %} {% block content %}
{% if thing %} {% if obj %}
<h1 class="mt-2">Info</h1> <h1 class="mt-2">Info</h1>
<p><a href="{{thing.permalink}}">{{thing.permalink}}</a></p> <p><a href="{{obj.permalink}}">{{obj.permalink}}</a></p>
<p><b>Author:</b> <a href="{{thing.author.url}}">@{{thing.author.username}}</a></p> <p><b>Author:</b> <a href="{{obj.author.url}}">@{{obj.author.username}}</a></p>
<p><b>Author Created At:</b> <span data-time="{{thing.author.created_utc}}"></span></p> <p><b>Author Created At:</b> <span data-time="{{obj.author.created_utc}}"></span></p>
<p><b>Author Truescore:</b> {{"{:,}".format(thing.author.truescore)}}</p> <p><b>Author Truescore:</b> {{"{:,}".format(obj.author.truescore)}}</p>
<p><b>Upvotes: </b>{{ups | length}}</p> <p><b>Upvotes: </b>{{ups | length}}</p>
<p><b>Downvotes: </b>{{downs | length}}</p> <p><b>Downvotes: </b>{{downs | length}}</p>
<h2>Upvotes</h2> <h2>Upvotes</h2>
<div class="overflow-x-auto"> <div class="overflow-x-auto">
<table class="table table-striped mb-5"> <table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th>#</th> <th>#</th>
<th>User</th> <th>User</th>
<th>User Truescore</th> <th>User Truescore</th>
<th>Vote Time</th> <th>Vote Time</th>
</tr> </tr>
</thead> </thead>
{% for vote in ups %} {% for vote in ups %}
<tr> <tr>
<td>{{loop.index}}</td> <td>{{loop.index}}</td>
<td> <td>
{% with user=vote.user %} {% with user=vote.user %}
{% include "user_in_table.html" %} {% include "user_in_table.html" %}
{% endwith %} {% endwith %}
</td> </td>
<td>{{"{:,}".format(vote.user.truescore)}}</td> <td>{{"{:,}".format(vote.user.truescore)}}</td>
<td {% if vote.created_utc > 1599343262 %}data-time="{{vote.created_utc}}"{% endif %}></td> <td {% if vote.created_utc > 1599343262 %}data-time="{{vote.created_utc}}"{% endif %}></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
<h2>Downvotes</h2>
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>User</th>
<th>User Truescore</th>
<th>Vote Time</th>
</tr>
</thead>
{% for vote in downs %}
<tr>
<td>{{loop.index}}</td>
<td>
{% with user=vote.user %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{"{:,}".format(vote.user.truescore)}}</td>
<td {% if vote.created_utc > 1599343262 %}data-time="{{vote.created_utc}}"{% endif %}></td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
<h2>Downvotes</h2>
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>User</th>
<th>User Truescore</th>
<th>Vote Time</th>
</tr>
</thead>
{% for vote in downs %}
<tr>
<td>{{loop.index}}</td>
<td>
{% with user=vote.user %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{"{:,}".format(vote.user.truescore)}}</td>
<td {% if vote.created_utc > 1599343262 %}data-time="{{vote.created_utc}}"{% endif %}></td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
{% endblock %} {% endblock %}