diff --git a/aurweb/routers/accounts.py b/aurweb/routers/accounts.py index b3203356..152b0a15 100644 --- a/aurweb/routers/accounts.py +++ b/aurweb/routers/accounts.py @@ -624,6 +624,22 @@ async def account(request: Request, username: str): return render_template(request, "account/show.html", context) +@router.get("/account/{username}/comments") +@auth_required(redirect="/account/{username}/comments") +async def account_comments(request: Request, username: str): + user = db.query(models.User).filter( + models.User.Username == username + ).first() + if not user: + raise HTTPException(status_code=HTTPStatus.NOT_FOUND) + + context = make_context(request, "Accounts") + context["username"] = username + context["comments"] = user.package_comments.order_by( + models.PackageComment.CommentTS.desc()) + return render_template(request, "account/comments.html", context) + + @router.get("/accounts") @auth_required(True, redirect="/accounts") @account_type_required({account_type.TRUSTED_USER, diff --git a/templates/account/comments.html b/templates/account/comments.html new file mode 100644 index 00000000..a1012b1b --- /dev/null +++ b/templates/account/comments.html @@ -0,0 +1,52 @@ +{% extends "partials/layout.html" %} + +{% block pageContent %} +
Test comment
", + CommentTS=now) + + cookies = {"AURSID": user.login(Request(), "testPassword")} + endpoint = f"/account/{user.Username}/comments" + with client as request: + resp = request.get(endpoint, cookies=cookies) + assert resp.status_code == int(HTTPStatus.OK) + + root = parse_root(resp.text) + comments = root.xpath('//div[@class="article-content"]/div') + + # Assert that we got Comments rendered from the first comment. + assert comments[0].text.strip() == comment.Comments + + # And from the second, we have rendered content. + rendered = comments[1].xpath('./p') + expected = rendered_comment.RenderedComment.replace( + "", "").replace("
", "") + assert rendered[0].text.strip() == expected
+ {{ + "Comments for %s%s%s" | tr + | format('' | format(username), + username, + "") + | safe + }} +
++ {{ + "Commented on package %s%s%s on %s%s%s" | tr + | format( + '', + comment.PackageBase.Name, + "", + '' | format( + username, + comment.ID + ), + commented_at.strftime("%Y-%m-%d %H:%M"), + "" + ) | safe + }} +
+