diff --git a/app/__init__.py b/app/__init__.py index b53a7a4..0e55eed 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -26,6 +26,7 @@ from app import models # IDK why this is here, but it works from app.models.comment import Comment from app.models.thread import Thread from app.models.forum import Forum +from app.models.topic import Topic from app.models.notification import Notification from app.routes import index, search, users # To load routes at initialization from app.routes.account import login, account, notification diff --git a/app/models/forum.py b/app/models/forum.py index de586e6..c459375 100644 --- a/app/models/forum.py +++ b/app/models/forum.py @@ -34,3 +34,7 @@ class Forum(db.Model): def __repr__(self): return f'' + + def post_count(self): + """Number of posts in every topic of the forum, without subforums.""" + return sum(len(thread.comments) for thread in self.topics) diff --git a/app/templates/admin/forums.html b/app/templates/admin/forums.html index ae19fa3..c8bdf7d 100644 --- a/app/templates/admin/forums.html +++ b/app/templates/admin/forums.html @@ -1,14 +1,17 @@ {% extends "base/base.html" %} {# This macro will allow us to perform recursive HTML generation #} -{% macro forumtree(f) %} -
  • {{ f.name }} - -
  • +{% macro forumtree(f, level) %} + + {{ f.url }} + {{ f.name }} + {{ f.topics | length }} + {{ f.post_count() }} + + + {% for subf in f.sub_forums %} + {{ forumtree(subf, level+1) }} + {% endfor %} {% endmacro %} {% block title %} @@ -24,9 +27,10 @@ {% if main_forum == None %}

    Il n'y a aucun forum.

    {% else %} - + + + {{ forumtree(main_forum, 0) }} +
    URLNomSujetsMessages
    {% endif %} {% endblock %} diff --git a/migrations/versions/a3fb8937ae16_add_topics.py b/migrations/versions/a3fb8937ae16_add_topics.py new file mode 100644 index 0000000..ae11040 --- /dev/null +++ b/migrations/versions/a3fb8937ae16_add_topics.py @@ -0,0 +1,34 @@ +"""add topics + +Revision ID: a3fb8937ae16 +Revises: ebca7362eb22 +Create Date: 2019-09-05 21:35:48.260827 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'a3fb8937ae16' +down_revision = 'ebca7362eb22' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('topic', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('forum_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['forum_id'], ['forum.id'], ), + sa.ForeignKeyConstraint(['id'], ['thread.id'], ), + sa.PrimaryKeyConstraint('id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('topic') + # ### end Alembic commands ###