aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2015-04-01 22:56:57 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2015-04-01 22:56:57 -0400
commitd390b55e60bf97de9010ff518943920b680657b0 (patch)
tree89a5b13bd569530b2474355abad52adf38f6b70d /famille.py
parent5b912c458d5794e346ce905daedb8e82783a12c1 (diff)
downloadfamille-flask-d390b55e60bf97de9010ff518943920b680657b0.tar.gz
Do not add empty comments to the database
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/famille.py b/famille.py
index d958bcb..0a4a3d6 100644
--- a/famille.py
+++ b/famille.py
@@ -193,13 +193,14 @@ def show_news(news_id):
elif request.method == 'POST':
user_id = session['user_id']
content = request.form['content']
- content_cache = rstify(content)
- db = get_db()
- db.execute("INSERT INTO comments "
- "('user_id', 'content', 'news_id', 'content_cache') "
- "VALUES (?, ?, ?, ?)",
- (user_id, content, news_id, content_cache))
- db.commit()
+ if content:
+ content_cache = rstify(content)
+ db = get_db()
+ db.execute("INSERT INTO comments "
+ "('user_id', 'content', 'news_id', 'content_cache') "
+ "VALUES (?, ?, ?, ?)",
+ (user_id, content, news_id, content_cache))
+ db.commit()
return redirect(url_for('show_news', news_id=news_id))