summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-05-21 23:30:15 +0000
committerubq323 <ubq323>2021-05-21 23:30:15 +0000
commit76120509b4ff409c6642b837be95ebc72c529d4b (patch)
tree8759e850feb4d848c2c59319d763d79b4fb8ce8c
parent61d73d6470096e3afa5dd278f8bcacc37e1bf877 (diff)
threads etc
-rw-r--r--apioforum/__init__.py3
-rw-r--r--apioforum/db.py12
-rw-r--r--apioforum/forum.py15
-rw-r--r--apioforum/templates/view_forum.html.j223
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%}