[FIX] website_forum: post edition working again

bzr revid: tde@openerp.com-20140411164455-2mx3yic1hquu0pil
This commit is contained in:
Thibault Delavallée 2014-04-11 18:44:55 +02:00
parent b6a1359b4f
commit a1e5f69cb3
2 changed files with 19 additions and 28 deletions

View File

@ -324,44 +324,40 @@ class WebsiteForum(http.Controller):
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/edit', type='http', auth="user", website=True, multilang=True)
def post_edit(self, forum, post, **kwargs):
cr, uid, context = request.cr, request.uid, request.context
tags = ""
for tag_name in post.tag_ids:
tags += tag_name.name + ","
values = self._prepare_forum_values(forum=forum)
values.update({
'question': post.parent_id,
'tags': tags,
'answer': post,
'is_answer': True if post else False,
'post': post,
'is_answer': bool(post.parent_id),
'searches': kwargs
})
return request.website.render("website_forum.edit_post", values)
@http.route('/forum/<model("forum.forum"):forum>/post/save', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def post_save(self, forum, **post):
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/save', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def post_save(self, forum, post, **kwargs):
cr, uid, context = request.cr, request.uid, request.context
vals = {
'content': post.get('content'),
}
question_tags = []
if post.get('question_tag') and post.get('question_tag').strip('[]'):
if kwargs.get('question_tag') and kwargs.get('question_tag').strip('[]'):
Tag = request.registry['forum.tag']
tags = post.get('question_tag').strip('[]').replace('"','').split(",")
tags = kwargs.get('question_tag').strip('[]').replace('"', '').split(",")
for tag in tags:
tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
if tag_ids:
question_tags += tag_ids
else:
new_tag = Tag.create(cr, uid, {'name' : tag,'forum_id' : forum.id}, context=context)
new_tag = Tag.create(cr, uid, {'name': tag, 'forum_id': forum.id}, context=context)
question_tags.append(new_tag)
vals.update({'tag_ids': [(6, 0, question_tags)], 'name': post.get('question_name')})
post_id = post.get('answer_id') if post.get('answer_id') else post.get('question_id')
new_question_id = request.registry['forum.post'].write( cr, uid, [int(post_id)], vals, context=context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('question_id')))
vals = {
'tag_ids': [(6, 0, question_tags)],
'name': kwargs.get('question_name'),
'content': kwargs.get('content'),
}
request.registry['forum.post'].write(cr, uid, [post.id], vals, context=context)
question = post.parent_id if post.parent_id else post
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
@http.route('/forum/<int:forum_id>/post/<int:post_id>/upvote', type='json', auth="public", multilang=True, website=True)
def post_upvote_tmp(self, forum_id, post_id, **kwargs):

View File

@ -309,21 +309,16 @@
<t t-call="website_forum.header">
<h3 t-if="not is_answer">Edit question</h3>
<h3 t-if="is_answer">Edit answer</h3>
<form t-attf-action="/forum/#{ slug(forum) }/post/save" method="post" role="form" class="tag_text">
<form t-attf-action="/forum/#{slug(forum)}/post/#{slug(post)}/save" method="post" role="form" class="tag_text">
<div t-if="not is_answer">
<input type="text" name="question_name" id="question_name" required="True"
t-attf-value="#{question.name}" class="form-control" placeholder="Edit your Question"/>
t-attf-value="#{post.name}" class="form-control" placeholder="Edit your Question"/>
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
</div>
<input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/>
<textarea name="content" required="True" class="form-control load_editor">
<t t-if="is_answer"> <t t-esc="answer.content"/></t>
<t t-if="not is_answer"><t t-esc="question.content"/></t>
<t t-esc="post.content"/>
</textarea>
<input name="question_id" t-att-value="question.id" type="hidden"/>
<div t-if="is_answer">
<input name="answer_id" t-att-value="answer.id" type="hidden"/>
</div>
<div t-if="not is_answer">
<br/>
<input type="text" name="question_tag" class="form-control col-md-9 load_tags" placeholder="Tags" t-attf-value="#{tags}"/>
@ -442,7 +437,7 @@
<a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)/reopen">reopen</a>
</li>
<li t-if="user.id == question.create_uid.id or user.karma&gt;=300">
<a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/edit">edit</a>
<a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/post/#{slug(question)}/edit">edit</a>
</li>
<li t-if="question.active and user.id == question.create_uid.id or user.karma&gt;=1000">
<a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/delete">delete</a>