From d390b55e60bf97de9010ff518943920b680657b0 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 1 Apr 2015 22:56:57 -0400 Subject: Do not add empty comments to the database --- famille.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'famille.py') 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)) -- cgit v1.2.3-70-g09d2