Browse Source

forum: list subforum topics

Also introduces a 'date' filter that displays date in a readable format.
posts
Lephe 3 months ago
parent
commit
3ad3eca470
Signed by: Lephe <sebastien.michelland@protonmail.com> GPG Key ID: 1BBA026E13FC0495
6 changed files with 66 additions and 4 deletions
  1. +1
    -0
      app/__init__.py
  2. +4
    -0
      app/models/topic.py
  3. +11
    -0
      app/static/css/table.css
  4. +13
    -4
      app/templates/forum/forum.html
  5. +9
    -0
      app/utils/date.py
  6. +28
    -0
      migrations/versions/c665488fc26e_add_number_of_views_to_topic.py

+ 1
- 0
app/__init__.py 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

+ 4
- 0
app/models/topic.py 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


+ 11
- 0
app/static/css/table.css 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;
}

+ 13
- 4
app/templates/forum/forum.html 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
- 0
app/utils/date.py 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")

+ 28
- 0
migrations/versions/c665488fc26e_add_number_of_views_to_topic.py 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 ###

Loading…
Cancel
Save