diff --git a/suchwow/app.py b/suchwow/app.py index 2a0d27d..eda0d7c 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -17,6 +17,7 @@ Session(app) app.register_blueprint(post.bp) app.register_blueprint(auth.bp) app.register_blueprint(profile.bp) +app.register_blueprint(comment.bp) @app.route("/") def index(): diff --git a/suchwow/routes/comment.py b/suchwow/routes/comment.py index e69de29..bda7ae0 100644 --- a/suchwow/routes/comment.py +++ b/suchwow/routes/comment.py @@ -0,0 +1,30 @@ +from flask import render_template, Blueprint, flash +from flask import request, redirect, url_for, session +from suchwow.models import Post, Comment, Profile +from suchwow.utils.decorators import login_required + + +bp = Blueprint("comment", "comment") + +@bp.route("/comment/create/post/", methods=["GET", "POST"]) +@login_required +def create(post_id): + if not Post.filter(id=post_id): + flash("WTF, that post doesn't exist. Stop it, hackerman.") + return redirect(url_for("index")) + + if request.method == "POST": + comment_text = request.form.get("comment") + if len(comment_text) > 300: + flash("WTF, too many characters to post, asshole.") + return redirect(request.url) + commenter = Profile.get(username=session["auth"]["preferred_username"]) + post = Post.get(id=post_id) + c = Comment( + comment=comment_text, + commenter=commenter, + post=post, + ) + c.save() + return redirect(url_for("post.read", id=post_id)) + return render_template("comment/create.html") diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 0029ac0..6722a45 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -3,7 +3,7 @@ from flask import render_template, Blueprint, request, session, flash from flask import send_from_directory, redirect, url_for, current_app from werkzeug.utils import secure_filename from suchwow import wownero -from suchwow.models import Post +from suchwow.models import Post, Comment from suchwow.utils.decorators import login_required, profile_required from suchwow.utils.helpers import allowed_file @@ -15,11 +15,12 @@ def read(id): if Post.filter(id=id): wallet = wownero.Wallet() post = Post.get(id=id) + comments = Comment.select().where(Comment.post==post.id) if wallet.connected: address = wallet.addresses(account=post.account_index)[0] else: address = "?" - return render_template("post/read.html", post=post, address=address) + return render_template("post/read.html", post=post, address=address, comments=comments) else: return "no meme there brah" diff --git a/suchwow/templates/comment/create.html b/suchwow/templates/comment/create.html new file mode 100644 index 0000000..2c22e4f --- /dev/null +++ b/suchwow/templates/comment/create.html @@ -0,0 +1,19 @@ +{% extends 'base.html' %} + +{% block content %} + +
+
+

Leave a Comment

+
+
+ + +
+
+ +
+
+
+
+{% endblock %} diff --git a/suchwow/templates/navbar.html b/suchwow/templates/navbar.html index 00d9761..b0a1841 100755 --- a/suchwow/templates/navbar.html +++ b/suchwow/templates/navbar.html @@ -19,7 +19,7 @@ {% else %}