[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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user