From 3ad3eca4708672e2081858aab12dac20eabc5ebb Mon Sep 17 00:00:00 2001 From: Lephe Date: Mon, 9 Sep 2019 08:03:23 +0200 Subject: [PATCH] forum: list subforum topics Also introduces a 'date' filter that displays date in a readable format. --- app/__init__.py | 1 + app/models/topic.py | 4 +++ app/static/css/table.css | 11 ++++++++ app/templates/forum/forum.html | 17 ++++++++--- app/utils/date.py | 9 ++++++ ...65488fc26e_add_number_of_views_to_topic.py | 28 +++++++++++++++++++ 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 app/utils/date.py create mode 100644 migrations/versions/c665488fc26e_add_number_of_views_to_topic.py diff --git a/app/__init__.py b/app/__init__.py index 8b99b51..7cc7839 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 diff --git a/app/models/topic.py b/app/models/topic.py index 16302f4..fe18b9d 100644 --- a/app/models/topic.py +++ b/app/models/topic.py @@ -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 diff --git a/app/static/css/table.css b/app/static/css/table.css index b0a0073..c70652c 100644 --- a/app/static/css/table.css +++ b/app/static/css/table.css @@ -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; +} diff --git a/app/templates/forum/forum.html b/app/templates/forum/forum.html index e70c299..974e89a 100644 --- a/app/templates/forum/forum.html +++ b/app/templates/forum/forum.html @@ -7,14 +7,23 @@ {% block content %}
- {{ f.descr }} +

{{ f.descr }}

{% if f.topics %} -