diff options
-rw-r--r-- | apioforum/__init__.py | 3 | ||||
-rw-r--r-- | apioforum/db.py | 12 | ||||
-rw-r--r-- | apioforum/forum.py | 15 | ||||
-rw-r--r-- | apioforum/templates/view_forum.html.j2 | 23 |
4 files changed, 47 insertions, 6 deletions
diff --git a/apioforum/__init__.py b/apioforum/__init__.py index bdfe88f..2eacd67 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -23,6 +23,9 @@ def create_app(): from . import auth app.register_blueprint(auth.bp) + from . import forum + app.register_blueprint(forum.bp) + @app.route("/") def main(): return "the" diff --git a/apioforum/db.py b/apioforum/db.py index a2830fe..31eb8ef 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -26,18 +26,18 @@ CREATE TABLE users ( );""", """ CREATE TABLE threads ( - id INT PRIMARY KEY, + id INTEGER PRIMARY KEY, title TEXT NOT NULL, creator TEXT NOT NULL REFERENCES users(username), - created INT NOT NULL, - updated INT NOT NULL + created TIMESTAMP NOT NULL, + updated TIMESTAMP NOT NULL ); CREATE TABLE posts ( - id INT PRIMARY KEY, + id INTEGER PRIMARY KEY, content TEXT, - thread INT NOT NULL REFERENCES threads(id), + thread INTEGER NOT NULL REFERENCES threads(id), author TEXT NOT NULL REFERENCES users(username), - idx INT NOT NULL + idx INTEGER NOT NULL ); CREATE INDEX posts_thread_idx ON posts (thread); """, diff --git a/apioforum/forum.py b/apioforum/forum.py new file mode 100644 index 0000000..7fb1e57 --- /dev/null +++ b/apioforum/forum.py @@ -0,0 +1,15 @@ +# view threads in a forum +# currently there is only ever one forum however + +from flask import ( + Blueprint, render_template +) +from .db import get_db + +bp = Blueprint("forum", __name__, url_prefix="/") + +@bp.route("/") +def view_forum(): + db = get_db() + threads = db.execute("SELECT * FROM threads ORDER BY updated DESC LIMIT 10;").fetchall() + return render_template("view_forum.html.j2",threads=threads) diff --git a/apioforum/templates/view_forum.html.j2 b/apioforum/templates/view_forum.html.j2 new file mode 100644 index 0000000..fe14652 --- /dev/null +++ b/apioforum/templates/view_forum.html.j2 @@ -0,0 +1,23 @@ +{% extends 'base.html.j2' %} +{% block header %}<h1>{% block title %}apio forum george etc{%endblock%}</h1>{%endblock%} +{%block content%} +<p>the</p> +<table> + <tr> + <th>id</th> + <th>title</th> + <th>creator</th> + <th>created</th> + <th>updated</th> + </tr> +{%for thread in threads%} +<tr> + <td>#{{thread.id}}</td> + <td><a href="#">{{thread.title}}</a></td> + <td>{{thread.creator}}</td> + <td>{{thread.created}}</td> + <td>{{thread.updated}}</td> +</tr> +{%endfor%} +</table> +{%endblock%} |