[FIX] website_forum: convert comment to post is back and works

bzr revid: tde@openerp.com-20140411161916-rlobfxosniii66m4
This commit is contained in:
Thibault Delavallée
2014-04-11 18:19:16 +02:00
parent 907a97b15b
commit b6a1359b4f
4 changed files with 38 additions and 29 deletions
+25 -20
View File
@@ -115,7 +115,7 @@ class WebsiteForum(http.Controller):
return request.website.render("website_forum.forum_index", values)
@http.route(['/forum/<model("forum.forum"):forum>/faq'], type='http', auth="public", website=True, multilang=True)
def faq(self, forum, **post):
def forum_faq(self, forum, **post):
values = self._prepare_forum_values(forum=forum, searches=dict(), **post)
return request.website.render("website_forum.faq", values)
@@ -148,7 +148,7 @@ class WebsiteForum(http.Controller):
return request.website.render("website_forum.ask_question", values)
@http.route('/forum/<model("forum.forum"):forum>/question/new', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def register_question(self, forum, **post):
def question_create(self, forum, **post):
cr, uid, context = request.cr, request.uid, request.context
Tag = request.registry['forum.tag']
question_tag_ids = []
@@ -186,23 +186,6 @@ class WebsiteForum(http.Controller):
})
return request.website.render("website_forum.post_description_full", values)
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment', type='http', auth="public", methods=['POST'], website=True)
def post_comment(self, forum, post, **kwargs):
# tde: fix post / question
if not request.session.uid:
return login_redirect()
cr, uid, context = request.cr, request.uid, request.context
if kwargs.get('comment'):
# TDE FIXME: check that post_id is the question or one of its answers
if request.registry['res.users'].has_group(cr, uid, 'website_mail.group_comment'):
request.registry['forum.post'].message_post(
cr, uid, post.id,
body=kwargs.get('comment'),
type='comment',
subtype='mt_comment',
context=dict(context, mail_create_nosubcribe=True))
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
@http.route('/forum/<int:forum_id>/question/<int:question_id>/toggle_favourite', type='json', auth="user", multilang=True, website=True)
def question_toggle_favorite_tmp(self, forum_id, question_id, **post):
if not request.session.uid:
@@ -281,6 +264,9 @@ class WebsiteForum(http.Controller):
request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'active': True}, context=request.context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
# Answers
# --------------------------------------------------
# Post
# --------------------------------------------------
@@ -296,6 +282,24 @@ class WebsiteForum(http.Controller):
}, context=request.context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment', type='http', auth="public", methods=['POST'], website=True)
def post_comment(self, forum, post, **kwargs):
# tde: fix post / question
if not request.session.uid:
return login_redirect()
question = post.parent_id if post.parent_id else post
cr, uid, context = request.cr, request.uid, request.context
if kwargs.get('comment') and post.forum_id.id == forum.id:
# TDE FIXME: check that post_id is the question or one of its answers
if request.registry['res.users'].has_group(cr, uid, 'website_mail.group_comment'):
request.registry['forum.post'].message_post(
cr, uid, post.id,
body=kwargs.get('comment'),
type='comment',
subtype='mt_comment',
context=dict(context, mail_create_nosubcribe=True))
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/toggle_correct', type='json', auth="public", website=True)
def post_toggle_correct(self, forum, post, **kwargs):
cr, uid, context = request.cr, request.uid, request.context
@@ -563,7 +567,8 @@ class WebsiteForum(http.Controller):
'content': comment.body,
}
request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context)
return self.post_answer(forum, post.parent_id and post.parent_id.id or post.id, **values)
question = post.parent_id if post.parent_id else post
return self.post_new(forum, question, **values)
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/convert_to_comment', type='http', auth="user", multilang=True, website=True)
def convert_answer_to_comment(self, forum, post, **kwarg):
@@ -63,7 +63,8 @@ a.no-decoration {
}
.oe_comment_grey {
color: whitesmoke;
background-color: whitesmoke;
padding: 4px;
}
.country_flag {
@@ -50,7 +50,8 @@ a.no-decoration
color: #428bca
.oe_comment_grey
color: #f5f5f5
background-color: #f5f5f5
padding: 4px
.country_flag
max-height: 16px
+9 -7
View File
@@ -542,19 +542,21 @@
<template id="post_comment">
<div class="row clearfix">
<div class="col-sm-10 col-sm-offset-2">
<div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_comment_grey" style="padding: 4px;">
<div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_comment_grey mb8">
<small class="text-muted">
<button type="button" t-if="user.karma&gt;=750" t-att-id="message.id" class="close comment_delete">&amp;times;</button>
<button type="button" t-if="user.partner_id.id == message.author_id.id and user.karma&gt;=750" t-att-id="message.id" class="close comment_delete">&amp;times;</button>
<span t-field="message.body"/>
<a t-attf-href="/forum/#{slug(forum)}/user/#{message.id}"
t-field="message.author_id" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}'
style="display: inline-block;"/>
on <span t-field="message.date" t-field-options='{"format":"short"}'/>
<a t-attf-href="/forum/#{slug(forum)}/user/#{message.id}"
t-field="message.author_id" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}'
style="display: inline-block;"/>
on <span t-field="message.date" t-field-options='{"format":"short"}'/>
<a class="fa fa-magic text-muted pull-right"
t-attf-href="/forum/#{slug(forum)}/post/#{slug(object)}/comment/#{slug(message)}/convert_to_answer">Convert as an answer</a>
</small>
</div>
<div class="css_editable_mode_hidden">
<form t-attf-id="comment#{ object._name.replace('.','') + '-' + str(object.id) }" class="collapse"
t-attf-action="/forum/#{slug(forum)}/question/#{slug(object)}/comment" method="POST">
t-attf-action="/forum/#{slug(forum)}/post/#{slug(object)}/comment" method="POST">
<input name="post_id" t-att-value="object.id" type="hidden"/>
<textarea name="comment" class="form-control" placeholder="Comment this post..."/>
<button type="submit" class="btn btn-primary mt8">Post</button>