|
|
|
@ -9,8 +9,8 @@ from sqlalchemy import func
|
|
|
|
|
from sqlalchemy.orm import aliased
|
|
|
|
|
|
|
|
|
|
from yadc import db
|
|
|
|
|
from yadc.forms import UploadPostForm
|
|
|
|
|
from yadc.models import FILETYPE, RATING, Post, Tag
|
|
|
|
|
from yadc.forms import UploadForm, CommentForm
|
|
|
|
|
from yadc.models import FILETYPE, RATING, Post, Tag, Comment
|
|
|
|
|
from yadc.utils import query_replace
|
|
|
|
|
|
|
|
|
|
bp = Blueprint('post', __name__)
|
|
|
|
@ -77,12 +77,15 @@ def post_show(id):
|
|
|
|
|
tag.count = count
|
|
|
|
|
tag.endpoint = query_replace({'tags': tag.content.replace(' ','_')}, url_for('.posts'))
|
|
|
|
|
|
|
|
|
|
return render_template('post.html', post=post, tags=post.tags)
|
|
|
|
|
form = CommentForm()
|
|
|
|
|
form.post_id.data = post.id
|
|
|
|
|
|
|
|
|
|
return render_template('post.html', post=post, tags=post.tags, comments=post.comments, comment_form=form)
|
|
|
|
|
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST'])
|
|
|
|
|
@login_required
|
|
|
|
|
def post_upload():
|
|
|
|
|
form = UploadPostForm(request.form)
|
|
|
|
|
def upload():
|
|
|
|
|
form = UploadForm(request.form)
|
|
|
|
|
if request.method == 'POST' and form.validate():
|
|
|
|
|
file = request.files.get(form.post_img.name)
|
|
|
|
|
file.data = io.BytesIO(file.read())
|
|
|
|
@ -112,6 +115,22 @@ def post_upload():
|
|
|
|
|
|
|
|
|
|
flash('Successfully submitted {}'.format(str(post)))
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('.post_upload'))
|
|
|
|
|
return redirect(url_for('.upload'))
|
|
|
|
|
|
|
|
|
|
return render_template('upload.html', form=form)
|
|
|
|
|
|
|
|
|
|
@bp.route('comment', methods=['POST'])
|
|
|
|
|
@login_required
|
|
|
|
|
def comment():
|
|
|
|
|
form = CommentForm(request.form)
|
|
|
|
|
if request.method == 'POST' and form.validate():
|
|
|
|
|
comment = Comment(content=form.content.data, post_id=form.post_id.data, user=current_user)
|
|
|
|
|
|
|
|
|
|
db.session.add(comment)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
flash('Successfully submitted {}'.format(str(comment)))
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('.post_show', id=form.post_id.data))
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('.posts'))
|