mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-15 06:13:07 -06:00
Add field rendering Macro for new form validation & add Flask-WTF to Pipfile
This commit is contained in:
1
Pipfile
1
Pipfile
@@ -15,6 +15,7 @@ humanize = "*"
|
||||
gunicorn = "*"
|
||||
psycopg2 = "*"
|
||||
profanity-filter = "*"
|
||||
flask-wtf = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
18
Pipfile.lock
generated
18
Pipfile.lock
generated
@@ -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",
|
||||
|
||||
13
forms.py
13
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()
|
||||
|
||||
12
templates/macros.html
Normal file
12
templates/macros.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% macro render_field(field) %}
|
||||
<dt>{{ field.label }}
|
||||
<dd>{{ field(**kwargs)|safe }}
|
||||
{% if field.errors %}
|
||||
<ul class=errors>
|
||||
{% for error in field.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endmacro %}
|
||||
Reference in New Issue
Block a user