forum: better tree visualization, and topics
Turns the forum tree visualization in the admin panel into a tree-like table, and exposes the Topic class to the application and database.
This commit is contained in:
parent
153f303857
commit
35f1335f64
|
@ -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
|
||||
|
|
|
@ -34,3 +34,7 @@ class Forum(db.Model):
|
|||
|
||||
def __repr__(self):
|
||||
return f'<Forum: {self.name}>'
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
{% extends "base/base.html" %}
|
||||
|
||||
{# This macro will allow us to perform recursive HTML generation #}
|
||||
{% macro forumtree(f) %}
|
||||
<li> {{ f.name }}
|
||||
<ul>
|
||||
{% for subf in f.sub_forums %}
|
||||
{{ forumtree(subf) }}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% macro forumtree(f, level) %}
|
||||
<tr>
|
||||
<td><code>{{ f.url }}</code></td>
|
||||
<td style='padding-left: {{ 6+24*level }}px'>{{ f.name }}</td>
|
||||
<td>{{ f.topics | length }}</td>
|
||||
<td>{{ f.post_count() }}</td>
|
||||
</tr>
|
||||
|
||||
{% for subf in f.sub_forums %}
|
||||
{{ forumtree(subf, level+1) }}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% block title %}
|
||||
|
@ -24,9 +27,10 @@
|
|||
{% if main_forum == None %}
|
||||
<p>Il n'y a aucun forum.</p>
|
||||
{% else %}
|
||||
<ul>
|
||||
{{ forumtree(main_forum) }}
|
||||
</ul>
|
||||
<table style='width: 90%; margin: auto'>
|
||||
<tr><th>URL</th><th>Nom</th><th>Sujets</th><th>Messages</th></tr>
|
||||
{{ forumtree(main_forum, 0) }}
|
||||
</table>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
|
@ -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 ###
|
Loading…
Reference in New Issue