Compare commits

...

2 Commits

Author SHA1 Message Date
Lephe d3f137b92d
programs: add models for programs and topic promotions (#20)
Not tested yet since there is a lack of tools to manipulate comments,
topics and programs. The /programmes routes is used to display a list of
all programs, temporarily.
2020-08-01 15:11:19 +02:00
Lephe ea39b5d787
templates: fix indent and tags of forum index 2020-08-01 15:09:07 +02:00
9 changed files with 165 additions and 17 deletions

View File

@ -3,3 +3,4 @@ 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.models.program import Program

43
app/models/program.py Normal file
View File

@ -0,0 +1,43 @@
from app import db
from app.models.post import Post
class Program(Post):
__tablename__ = 'program'
__mapper_args__ = {'polymorphic_identity': __tablename__}
# ID of underlying Post object
id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
# Program name
title = db.Column(db.Unicode(128))
# TODO: Category (games/utilities/lessons)
# TODO: Tags
# TODO: Compatible calculator models
thread_id = db.Column(db.Integer,db.ForeignKey('thread.id'),nullable=False)
thread = db.relationship('Thread', foreign_keys=thread_id)
# TODO: Number of views, statistics, attached files, etc
def __init__(self, author, title, thread):
"""
Create a Program.
Arguments:
author -- post author (User, though only Members can post)
title -- program title (unicode string)
thread -- discussion thread attached to the topic
"""
Post.__init__(self, author)
self.title = title
self.thread = thread
@staticmethod
def from_topic(topic):
p = Program(topic.author, topic.title, topic.thread)
topic.promotion = p
def __repr__(self):
return f'<Program: #{self.id} "{self.title}">'

View File

@ -3,13 +3,22 @@ from app.models.post import Post
class Topic(Post):
__tablename__ = 'topic'
__mapper_args__ = {'polymorphic_identity': __tablename__}
# ID of the underlying [Post] object
id = db.Column(db.Integer, db.ForeignKey('post.id'), primary_key=True)
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'primary_key': id,
'inherit_condition': id == Post.id
}
# Post that the topic was promoted into. If this is not None, then the
# topic was published into a project and a redirection should be emitted
promotion_id = db.Column(db.Integer,db.ForeignKey('post.id'),nullable=True)
promotion = db.relationship('Post', foreign_keys=promotion_id)
# Topic title
title = db.Column(db.Unicode(32))
title = db.Column(db.Unicode(128))
# Parent forum
forum_id = db.Column(db.Integer, db.ForeignKey('forum.id'), nullable=False)

View File

@ -4,3 +4,4 @@ from app.routes import index, search, users, tools
from app.routes.account import login, account, notification
from app.routes.admin import index, groups, account, trophies, forums
from app.routes.forum import index, topic
from app.routes.programs import index

View File

@ -0,0 +1,8 @@
from app import app, db
from app.models.program import Program
from app.utils.render import render
@app.route('/programmes')
def program_index():
programs = Program.query.all()
return render('/programs/index.html')

View File

@ -15,25 +15,25 @@
.
</p>
{% if main_forum == None %}
{% if main_forum == None %}
<p>Il n'y a aucun forum.</p>
{% else %}
{% else %}
{% for l1 in main_forum.sub_forums %}
{% for l1 in main_forum.sub_forums %}
<table class=forumlist>
<tr><th>{{ l1.name }}</th><th>Nombre de sujets</th></tr>
<tr><th>{{ l1.name }}</th><th>Nombre de sujets</th></tr>
{% if l1.sub_forums == [] %}
<tr><td><a href='/forum{{ l1.url }}'>{{ l1.name }}</td>
<td>{{ l1.topics | length }}</td></tr>
<tr><td>{{ l1.descr }}</td><td></td></tr>
{% endif %}
{% if l1.sub_forums == [] %}
<tr><td><a href='/forum{{ l1.url }}'>{{ l1.name }}</a></td>
<td>{{ l1.topics | length }}</td></tr>
<tr><td>{{ l1.descr }}</td><td></td></tr>
{% endif %}
{% for l2 in l1.sub_forums %}
<tr><td><a href='/forum{{ l2.url }}'>{{ l2.name }}</td>
<td>{{ l2.topics | length }}</td></tr>
<tr><td>{{ l2.descr }}</td><td></td></tr>
{% endfor %}
{% for l2 in l1.sub_forums %}
<tr><td><a href='/forum{{ l2.url }}'>{{ l2.name }}</td>
<td>{{ l2.topics | length }}</td></tr>
<tr><td>{{ l2.descr }}</td><td></td></tr>
{% endfor %}
</table>
{% endfor %}

View File

@ -0,0 +1,21 @@
{% extends "base/base.html" %}
{% block title %}
<h1>Programmes de Planète Casio</h1>
{% endblock %}
{% block content %}
<section>
<h2>Tous les programmes</h2>
<table class=programlist>
<tr><th>ID</th><th>Nom</th><th>Auteur</th><th>Publié le</th></tr>
{% for p in programs %}
<tr><td>{{ p.id }}</td>
<td><a href='#'>{{ p.name }}</a></td>
<td>{{ p.author.name }}</td>
<td>{{ p.date_created }}</td></tr>
{% endfor %}
</table>
</section>
{% endblock %}

View File

@ -0,0 +1,35 @@
"""add a base model for programs
Revision ID: c5561fa6af4e
Revises: c7779a558510
Create Date: 2020-08-01 14:52:52.878440
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c5561fa6af4e'
down_revision = 'c7779a558510'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('program',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.Unicode(length=128), nullable=True),
sa.Column('thread_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['id'], ['post.id'], ),
sa.ForeignKeyConstraint(['thread_id'], ['thread.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('program')
# ### end Alembic commands ###

View File

@ -0,0 +1,30 @@
"""add promotion information to topics
Revision ID: c7779a558510
Revises: 001d2eaf0413
Create Date: 2020-08-01 11:27:23.298821
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c7779a558510'
down_revision = '001d2eaf0413'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('topic', sa.Column('promotion_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'topic', 'post', ['promotion_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'topic', type_='foreignkey')
op.drop_column('topic', 'promotion_id')
# ### end Alembic commands ###