diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py index e99136f4..8cfa14af 100644 --- a/app/blueprints/threads/__init__.py +++ b/app/blueprints/threads/__init__.py @@ -39,9 +39,16 @@ def list_all(): pid = get_int_or_abort(pid) query = query.filter_by(package_id=pid) + query = query.filter_by(review_id=None) + query = query.order_by(db.desc(Thread.created_at)) - return render_template("threads/list.html", threads=query.all()) + page = get_int_or_abort(request.args.get("page"), 1) + num = min(40, get_int_or_abort(request.args.get("n"), 100)) + + pagination = query.paginate(page, num, True) + + return render_template("threads/list.html", pagination=pagination, threads=pagination.items) @bp.route("/threads//subscribe/", methods=["POST"]) diff --git a/app/models/threads.py b/app/models/threads.py index d4a1eec2..12b3c5d8 100644 --- a/app/models/threads.py +++ b/app/models/threads.py @@ -91,6 +91,9 @@ class Thread(db.Model): else: raise Exception("Permission {} is not related to threads".format(perm.name)) + def get_latest_reply(self): + return ThreadReply.query.filter_by(thread_id=self.id).order_by(db.desc(ThreadReply.id)).first() + class ThreadReply(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/app/template_filters.py b/app/template_filters.py index 3a972d12..91d5b5a4 100644 --- a/app/template_filters.py +++ b/app/template_filters.py @@ -4,6 +4,7 @@ from .utils import abs_url_for, url_set_query from flask_login import current_user from flask_babel import format_timedelta from urllib.parse import urlparse +from datetime import datetime as dt @app.context_processor def inject_debug(): @@ -37,7 +38,11 @@ def date(value): @app.template_filter() def datetime(value): - return value.strftime("%Y-%m-%d %H:%M") + " UTC" + delta = dt.utcnow() - value + if delta.days == 0: + return format_timedelta(value) + else: + return value.strftime("%Y-%m-%d %H:%M") + " UTC" @app.template_filter() def timedelta(value): diff --git a/app/templates/macros/threads.html b/app/templates/macros/threads.html index b0223488..50b92fcf 100644 --- a/app/templates/macros/threads.html +++ b/app/templates/macros/threads.html @@ -95,46 +95,90 @@ {% endif %} {% endmacro %} -{% macro render_threadlist(threads, compact=False) -%} +{% macro render_compact_threadlist(threads) -%} {% for t in threads %} - {% if compact %} - {% if t.private %}🔒 {% endif %} - {{ t.title }} - by {{ t.author.display_name }} - {% else %} -
-
- - {% if not t.review and t.private %} - - {% elif not t.review %} - - {% elif t.review.recommends %} - - {% else %} - - {% endif %} - - - {{ t.title }} - by {{ t.author.display_name }} -
- -
- {% if t.package %} - {{ _("%(title)s by %(author)s", - title="" | safe + t.package.title + "" | safe, - author=t.package.author.display_name) }} - {% endif %} -
- -
- {{ t.created_at | datetime }} -
-
- {% endif %} + {% if t.private %}🔒 {% endif %} + {{ t.title }} + by {{ t.author.display_name }} +
+ {% else %} +

No threads found

+ {% endfor %} +{% endmacro %} + +{% macro render_threadlist(threads) -%} +
+
+ + {{ _("Thread") }} + + + + {{ _("Last Reply") }} + + + +
+
+ + {% for t in threads %} + {% set replies = t.replies.count() - 1 %} + + +
+
+ {% if not t.review and t.private %} + + {% elif not t.review %} + + {% elif t.review.recommends %} + + {% else %} + + {% endif %} + + {{ t.title }} +
+ + {{ t.author.display_name }} + + + {{ t.created_at | datetime }} + + + {{ replies }} + + +
+ +
+ {% if replies > 0 %} + {% set latest = t.get_latest_reply() %} + + {{ latest.author.display_name }} +
+ + {{ latest.created_at | datetime }} + + {% endif %} +
+ + {% if t.package %} +
+
+ + + {{ t.package.title }} + +
+ {% endif %} +
{% else %}

No threads found

diff --git a/app/templates/packages/reviews_list.html b/app/templates/packages/reviews_list.html index b3971f7a..fe69fa63 100644 --- a/app/templates/packages/reviews_list.html +++ b/app/templates/packages/reviews_list.html @@ -6,11 +6,9 @@ {% block content %} {% from "macros/pagination.html" import render_pagination %} - {{ render_pagination(pagination, url_set_query) }} - {% from "macros/reviews.html" import render_reviews %} - {{ render_reviews(reviews, current_user, True) }} - {% from "macros/pagination.html" import render_pagination %} + {{ render_pagination(pagination, url_set_query) }} + {{ render_reviews(reviews, current_user, True) }} {{ render_pagination(pagination, url_set_query) }} {% endblock %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index 37a9093d..4d8397cf 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -365,8 +365,8 @@ Threads diff --git a/app/templates/threads/list.html b/app/templates/threads/list.html index 2d861905..89e205d0 100644 --- a/app/templates/threads/list.html +++ b/app/templates/threads/list.html @@ -7,8 +7,14 @@ Threads {% block content %}

Threads

+ {% from "macros/pagination.html" import render_pagination %} {% from "macros/threads.html" import render_threadlist %} + {{ render_pagination(pagination, url_set_query) }} +
{{ render_threadlist(threads) }}
+ + {{ render_pagination(pagination, url_set_query) }} + {% endblock %}