From 78bee4ec778947df35fa47e29282a60aec5a7acd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 23 May 2021 20:23:54 +0000 Subject: threads etc --- apioforum/__init__.py | 9 --------- apioforum/auth.py | 7 ++++++- apioforum/db.py | 3 ++- apioforum/templates/base.html | 2 +- apioforum/templates/view_thread.html | 7 ++++++- apioforum/thread.py | 11 +++++++---- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index df7185b..e4bea05 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -29,13 +29,4 @@ def create_app(): from . import thread app.register_blueprint(thread.bp) - @app.route("/") - def main(): - return "the" - - @app.route("/b") - def b(): - db=get_db() - return str(db.execute("select 2 + 2;").fetchone()[0]) - return app diff --git a/apioforum/auth.py b/apioforum/auth.py index fe03264..49808ea 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -75,9 +75,14 @@ def load_user(): if username is None: g.user = None else: - g.user = get_db().execute( + row = get_db().execute( "SELECT * FROM users WHERE username = ?;", (username,) ).fetchone() + if row is None: + g.user = None + else: + g.user = row['username'] + def login_required(view): @functools.wraps(view) diff --git a/apioforum/db.py b/apioforum/db.py index 31eb8ef..9db27db 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -37,8 +37,9 @@ CREATE TABLE posts ( content TEXT, thread INTEGER NOT NULL REFERENCES threads(id), author TEXT NOT NULL REFERENCES users(username), - idx INTEGER NOT NULL + created TIMESTAMP NOT NULL ); + CREATE INDEX posts_thread_idx ON posts (thread); """, ] diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index 6660686..28fd055 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -10,7 +10,7 @@

apioforum