Post.write( cr, uid, [post.id, post.parent_id.id], { 'correct': correct }, context=context)
return correct
+ @http.route('/forum/favourite_question', type='json', auth="user", multilang=True, methods=['POST'], website=True)
+ def favourite_question(self, **kwarg):
+ cr, uid, context = request.cr, request.uid, request.context
+ Post = request.registry['website.forum.post']
+ post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context)
+ favourite = False if post.user_favourite else True
+ favourite_ids = [(4, uid)]
+ if post.user_favourite:
+ favourite_ids = [(3, uid)]
+ Post.write( cr, uid, [post.id], { 'favourite_ids': favourite_ids }, context=context)
+ return favourite
+
@http.route('/forum/<model("website.forum"):forum>/close/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
def close_question(self, forum, post, **kwarg):
cr, uid, context = request.cr, request.uid, request.context
_description = "Question"
_inherit = ['mail.thread', 'website.seo.metadata']
- def _get_votes(self, cr, uid, ids, field_name, arg, context):
- res = dict.fromkeys(ids, 0)
- # Note: read_group is not returning all fields which we passed in list.when it will work uncomment this code and remove remaining code
- #Vote = self.pool['website.forum.post.vote']
- #data = Vote.read_group(cr, uid, [('post_id','in', ids), ('user_id', '=', uid)], [ "post_id", "vote"], groupby=["post_id"], context=context)
- #for rec in data:
- # res[rec[post_id][0]] = rec['vote']
- for post in self.browse(cr, uid, ids, context=context):
- if post.vote_ids:
- for vote in post.vote_ids:
- if vote.user_id.id == uid:
- if vote.vote == '1':
- res[post.id] = 1
- elif vote.vote == '-1':
- res[post.id] = -1
- return res
-
def _get_vote_count(self, cr, uid, ids, field_name, arg, context):
res = dict.fromkeys(ids, 0)
for post in self.browse(cr, uid, ids, context=context):
result[statistic.post_id.id] = True
return result.keys()
+ def _get_user_vote(self, cr, uid, ids, field_name, arg, context):
+ res = dict.fromkeys(ids, 0)
+ # Note: read_group is not returning all fields which we passed in list.when it will work uncomment this code and remove remaining code
+ #Vote = self.pool['website.forum.post.vote']
+ #data = Vote.read_group(cr, uid, [('post_id','in', ids), ('user_id', '=', uid)], [ "post_id", "vote"], groupby=["post_id"], context=context)
+ #for rec in data:
+ # res[rec[post_id][0]] = rec['vote']
+ for post in self.browse(cr, uid, ids, context=context):
+ for vote in post.vote_ids:
+ if vote.user_id.id == uid:
+ if vote.vote == '1':
+ res[post.id] = 1
+ elif vote.vote == '-1':
+ res[post.id] = -1
+ return res
+
+ def _get_user_favourite(self, cr, uid, ids, field_name, arg, context):
+ res = dict.fromkeys(ids, False)
+ user = self.pool['res.users'].browse(cr, uid, uid, context=context)
+ for post in self.browse(cr, uid, ids, context=context):
+ if user in post.favourite_ids:
+ res[post.id] = True
+ return res
+
_columns = {
'name': fields.char('Title', size=128),
'forum_id': fields.many2one('website.forum', 'Forum', required=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'),
+ 'vote_ids':fields.one2many('website.forum.post.vote', 'post_id', 'Votes'),
+ 'user_vote':fields.function(_get_user_vote, string="My Vote", type='integer'),
'favourite_ids': fields.many2many('res.users', 'forum_favourite_rel', 'forum_id', 'user_id', 'Favourite'),
+ 'user_favourite':fields.function(_get_user_favourite, string="My Favourite", type='boolean'),
'state': fields.selection([('active', 'Active'), ('close', 'Close'),('offensive', 'Offensive')], 'Status'),
'active': fields.boolean('Active'),
help="Comments on forum post",
),
- 'user_vote':fields.function(_get_votes, string="My Vote", type='integer',
- store={
- 'website.forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
- 'website.forum.post.vote': (_get_vote, [], 10),
- }
- ),
-
'vote_count':fields.function(_get_vote_count, string="Votes", type='integer',
store={
'website.forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
.oe_answer_false
color: #999999
+.forum_favourite_question
+ color: #ffcc00 !important
+
.load_tags
width: 845px !important
-.fa-thumbs-up, .fa-thumbs-down, .oe_answer_true, .oe_answer_false
+a.no-decoration
cursor: pointer
+ text-decoration: none !important
.faq-question:hover
text-decoration: none !important
-webkit-box-shadow: 0px 4px 6px 2px #eeeeee
box-shadow: 0px 4px 6px 2px #eeeeee
+.forum_user_flag
+ max-width: 25px
+ display: inline-block
+ margin-left: 2px
+
.tag_text .text-core .text-wrap
textarea, input, .text-dropdown, .text-prompt
- font: 1.2em "Helvetica Neue",Helvetica,Arial,sans-serif !important
+ font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important
.text-tags .text-tag .text-button
- font: 1.2em "Helvetica Neue",Helvetica,Arial,sans-serif !important
+ font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important
height: 1.2em !important
\ No newline at end of file
<template id="vote">
<div t-attf-class="box oe_grey">
- <a t-attf-class="vote_up fa fa-thumbs-up #{post.user_vote == 1 and 'text-success' or ''}"
+ <a t-attf-class="vote_up fa fa-thumbs-up no-decoration #{post.user_vote == 1 and 'text-success' or ''}"
t-attf-id="#{post.id}" t-attf-value="1"/>
<span id="vote_count" t-esc="post.vote_count"/>
- <a t-attf-class="vote_down fa fa-thumbs-down #{post.user_vote == -1 and 'text-warning' or ''}"
+ <a t-attf-class="vote_down fa fa-thumbs-down no-decoration #{post.user_vote == -1 and 'text-warning' or ''}"
t-attf-id="#{post.id}" t-attf-value="-1"/>
<div>
votes
<span t-if="question.child_count>1">Answers</span>
<span t-if="question.child_count<=1">Answer</span>
</div>
+ <div>
+ <a t-attf-id="#{question.id}" t-attf-class="favourite_question no-decoration fa fa-2x fa-star #{question.user_favourite and 'forum_favourite_question' or ''}"/>
+ </div>
</div>
<div style="margin-left: 95px;">
<h1 class="mt0">
<t t-set="post" t-value="answer"/>
</t>
<div class="text-muted">
- <a t-attf-id="#{answer.id}" t-if="answer.correct" class="accept_answer fa fa-2x fa-check-circle oe_answer_true"/>
- <a t-attf-id="#{answer.id}" t-if="not answer.correct" class="accept_answer fa fa-2x fa-check-circle oe_answer_false"/>
+ <a t-attf-id="#{answer.id}" t-if="answer.correct" class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_true"/>
+ <a t-attf-id="#{answer.id}" t-if="not answer.correct" class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_false"/>
</div>
</div>
<div style="margin-left: 95px;" class="clearfix">
<td>
<span class="fa fa-thumbs-up"/>
<span t-esc="up_votes"/>
- <span class="fa fa-thumbs-down "/>
+ <span class="fa fa-thumbs-down"/>
<span t-esc="down_votes"/>
</td>
</tr>