{{ post.title }}
+ +{{ post.body }}
++ +
diff --git a/kanken_online/forum.py b/kanken_online/forum.py index 4fae4d3..5a43f81 100644 --- a/kanken_online/forum.py +++ b/kanken_online/forum.py @@ -1,8 +1,37 @@ -from flask import Blueprint, render_template +import datetime +from flask import Blueprint, flash, redirect, render_template, request, session, url_for + +from kanken_online.auth import login_required +from kanken_online.database import get_database blueprint = Blueprint("forum", __name__, url_prefix="/forum") @blueprint.route("/") def index(): - return render_template("forum/index.html") + # Get forum posts + db = get_database() + + posts = db.execute("SELECT post.*, user.username FROM post, user WHERE user.id = post.author_id ORDER BY post.created DESC LIMIT 50").fetchall() + + # Pass to the template to render + return render_template("forum/index.html", posts=posts) + +@blueprint.route("/new", methods=["GET", "POST"]) +@login_required +def new_post(): + if request.method == "GET": + return render_template("forum/new.html") + else: + title = request.form["title"] + body = request.form["body"] + + author_id = session["user_id"] + created = datetime.datetime.now() + + db = get_database() + db.execute("INSERT INTO post VALUES (NULL, ?, ?, ?, ?)", + (author_id, created, title, body)) + db.commit() + flash("success_new_post") + return redirect(url_for("forum.index")) \ No newline at end of file diff --git a/kanken_online/static/lang/en.json b/kanken_online/static/lang/en.json index 3b657e5..ea1c937 100644 --- a/kanken_online/static/lang/en.json +++ b/kanken_online/static/lang/en.json @@ -36,5 +36,10 @@ "kanji_tsv_download": "Download kanji TSV", "kotoba_tsv_download": "Download kotoba TSV", "ankipkg_download": "Download Anki package", -"database_download": "Download database" +"database_download": "Download database", +"new_post": "New post", +"submit_post": "Submit post", +"title": "Title", +"post_body": "Post body", +"success_new_post": "Successfully created new post" } \ No newline at end of file diff --git a/kanken_online/static/lang/ja.json b/kanken_online/static/lang/ja.json index 3f00449..bce93ff 100644 --- a/kanken_online/static/lang/ja.json +++ b/kanken_online/static/lang/ja.json @@ -36,5 +36,10 @@ "kanji_tsv_download": "漢字TSVをダウンロード", "kotoba_tsv_download": "言葉TSVをダウンロード", "ankipkg_download": "APKGをダウンロード", -"database_download": "データーベースをダウンロード" +"database_download": "データーベースをダウンロード", +"new_post": "新しい投稿", +"submit_post": "投稿する", +"title": "話題", +"post_body": "投稿内容", +"success_new_post": "無事に新しい投稿を作りました" } \ No newline at end of file diff --git a/kanken_online/templates/base.html b/kanken_online/templates/base.html index 6fbf042..6a9ff0d 100644 --- a/kanken_online/templates/base.html +++ b/kanken_online/templates/base.html @@ -27,6 +27,7 @@
{{ post.body }}
+