From eb298f0c63eb6ac5547a6a7a0086e5e086ad5abc Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 22 May 2021 15:12:30 +0000 Subject: thread view, also fix file extensions --- apioforum/__init__.py | 3 +++ apioforum/auth.py | 4 ++-- apioforum/forum.py | 2 +- apioforum/templates/auth/login.html | 14 ++++++++++++++ apioforum/templates/auth/login.html.j2 | 14 -------------- apioforum/templates/auth/register.html | 14 ++++++++++++++ apioforum/templates/auth/register.html.j2 | 14 -------------- apioforum/templates/base.html | 29 +++++++++++++++++++++++++++++ apioforum/templates/base.html.j2 | 29 ----------------------------- apioforum/templates/view_forum.html | 23 +++++++++++++++++++++++ apioforum/templates/view_forum.html.j2 | 23 ----------------------- apioforum/templates/view_thread.html | 18 ++++++++++++++++++ apioforum/thread.py | 19 +++++++++++++++++++ 13 files changed, 123 insertions(+), 83 deletions(-) create mode 100644 apioforum/templates/auth/login.html delete mode 100644 apioforum/templates/auth/login.html.j2 create mode 100644 apioforum/templates/auth/register.html delete mode 100644 apioforum/templates/auth/register.html.j2 create mode 100644 apioforum/templates/base.html delete mode 100644 apioforum/templates/base.html.j2 create mode 100644 apioforum/templates/view_forum.html delete mode 100644 apioforum/templates/view_forum.html.j2 create mode 100644 apioforum/templates/view_thread.html create mode 100644 apioforum/thread.py diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 2eacd67..df7185b 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -26,6 +26,9 @@ def create_app(): from . import forum app.register_blueprint(forum.bp) + from . import thread + app.register_blueprint(thread.bp) + @app.route("/") def main(): return "the" diff --git a/apioforum/auth.py b/apioforum/auth.py index f558025..fe03264 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -32,7 +32,7 @@ def login(): flash(err) - return render_template("auth/login.html.j2") + return render_template("auth/login.html") @bp.route("/register", methods=("GET","POST")) def register(): @@ -62,7 +62,7 @@ def register(): flash(err) - return render_template("auth/register.html.j2") + return render_template("auth/register.html") @bp.route("/logout") def logout(): diff --git a/apioforum/forum.py b/apioforum/forum.py index 7fb1e57..c09b0e8 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -12,4 +12,4 @@ bp = Blueprint("forum", __name__, url_prefix="/") 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) + return render_template("view_forum.html",threads=threads) diff --git a/apioforum/templates/auth/login.html b/apioforum/templates/auth/login.html new file mode 100644 index 0000000..c0a2eed --- /dev/null +++ b/apioforum/templates/auth/login.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block header %} +

{% block title %}login{% endblock %}

+{% endblock %} + +{% block content %} +
+ + + + + +
+{% endblock %} diff --git a/apioforum/templates/auth/login.html.j2 b/apioforum/templates/auth/login.html.j2 deleted file mode 100644 index c8c67b4..0000000 --- a/apioforum/templates/auth/login.html.j2 +++ /dev/null @@ -1,14 +0,0 @@ -{% extends "base.html.j2" %} -{% block header %} -

{% block title %}login{% endblock %}

-{% endblock %} - -{% block content %} -
- - - - - -
-{% endblock %} diff --git a/apioforum/templates/auth/register.html b/apioforum/templates/auth/register.html new file mode 100644 index 0000000..716fa1d --- /dev/null +++ b/apioforum/templates/auth/register.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% block header %} +

{% block title %}register{% endblock %}

+{% endblock %} + +{% block content %} +
+ + + + + +
+{% endblock %} diff --git a/apioforum/templates/auth/register.html.j2 b/apioforum/templates/auth/register.html.j2 deleted file mode 100644 index f7eab81..0000000 --- a/apioforum/templates/auth/register.html.j2 +++ /dev/null @@ -1,14 +0,0 @@ -{% extends "base.html.j2" %} -{% block header %} -

{% block title %}register{% endblock %}

-{% endblock %} - -{% block content %} -
- - - - - -
-{% endblock %} diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html new file mode 100644 index 0000000..6660686 --- /dev/null +++ b/apioforum/templates/base.html @@ -0,0 +1,29 @@ +{# BASED? BASED ON WHAT? #} + + + + {%block title %}{% endblock %} + + + + + + {% block header %}{% endblock %} + {% for msg in get_flashed_messages() %} +
{{ msg }}
+ {% endfor %} + {%block content %}{% endblock %} + + + diff --git a/apioforum/templates/base.html.j2 b/apioforum/templates/base.html.j2 deleted file mode 100644 index 6660686..0000000 --- a/apioforum/templates/base.html.j2 +++ /dev/null @@ -1,29 +0,0 @@ -{# BASED? BASED ON WHAT? #} - - - - {%block title %}{% endblock %} - - - - - - {% block header %}{% endblock %} - {% for msg in get_flashed_messages() %} -
{{ msg }}
- {% endfor %} - {%block content %}{% endblock %} - - - diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html new file mode 100644 index 0000000..2140c7a --- /dev/null +++ b/apioforum/templates/view_forum.html @@ -0,0 +1,23 @@ +{% extends 'base.html' %} +{% 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%} diff --git a/apioforum/templates/view_forum.html.j2 b/apioforum/templates/view_forum.html.j2 deleted file mode 100644 index fe14652..0000000 --- a/apioforum/templates/view_forum.html.j2 +++ /dev/null @@ -1,23 +0,0 @@ -{% 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%} diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html new file mode 100644 index 0000000..34faeea --- /dev/null +++ b/apioforum/templates/view_thread.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% block header %} +

{%block title %}thread{% endblock %}

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

{{thread.title}}

+

by {{thread.creator}}

+
+{% for post in posts %} +
{{post.author}}
+
{{post.content}}
+{% else %} +
there weren't
+
any posts
+{% endfor %} +
+{% endblock %} diff --git a/apioforum/thread.py b/apioforum/thread.py new file mode 100644 index 0000000..24b7766 --- /dev/null +++ b/apioforum/thread.py @@ -0,0 +1,19 @@ +# view posts in thread + +from flask import ( + Blueprint, render_template +) +from .db import get_db + +bp = Blueprint("thread", __name__, url_prefix="/thread") + +@bp.route("/view/") +def view_thread(thread_id): + db = get_db() + thread = db.execute("SELECT * FROM threads WHERE id = ?;",(thread_id,)).fetchone() + if thread is None: + abort(404) + else: + posts = db.execute("SELECT * FROM posts WHERE thread = ? ORDER BY idx;",(thread_id,)).fetchall() + return render_template("view_thread.html",posts=posts,thread=thread) + -- cgit v1.2.3