Merge branch 'master' into live

This commit is contained in:
Kevin Morris 2022-02-04 18:49:10 -08:00
commit 2ccef3ac27
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 21 additions and 12 deletions

View file

@ -5,7 +5,7 @@ from http import HTTPStatus
from fastapi import APIRouter, Form, HTTPException, Request from fastapi import APIRouter, Form, HTTPException, Request
from fastapi.responses import RedirectResponse, Response from fastapi.responses import RedirectResponse, Response
from sqlalchemy import and_, or_ from sqlalchemy import and_, func, or_
from aurweb import db, l10n, logging, models, time from aurweb import db, l10n, logging, models, time
from aurweb.auth import creds, requires_auth from aurweb.auth import creds, requires_auth
@ -80,18 +80,21 @@ async def trusted_user(request: Request,
if past_by == "asc" else past_votes.all() if past_by == "asc" else past_votes.all()
context["past_off"] = past_off context["past_off"] = past_off
# TODO last_vote = func.max(models.TUVote.VoteID).label("LastVote")
# We order last votes by TUVote.VoteID and User.Username. last_votes_by_tu = db.query(models.TUVote).join(
# This is really bad. We should add a Created column to models.User
# TUVote of type Timestamp and order by that instead. ).join(models.TUVoteInfo).filter(
last_votes_by_tu = db.query(models.TUVote).filter(
and_(models.TUVote.VoteID == models.TUVoteInfo.ID, and_(models.TUVote.VoteID == models.TUVoteInfo.ID,
models.User.ID == models.TUVote.UserID,
models.TUVoteInfo.End <= ts, models.TUVoteInfo.End <= ts,
models.TUVote.UserID == models.User.ID,
or_(models.User.AccountTypeID == 2, or_(models.User.AccountTypeID == 2,
models.User.AccountTypeID == 4)) models.User.AccountTypeID == 4))
).group_by(models.User.ID).order_by( ).with_entities(
models.TUVote.VoteID.desc(), models.User.Username.asc()) models.TUVote.UserID,
func.max(models.TUVote.VoteID).label("LastVote"),
models.User.Username
).group_by(models.TUVote.UserID).order_by(
last_vote.desc(), models.User.Username.asc())
context["last_votes_by_tu"] = last_votes_by_tu.all() context["last_votes_by_tu"] = last_votes_by_tu.all()
context["current_by_next"] = "asc" if current_by == "desc" else "desc" context["current_by_next"] = "asc" if current_by == "desc" else "desc"

View file

@ -18,10 +18,14 @@
{% else %} {% else %}
{% for vote in votes %} {% for vote in votes %}
<tr> <tr>
<td>{{ vote.User.Username }}</td>
<td> <td>
<a href="/tu/{{ vote.VoteID }}"> <a href="/account/{{ vote.Username }}">
{{ vote.VoteID }} {{ vote.Username }}
</a>
</td>
<td>
<a href="/tu/{{ vote.LastVote }}">
{{ vote.LastVote }}
</a> </a>
</td> </td>
</tr> </tr>

View file

@ -251,6 +251,7 @@ def test_tu_index(client, tu_user):
# Check to see the rows match up to our user and related vote. # Check to see the rows match up to our user and related vote.
username, vote_id = rows[0] username, vote_id = rows[0]
username = username.xpath("./a")[0]
vote_id = vote_id.xpath("./a")[0] vote_id = vote_id.xpath("./a")[0]
assert username.text.strip() == tu_user.Username assert username.text.strip() == tu_user.Username
assert int(vote_id.text.strip()) == vote_records[1].ID assert int(vote_id.text.strip()) == vote_records[1].ID
@ -464,6 +465,7 @@ def test_tu_index_last_votes(client, tu_user, user):
last_vote = rows[0] last_vote = rows[0]
user, vote_id = last_vote.xpath("./td") user, vote_id = last_vote.xpath("./td")
user = user.xpath("./a")[0]
vote_id = vote_id.xpath("./a")[0] vote_id = vote_id.xpath("./a")[0]
assert user.text.strip() == tu_user.Username assert user.text.strip() == tu_user.Username