mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 01:23:48 +01:00
Improve thread list appearance
This commit is contained in:
parent
1064885a2c
commit
df79159e2e
@ -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/<int:id>/subscribe/", methods=["POST"])
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -95,46 +95,90 @@
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_threadlist(threads, compact=False) -%}
|
||||
{% macro render_compact_threadlist(threads) -%}
|
||||
{% for t in threads %}
|
||||
<a class="list-group-item list-group-item-action"
|
||||
href="{{ url_for('threads.view', id=t.id) }}">
|
||||
{% if compact %}
|
||||
{% if t.private %}🔒 {% endif %}
|
||||
<strong>{{ t.title }}</strong>
|
||||
by {{ t.author.display_name }}
|
||||
{% else %}
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<span class="mr-3">
|
||||
{% if not t.review and t.private %}
|
||||
<i class="fas fa-lock" style="color:#ffac33;"></i>
|
||||
{% elif not t.review %}
|
||||
<i class="fas fa-comment-alt" style="color:#666;"></i>
|
||||
{% elif t.review.recommends %}
|
||||
<i class="fas fa-thumbs-up" style="color:#6f6;"></i>
|
||||
{% else %}
|
||||
<i class="fas fa-thumbs-down" style="color:#f66;"></i>
|
||||
{% endif %}
|
||||
</span>
|
||||
|
||||
<strong>{{ t.title }}</strong>
|
||||
by {{ t.author.display_name }}
|
||||
</div>
|
||||
|
||||
<div class="col-sm">
|
||||
{% if t.package %}
|
||||
{{ _("%(title)s by %(author)s",
|
||||
title="<b>" | safe + t.package.title + "</b>" | safe,
|
||||
author=t.package.author.display_name) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-auto text-muted text-right">
|
||||
{{ t.created_at | datetime }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if t.private %}🔒 {% endif %}
|
||||
<strong>{{ t.title }}</strong>
|
||||
by {{ t.author.display_name }}
|
||||
</a>
|
||||
{% else %}
|
||||
<p class="list-group-item"><i>No threads found</i></p>
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_threadlist(threads) -%}
|
||||
<div class="list-group-item">
|
||||
<div class="row text-muted">
|
||||
<span class="col-md">
|
||||
{{ _("Thread") }}
|
||||
</span>
|
||||
|
||||
<span class="col-md">
|
||||
{{ _("Last Reply") }}
|
||||
</span>
|
||||
|
||||
<span class="col-md-2"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for t in threads %}
|
||||
{% set replies = t.replies.count() - 1 %}
|
||||
|
||||
<a class="list-group-item list-group-item-action"
|
||||
href="{{ url_for('threads.view', id=t.id) }}">
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
{% if not t.review and t.private %}
|
||||
<i class="fas fa-lock" style="color:#ffac33;"></i>
|
||||
{% elif not t.review %}
|
||||
<i class="fas fa-comment-alt" style="color:#666;"></i>
|
||||
{% elif t.review.recommends %}
|
||||
<i class="fas fa-thumbs-up" style="color:#6f6;"></i>
|
||||
{% else %}
|
||||
<i class="fas fa-thumbs-down" style="color:#f66;"></i>
|
||||
{% endif %}
|
||||
<strong class="ml-1">
|
||||
{{ t.title }}
|
||||
</strong><br />
|
||||
<span>
|
||||
{{ t.author.display_name }}
|
||||
</span>
|
||||
<span class="text-muted ml-3">
|
||||
{{ t.created_at | datetime }}
|
||||
</span>
|
||||
<span class="text-muted ml-3">
|
||||
{{ replies }}
|
||||
<i class="fas fa-comment ml-1"></i>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
{% if replies > 0 %}
|
||||
{% set latest = t.get_latest_reply() %}
|
||||
<span>
|
||||
{{ latest.author.display_name }}
|
||||
</span><br />
|
||||
<span class="text-muted">
|
||||
{{ latest.created_at | datetime }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if t.package %}
|
||||
<div class="col-md-2 text-muted text-right">
|
||||
<img
|
||||
class="img-fluid"
|
||||
style="max-height: 22px; max-width: 22px;"
|
||||
src="{{ t.package.getThumbnailURL(1) }}" /><br />
|
||||
|
||||
<span class="pl-2">
|
||||
{{ t.package.title }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
{% else %}
|
||||
<p class="list-group-item"><i>No threads found</i></p>
|
||||
|
@ -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 %}
|
||||
|
@ -365,8 +365,8 @@
|
||||
Threads
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
{% from "macros/threads.html" import render_threadlist %}
|
||||
{{ render_threadlist(threads, compact=True) }}
|
||||
{% from "macros/threads.html" import render_compact_threadlist %}
|
||||
{{ render_compact_threadlist(threads) }}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
@ -7,8 +7,14 @@ Threads
|
||||
{% block content %}
|
||||
<h1>Threads</h1>
|
||||
|
||||
{% from "macros/pagination.html" import render_pagination %}
|
||||
{% from "macros/threads.html" import render_threadlist %}
|
||||
{{ render_pagination(pagination, url_set_query) }}
|
||||
|
||||
<div class="list-group">
|
||||
{{ render_threadlist(threads) }}
|
||||
</div>
|
||||
|
||||
{{ render_pagination(pagination, url_set_query) }}
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user