summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2016-07-29 16:17:02 +0200
committerJeremy Kersten <jke@odoo.com>2016-07-29 17:29:25 +0200
commitf19d620ebe6dffb373ce13ee21c2335c67e467ef (patch)
treee6a13d5332beadc714ae439f23f2862b799969af /addons
parent6d43f280c9bfa589a88dec9433948861a93b39d7 (diff)
[FIX] website_forum: don't allow to post an empty question
Instead to post the empty question, now we redirect the end user to the question page with a warning. This commit closes #12962
Diffstat (limited to 'addons')
-rw-r--r--addons/website_forum/controllers/main.py5
-rw-r--r--addons/website_forum/views/website_forum.xml3
2 files changed, 7 insertions, 1 deletions
diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py
index 7dbac19620a..94b5f684879 100644
--- a/addons/website_forum/controllers/main.py
+++ b/addons/website_forum/controllers/main.py
@@ -317,8 +317,11 @@ class WebsiteForum(http.Controller):
'/forum/<model("forum.forum"):forum>/<model("forum.post"):post_parent>/reply'],
type='http', auth="user", methods=['POST'], website=True)
def post_create(self, forum, post_parent=None, post_type=None, **post):
- if post_type == 'question' and not post.get('post_name', '').strip():
+ if post_type == 'question' and not post.get('post_name', ''):
return request.website.render('website.http_error', {'status_code': _('Bad Request'), 'status_message': _('Title should not be empty.')})
+ if post.get('content', '') == '<p><br></p>':
+ return werkzeug.utils.redirect("/forum/%s/question/%s?nocontent=1" % (slug(forum), post_parent and slug(post_parent)))
+
post_tag_ids = forum._tag_to_write_vals(post.get('post_tags', ''))
new_question = request.env['forum.post'].create({
'forum_id': forum.id,
diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml
index ab29205ea40..5e5dea85da1 100644
--- a/addons/website_forum/views/website_forum.xml
+++ b/addons/website_forum/views/website_forum.xml
@@ -690,6 +690,9 @@
- no need to answer the same question twice. Also, please <b>don't forget to vote</b>
- it really helps to select the best questions and answers!
</p>
+ <t t-if="request.params.get('nocontent')">
+ <p class='alert alert-danger' role='alert'>You cannot post an empty answer</p>
+ </t>
<form t-attf-action="/forum/#{ slug(forum) }/#{slug(question)}/reply" method="post" class="js_website_submit_form" role="form">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/>