forum: list subforum topics

Also introduces a 'date' filter that displays date in a readable format.
This commit is contained in:
Lephe 2019-09-09 08:03:23 +02:00
parent 79e5af7924
commit 3ad3eca470
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
6 changed files with 66 additions and 4 deletions

View File

@ -38,4 +38,5 @@ from app.routes.admin import index, groups, account, trophies, forums
from app.routes.forum import index
from app.utils import pluralize # To use pluralize into the templates
from app.utils import date
from app.utils import is_title

View File

@ -20,6 +20,9 @@ class Topic(Post):
thread_id = db.Column(db.Integer,db.ForeignKey('thread.id'),nullable=False)
thread = db.relationship('Thread', foreign_keys=thread_id)
# Number of views in the forum
views = db.Column(db.Integer)
def __init__(self, forum, author, title, thread):
"""
Create a Topic.
@ -33,6 +36,7 @@ class Topic(Post):
Post.__init__(self, author)
self.title = title
self.views = 0
self.thread = thread
self.forum = forum

View File

@ -41,3 +41,14 @@ table.forumlist tr:nth-child(4n+2),
table.forumlist tr:nth-child(4n+3) {
background: rgba(0, 0, 0, .05);
}
/* Topic table */
table.topiclist {
width: 90%;
margin: auto;
}
table.topiclist tr > *:nth-child(n+2) {
/* This matches all children except the first column */
text-align: center;
}

View File

@ -7,14 +7,23 @@
{% block content %}
<section>
{{ f.descr }}
<p>{{ f.descr }}</p>
{% if f.topics %}
<ul>
<table class=topiclist>
<tr><th>Sujet</th><th>Auteur</th><th>Date de création</th>
<th>Commentaires</th><th>Vues</th></tr>
{% for t in f.topics %}
<li>{{ t.title }}</li>
<tr><td>{{ t.title }}</td>
<td><a href='/user/{{ t.author.norm }}'>{{ t.author.name }}</a></td>
<td>{{ t.date_created | date }}</td>
<td>{{ t.comments | length }}</td>
<td>{{ t.views }} </td></tr>
{% endfor %}
</ul>
</table>
{% else %}
<p>Il n'y a aucun topic sur ce forum ! Animons-le vite !</p>
{% endif %}
<div class=form>

9
app/utils/date.py Normal file
View File

@ -0,0 +1,9 @@
from app import app
@app.template_filter('date')
def filter_date(date):
"""
Print a date in a human-readable format.
"""
return date.strftime("%d %b %Y à %H:%M")

View File

@ -0,0 +1,28 @@
"""Add number of views to Topic
Revision ID: c665488fc26e
Revises: abd5f8de0106
Create Date: 2019-09-08 16:49:50.448779
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c665488fc26e'
down_revision = 'abd5f8de0106'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('topic', sa.Column('views', sa.Integer(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('topic', 'views')
# ### end Alembic commands ###