From 76120509b4ff409c6642b837be95ebc72c529d4b Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 May 2021 23:30:15 +0000 Subject: threads etc --- apioforum/__init__.py | 3 +++ apioforum/db.py | 12 ++++++------ apioforum/forum.py | 15 +++++++++++++++ apioforum/templates/view_forum.html.j2 | 23 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 apioforum/forum.py create mode 100644 apioforum/templates/view_forum.html.j2 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 %}

{% block title %}apio forum george etc{%endblock%}

{%endblock%} +{%block content%} +

the

+ + + + + + + + +{%for thread in threads%} + + + + + + + +{%endfor%} +
idtitlecreatorcreatedupdated
#{{thread.id}}{{thread.title}}{{thread.creator}}{{thread.created}}{{thread.updated}}
+{%endblock%} -- cgit v1.2.3