Update main.py
parent
55552e14b7
commit
3a433e69cd
7
main.py
7
main.py
|
@ -12,6 +12,7 @@ from functools import wraps
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
from sqlalchemy import func
|
||||||
# import csv
|
# import csv
|
||||||
# from sqlalchemy import create_engine, Table, MetaData
|
# from sqlalchemy import create_engine, Table, MetaData
|
||||||
|
|
||||||
|
@ -278,14 +279,16 @@ def create_post(category_id):
|
||||||
def view_post(category_name, post_id):
|
def view_post(category_name, post_id):
|
||||||
post = ForumPost.query.get_or_404(post_id)
|
post = ForumPost.query.get_or_404(post_id)
|
||||||
comments = ForumComment.query.filter_by(post_id=post_id).all()
|
comments = ForumComment.query.filter_by(post_id=post_id).all()
|
||||||
|
comment_count = len(comments)
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
created_by = request.form['created_by']
|
created_by = request.form['created_by']
|
||||||
text = request.form['text']
|
text = request.form['text']
|
||||||
new_comment = ForumComment(post_id=post_id, created_by=created_by, text=text) # type: ignore
|
creation_date = datetime.now()
|
||||||
|
new_comment = ForumComment(post_id=post_id, created_by=created_by, text=text, creation_date=creation_date)
|
||||||
db.session.add(new_comment)
|
db.session.add(new_comment)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('view_post', category_name=category_name, post_id=post_id))
|
return redirect(url_for('view_post', category_name=category_name, post_id=post_id))
|
||||||
return render_template('post.html', post=post, comments=comments)
|
return render_template('post.html', post=post, comment_count=comment_count, comments=comments)
|
||||||
|
|
||||||
@app.route('/forums/upvote_post/<int:post_id>')
|
@app.route('/forums/upvote_post/<int:post_id>')
|
||||||
def upvote_post(post_id):
|
def upvote_post(post_id):
|
||||||
|
|
Loading…
Reference in New Issue