From f569620fced52e11d74301105241196bf0dab9fe Mon Sep 17 00:00:00 2001 From: 0x01fe Date: Wed, 27 Mar 2024 14:50:43 -0500 Subject: [PATCH] started adding the comment thing --- .gitignore | 1 + app/app.py | 18 +++++++++++++++--- app/comment.py | 14 ++++++++++++++ app/config.ini | 9 --------- app/static/style.css | 23 +++++++++++++++++++++++ app/templates/index.html | 19 ++++++++++++++++++- requirements.txt | 4 +++- 7 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 app/comment.py delete mode 100644 app/config.ini diff --git a/.gitignore b/.gitignore index 9fe92d2..8b502d0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__ docker-compose.yaml *.sh +*.ini # Ignore images in posts *.jpg diff --git a/app/app.py b/app/app.py index 3492a78..c5509d4 100644 --- a/app/app.py +++ b/app/app.py @@ -3,13 +3,19 @@ import configparser import random import flask +import flask_wtf.csrf +import flask_session import waitress import markdown from post import Post +import comment app = flask.Flask(__name__, static_url_path='', static_folder='static') +csrf = flask_wtf.csrf.CSRFProtect() +csrf.init_app(app) + CONFIG_PATH = "./config.ini" config = configparser.ConfigParser() config.read(CONFIG_PATH) @@ -66,14 +72,20 @@ def index(): # Get posts posts = get_posts() - post_bodies = [] + # Get Comments + comments = [] + + posts_and_comments = [] for post in posts: - post_bodies.append(post.body) + posts_and_comments.append((post.body, comments)) # Get status status = get_status() - return flask.render_template('index.html', posts=post_bodies, status=status) + # Setup Comment Form + form = comment.CommentForm() + + return flask.render_template('index.html', posts=posts_and_comments, status=status, form=form) # Games Page @app.route('/games/') diff --git a/app/comment.py b/app/comment.py new file mode 100644 index 0000000..9b5d3b1 --- /dev/null +++ b/app/comment.py @@ -0,0 +1,14 @@ +import flask +import flask_session +import flask_wtf +import wtforms + + + + +class CommentForm(flask_wtf.FlaskForm): + textbox = wtforms.TextAreaField() + + + + diff --git a/app/config.ini b/app/config.ini deleted file mode 100644 index 8d00b71..0000000 --- a/app/config.ini +++ /dev/null @@ -1,9 +0,0 @@ -[POSTS] -posts_folder=./posts - -[STATUS] -status_file=./resources/status.text - -[NETWORK] -PORT=1111 -DEV=0 diff --git a/app/static/style.css b/app/static/style.css index 3ba8574..3d83e15 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -172,3 +172,26 @@ a:hover { line-height: 2.25; text-indent: 3em; } + +.comment-container { + background-color: var(--primary40); + border-style: var(--borders-style); + border-radius: var(--border-radius); + + padding: 1em; + margin: 1em; +} + +.comment-editor input { + width: 100%; + padding: 3em 0; + line-height: 140%; + + border-style: solid; + /* border-color: var(--secondary50); */ + border-radius: var(--border-radius); +} + +.comment-editor input:focus { + border: 3px solid var(--accent); +} diff --git a/app/templates/index.html b/app/templates/index.html index a5bfb0c..21daca3 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -25,7 +25,24 @@
{% for post in posts %} -
{{ post|safe }}
+
+ {{ post[0]|safe }} +
+ {% for comment in post[1] %} +
{{ comment|safe }}
+ {% endfor %} + {% if user %} +
+

{{ user }}

+
+ + {{ form.textbox }} + +
+
+ {% endif %} +
+
{% endfor %}
diff --git a/requirements.txt b/requirements.txt index bb91e2f..a8030e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ Markdown==3.5.2 Flask==2.2.3 waitress==2.1.2 -Werkzeug==2.2.3 \ No newline at end of file +Werkzeug==2.2.3 +Flask-Session==0.5.0 +Flask-WTF==1.1.1 \ No newline at end of file