From 4968868d3ac112fc2afe3935a089810746998000 Mon Sep 17 00:00:00 2001 From: Xevion <--get> Date: Tue, 29 Mar 2022 01:30:26 -0500 Subject: [PATCH] Add field rendering Macro for new form validation & add Flask-WTF to Pipfile --- Pipfile | 1 + Pipfile.lock | 18 +++++++++++++++++- forms.py | 13 +------------ templates/macros.html | 12 ++++++++++++ 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 templates/macros.html diff --git a/Pipfile b/Pipfile index 67baa41..66c566c 100644 --- a/Pipfile +++ b/Pipfile @@ -15,6 +15,7 @@ humanize = "*" gunicorn = "*" psycopg2 = "*" profanity-filter = "*" +flask-wtf = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 3015107..d1687b1 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "e847c58401b17c65209f6f6d77aacb1926b2f8805007f4629b67fcf95dccb209" + "sha256": "9b3713a297f7309e66d58786655c30bf4f17eaebe39c2f407ad357bf03ba6e13" }, "pipfile-spec": 6, "requires": { @@ -136,6 +136,14 @@ "index": "pypi", "version": "==2.5.1" }, + "flask-wtf": { + "hashes": [ + "sha256:01feccfc395405cea48a3f36c23f0d766e2cc6fd2a5a065ad50ad3e5827ec797", + "sha256:872fbb17b5888bfc734edbdcf45bc08fb365ca39f69d25dc752465a455517b28" + ], + "index": "pypi", + "version": "==1.0.0" + }, "greenlet": { "hashes": [ "sha256:0051c6f1f27cb756ffc0ffbac7d2cd48cb0362ac1736871399a739b2885134d3", @@ -685,6 +693,14 @@ "index": "pypi", "version": "==2.0.3" }, + "wtforms": { + "hashes": [ + "sha256:6b351bbb12dd58af57ffef05bc78425d08d1914e0fd68ee14143b7ade023c5bc", + "sha256:837f2f0e0ca79481b92884962b914eba4e72b7a2daaf1f939c890ed0124b834b" + ], + "markers": "python_version >= '3.7'", + "version": "==3.0.1" + }, "zipp": { "hashes": [ "sha256:9f50f446828eb9d45b267433fd3e9da8d801f614129124863f9c51ebceafb87d", diff --git a/forms.py b/forms.py index 564199b..e04c212 100644 --- a/forms.py +++ b/forms.py @@ -14,7 +14,7 @@ pf = ProfanityFilter() def edit_profile_post(username): user = db.session.query(User).filter_by(username=username).first_or_404() - # Ignore non + # Allow admins to edit profiles, but deny other users if not current_user.is_admin and current_user.id != user.id: return redirect(url_for('main.user', username=username)) @@ -31,17 +31,6 @@ def edit_profile_post(username): def new_post(): post_text = request.form.get('text') - if len(post_text) < 15: - flash('Must have at least 15 characters of text.') - return redirect(url_for('main.feed')) - elif len(post_text) > 1000: - flash('Cannot have more than 1000 characters of text.') - return redirect(url_for('main.feed')) - - if not pf.is_clean(post_text): - flash('Sorry, profanity is not allowed on runnerspace.') - return redirect(url_for('main.feed')) - post = Post(author=current_user.id, text=post_text) db.session.add(post) db.session.commit() diff --git a/templates/macros.html b/templates/macros.html new file mode 100644 index 0000000..0b6bfda --- /dev/null +++ b/templates/macros.html @@ -0,0 +1,12 @@ +{% macro render_field(field) %} +
{{ field.label }} +
{{ field(**kwargs)|safe }} + {% if field.errors %} + + {% endif %} +
+{% endmacro %}