From 933d8ebfe7579a8fcb29d0ecfd90e0f61069141e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 3 Jan 2022 01:41:50 +0000 Subject: [PATCH] Add all user replies page --- app/blueprints/threads/__init__.py | 12 ++++- app/models/users.py | 2 +- app/templates/threads/user_replies.html | 65 +++++++++++++++++++++++++ app/templates/users/profile.html | 4 +- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 app/templates/threads/user_replies.html diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py index 7afbdd5a..7f4454bc 100644 --- a/app/blueprints/threads/__init__.py +++ b/app/blueprints/threads/__init__.py @@ -28,6 +28,7 @@ from wtforms import * from wtforms.validators import * from app.utils import get_int_or_abort + @menu.register_menu(bp, ".threads", "Threads", order=20) @bp.route("/threads/") def list_all(): @@ -344,7 +345,7 @@ def new(): if is_review_thread: post_discord_webhook.delay(current_user.username, - "Opened approval thread: {}".format(thread.getViewURL(absolute=True)), True) + "Opened approval thread: {}".format(thread.gcletViewURL(absolute=True)), True) db.session.commit() @@ -352,3 +353,12 @@ def new(): return render_template("threads/new.html", form=form, allow_private_change=allow_change, package=package) + + +@bp.route("/users//replies/") +def user_replies(username): + user = User.query.filter_by(username=username).first() + if user is None: + abort(404) + + return render_template("threads/user_replies.html", user=user, replies=user.replies) \ No newline at end of file diff --git a/app/models/users.py b/app/models/users.py index 846c2201..d50ac859 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -177,7 +177,7 @@ class User(db.Model, UserMixin): review_votes = db.relationship("PackageReviewVote", back_populates="user", cascade="all, delete, delete-orphan") tokens = db.relationship("APIToken", back_populates="owner", lazy="dynamic", cascade="all, delete, delete-orphan") threads = db.relationship("Thread", back_populates="author", lazy="dynamic", cascade="all, delete, delete-orphan") - replies = db.relationship("ThreadReply", back_populates="author", lazy="dynamic", cascade="all, delete, delete-orphan") + replies = db.relationship("ThreadReply", back_populates="author", lazy="dynamic", cascade="all, delete, delete-orphan", order_by=db.desc("created_at")) forum_topics = db.relationship("ForumTopic", back_populates="author", lazy="dynamic", cascade="all, delete, delete-orphan") def __init__(self, username=None, active=False, email=None, password=None): diff --git a/app/templates/threads/user_replies.html b/app/templates/threads/user_replies.html new file mode 100644 index 00000000..5cfe2a37 --- /dev/null +++ b/app/templates/threads/user_replies.html @@ -0,0 +1,65 @@ +{% extends "base.html" %} + + +{% block link %} + {{ user.display_name }} +{% endblock %} + +{% block title %} + {{ _("Replies by %(user)s", user=user.display_name) }} +{% endblock %} + +{% block content %} +

{{ _("Replies by %(user)s", user=self.link()) }}

+ + + + +{% endblock %} diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index 00f5e834..540b28a8 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -101,13 +101,13 @@ - + {{ user.replies.count() }} {{ _("comments") }} - +