[ADD] added comment feature on question and answers, improved code to redirect to question from user activity.
bzr revid: tpa@tinyerp.com-20140306112816-m4o17q6wg6qyomc3
This commit is contained in:
parent
f02c071457
commit
976340ca34
|
@ -143,6 +143,28 @@ class website_forum(http.Controller):
|
|||
}
|
||||
return request.website.render("website_forum.post_description_full", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/comment'], type='http', auth="public", methods=['POST'], website=True)
|
||||
def post_comment(self, forum, post_id=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
if kwargs.get('comment'):
|
||||
user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
group_ids = user.groups_id
|
||||
group_id = request.registry["ir.model.data"].get_object_reference(cr, uid, 'website_mail', 'group_comment')[1]
|
||||
if group_id in [group.id for group in group_ids]:
|
||||
Post = request.registry['website.forum.post']
|
||||
Post.check_access_rights(cr, uid, 'read')
|
||||
Post.message_post(
|
||||
cr, SUPERUSER_ID, int(post_id),
|
||||
body=kwargs.get('comment'),
|
||||
type='comment',
|
||||
subtype='mt_comment',
|
||||
author_id=user.partner_id.id,
|
||||
context=dict(context, mail_create_nosubcribe=True))
|
||||
|
||||
post = request.registry['website.forum.post'].browse(cr, uid, int(post_id), context=context)
|
||||
question_id = post.parent_id.id if post.parent_id else post.id
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),question_id))
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/user/<model("res.users"):user>'], type='http', auth="public", website=True, multilang=True)
|
||||
def open_user(self, forum, user, **post):
|
||||
answers = {}
|
||||
|
|
|
@ -74,19 +74,20 @@ class Post(osv.Model):
|
|||
'create_uid': fields.many2one('res.users', 'Asked by', select=True, readonly=True ),
|
||||
'write_date': fields.datetime('Update on', select=True, readonly=True ),
|
||||
'write_uid': fields.many2one('res.users', 'Update by', select=True, readonly=True),
|
||||
|
||||
|
||||
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
||||
'vote_ids':fields.one2many('website.forum.post.vote', 'post_id', 'Vote'),
|
||||
|
||||
|
||||
'favourite_ids': fields.many2many('res.users', 'forum_favourite_rel', 'forum_id', 'user_id', 'Favourite'),
|
||||
|
||||
|
||||
'state': fields.selection([('active', 'Active'),('close', 'Close'),('offensive', 'Offensive')], 'Status'),
|
||||
'active': fields.boolean('Active'),
|
||||
'views': fields.integer('Views'),
|
||||
|
||||
|
||||
'parent_id': fields.many2one('website.forum.post', 'Parent'),
|
||||
'child_ids': fields.one2many('website.forum.post', 'parent_id', 'Child'),
|
||||
|
||||
|
||||
'history_ids': fields.one2many('blog.post.history', 'post_id', 'History', help='Last post modifications'),
|
||||
# TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
||||
'website_message_ids': fields.one2many(
|
||||
'mail.message', 'res_id',
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
|
||||
access_website_forum,website.forum,model_website_forum,base.group_public,1,0,0,0
|
||||
access_website_forum_post,website.forum.post,model_website_forum_post,base.group_public,1,0,0,0
|
||||
access_website_forum_post_history,website.forum.post.history,model_website_forum_post_history,base.group_public,1,0,0,0
|
||||
access_website_forum_post_vote,website.forum.post.vote,model_website_forum_post_vote,base.group_public,1,0,0,0
|
||||
|
|
|
|
@ -376,6 +376,9 @@
|
|||
<span class="text-muted">Asked on <span t-field="question.write_date"/></span>
|
||||
</t>
|
||||
</div>
|
||||
<t t-call="website_forum.comments">
|
||||
<t t-set="object" t-value="question"/>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
|
@ -432,6 +435,10 @@
|
|||
<span class="text-muted">Answered on <span t-field="answer.create_date"/></span>
|
||||
</t>
|
||||
</div>
|
||||
|
||||
<t t-call="website_forum.comments">
|
||||
<t t-set="object" t-value="answer"/>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="not answer_done">
|
||||
|
@ -444,6 +451,28 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<template id="comments">
|
||||
<h4 class="mt10"> <b>Comments</b> </h4>
|
||||
<div class="mb10 css_editable_mode_hidden">
|
||||
<form id="comment" t-attf-action="/forum/#{ slug(forum) }/comment" method="POST">
|
||||
<input name="post_id" t-att-value="object.id" type="hidden"/>
|
||||
<textarea rows="2" name="comment" class="form-control" placeholder="Write a comment..."></textarea>
|
||||
<button type="submit" class="btn btn-primary mt8">Post</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="clearfix"/>
|
||||
<ul class="media-list" id="comments-list">
|
||||
<li t-foreach="object.website_message_ids" t-as="message" class="media">
|
||||
<div class="media-body">
|
||||
<div t-field="message.body"/>
|
||||
<h5 class="media-heading">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.author_id.id }" t-field="message.author_id"/>
|
||||
<small>on <span t-field="message.date"/></small>
|
||||
</h5>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<template id="tag">
|
||||
<t t-call="website_forum.header">
|
||||
|
@ -573,9 +602,11 @@
|
|||
<li t-foreach="user.activity_ids" t-as="activity" class="media">
|
||||
<small t-esc="activity.create_date" class="pull-left"/>
|
||||
<span t-field="activity.type" class="label label-info"/>
|
||||
<a t-esc="activity.name" t-if="not activity.post_id.parent_id"/>
|
||||
<a t-esc="activity.name" t-if="not activity.post_id.parent_id"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ activity.post_id.id }"/>
|
||||
<t t-if="activity.post_id.parent_id">
|
||||
<a t-esc="activity.post_id.parent_id.name"/>
|
||||
<a t-esc="activity.post_id.parent_id.name"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ activity.post_id.parent_id.id }"/>
|
||||
<span class="glyphicon glyphicon-play"/>
|
||||
<t t-esc="activity.post_id.content[0:100]"/>
|
||||
<strong> ... </strong>
|
||||
|
|
Loading…
Reference in New Issue