mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
setup comments for posts
This commit is contained in:
parent
4262ec9f04
commit
d62aebabe4
6 changed files with 59 additions and 4 deletions
|
@ -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():
|
||||
|
|
|
@ -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/<post_id>", 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")
|
|
@ -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"
|
||||
|
||||
|
|
19
suchwow/templates/comment/create.html
Normal file
19
suchwow/templates/comment/create.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container" style="width:40%;">
|
||||
<div class="submit">
|
||||
<h1>Leave a Comment</h1>
|
||||
<form method=post enctype=multipart/form-data class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="inlineFormInput">Text</label>
|
||||
<input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" id="inlineFormInput" placeholder="Comment text (max 300 chars)" name="comment">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -19,7 +19,7 @@
|
|||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('profile.edit') }}">Profile ({{session.auth.preferred_username}})</a>
|
||||
<a class="nav-link" href="{{ url_for('profile.edit') }}">Profile ({{ session.auth.preferred_username }})</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
<h3>Comments</h3>
|
||||
{% if comments %}
|
||||
{% for comment in comments %}
|
||||
{{ comment.text }}
|
||||
<p id="comment{{ comment.id }}">
|
||||
<a href="{{ url_for('post.read', id=post.id, _external=True) }}#comment{{ comment.id }}">#{{ comment.id }}</a> - <i>{{ comment.commenter.username }}</i> - {{ comment.comment }}
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<p>No comments yet.</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<hr>
|
||||
<a href="{{ url_for('comment.create', post_id=post.id) }}"><button class="btn btn-warning">Leave a Comment</button></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue