thing -> obj in /votes

pull/216/head
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
def vote_info_get(v, link):
try:
if "p_" in link: thing = get_post(int(link.split("p_")[1]), v=v)
elif "c_" in link: thing = get_comment(int(link.split("c_")[1]), v=v)
if "p_" in link: obj = get_post(int(link.split("p_")[1]), v=v)
elif "c_" in link: obj = get_comment(int(link.split("c_")[1]), v=v)
else: 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)
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)
if isinstance(thing, Post):
if isinstance(obj, Post):
query = g.db.query(Vote).join(Vote.user).filter(
Vote.post_id == thing.id,
Vote.post_id == obj.id,
).order_by(Vote.created_utc)
ups = 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(
CommentVote.comment_id == thing.id,
CommentVote.comment_id == obj.id,
).order_by(CommentVote.created_utc)
ups = query.filter(CommentVote.vote_type == 1).all()
@ -221,7 +221,7 @@ def vote_info_get(v, link):
return render_template("votes.html",
v=v,
thing=thing,
obj=obj,
ups=ups,
downs=downs)

View File

@ -1,72 +1,67 @@
{% extends "default.html" %}
{% block pagetitle %}Votes on {{thing.shortlink}}{% endblock %}
{% block pagetitle %}Votes on {{obj.shortlink}}{% endblock %}
{% block content %}
{% if thing %}
<h1 class="mt-2">Info</h1>
<p><a href="{{thing.permalink}}">{{thing.permalink}}</a></p>
<p><b>Author:</b> <a href="{{thing.author.url}}">@{{thing.author.username}}</a></p>
<p><b>Author Created At:</b> <span data-time="{{thing.author.created_utc}}"></span></p>
<p><b>Author Truescore:</b> {{"{:,}".format(thing.author.truescore)}}</p>
<p><b>Upvotes: </b>{{ups | length}}</p>
<p><b>Downvotes: </b>{{downs | length}}</p>
{% if obj %}
<h1 class="mt-2">Info</h1>
<p><a href="{{obj.permalink}}">{{obj.permalink}}</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="{{obj.author.created_utc}}"></span></p>
<p><b>Author Truescore:</b> {{"{:,}".format(obj.author.truescore)}}</p>
<p><b>Upvotes: </b>{{ups | length}}</p>
<p><b>Downvotes: </b>{{downs | length}}</p>
<h2>Upvotes</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>
<h2>Upvotes</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 ups %}
<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>
<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 %}
{% for vote in ups %}
<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>
<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 %}