[ADD] added new functionality to follow question and improved some code.
bzr revid: tpa@tinyerp.com-20140328051606-sgrmo7nlwtvps966
This commit is contained in:
parent
804ef37691
commit
02735c1982
|
@ -158,16 +158,25 @@ class website_forum(http.Controller):
|
|||
request.session[request.session_id].append(question.id)
|
||||
post_obj._set_view_count(cr, SUPERUSER_ID, [question.id], 'views', 1, {}, context=context)
|
||||
|
||||
#Check that user have answered question or not.
|
||||
answer_done = False
|
||||
for answer in question.child_ids:
|
||||
if answer.user_id.id == request.uid:
|
||||
answer_done = True
|
||||
|
||||
#Check that user is following question or not
|
||||
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
||||
message_follower_ids = [follower.id for follower in question.message_follower_ids]
|
||||
following = True if partner_id in message_follower_ids else False
|
||||
|
||||
filters = 'question'
|
||||
values = {
|
||||
'question': question,
|
||||
'question_data': True,
|
||||
'notifications': self._get_notifications(),
|
||||
'searches': post,
|
||||
'filters': filters,
|
||||
'following': following,
|
||||
'answer_done': answer_done,
|
||||
'reversed': reversed,
|
||||
'forum': forum,
|
||||
|
@ -205,29 +214,40 @@ class website_forum(http.Controller):
|
|||
Post = request.registry['website.forum.post']
|
||||
Vote = request.registry['website.forum.post.vote']
|
||||
Activity = request.registry['mail.message']
|
||||
Followers = request.registry['mail.followers']
|
||||
Data = request.registry["ir.model.data"]
|
||||
|
||||
#questions asked by user.
|
||||
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id), ('parent_id', '=', False),
|
||||
#questions and answers by user.
|
||||
user_questions, user_answers = [], []
|
||||
user_post_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id),
|
||||
'|', ('active', '=', False), ('active', '=', True)], context=context)
|
||||
user_questions = Post.browse(cr, uid, question_ids, context=context)
|
||||
user_posts = Post.browse(cr, uid, user_post_ids, context=context)
|
||||
for record in user_posts:
|
||||
if record.parent_id:
|
||||
user_answers.append(record)
|
||||
else:
|
||||
user_questions.append(record)
|
||||
|
||||
#showing questions in which user answered
|
||||
obj_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id), ('parent_id', '!=', False)], context=context)
|
||||
user_answers = Post.browse(cr, uid, obj_ids, context=context)
|
||||
answers = [answer.parent_id for answer in user_answers]
|
||||
#showing questions which user following
|
||||
obj_ids = Followers.search(cr, SUPERUSER_ID, [('res_model', '=', 'website.forum.post'),('partner_id' , '=' , user.partner_id.id)], context=context)
|
||||
post_ids = [follower.res_id for follower in Followers.browse(cr, uid, obj_ids, context=context)]
|
||||
que_ids = Post.search(cr, uid, [('id', 'in', post_ids), ('forum_id', '=', forum.id), ('parent_id', '=', False)], context=context)
|
||||
followed = Post.browse(cr, uid, que_ids, context=context)
|
||||
|
||||
#votes which given on users questions and answers.
|
||||
total_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id)], count=True, context=context)
|
||||
up_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id), ('vote', '=', '1')], count=True, context=context)
|
||||
down_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
|
||||
data = Vote.read_group(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id)], ["vote"], groupby=["vote"], context=context)
|
||||
for rec in data:
|
||||
if rec['vote'] == '1':
|
||||
up_votes = rec['vote_count']
|
||||
elif rec['vote'] == '-1':
|
||||
down_votes = rec['vote_count']
|
||||
total_votes = up_votes + down_votes
|
||||
|
||||
#Votes which given by users on others questions and answers.
|
||||
post_votes = Vote.search(cr, uid, [('user_id', '=', user.id)], context=context)
|
||||
vote_ids = Vote.browse(cr, uid, post_votes, context=context)
|
||||
|
||||
#activity by user.
|
||||
user_post_ids = question_ids + obj_ids
|
||||
model, comment = Data.get_object_reference(cr, uid, 'mail', 'mt_comment')
|
||||
activity_ids = Activity.search(cr, uid, [('res_id', 'in', user_post_ids), ('model', '=', 'website.forum.post'), '|', ('subtype_id', '!=', comment), ('subtype_id', '=', False)], context=context)
|
||||
activities = Activity.browse(cr, uid, activity_ids, context=context)
|
||||
|
@ -248,6 +268,7 @@ class website_forum(http.Controller):
|
|||
'forum': forum,
|
||||
'questions': user_questions,
|
||||
'answers': user_answers,
|
||||
'followed': followed,
|
||||
'total_votes': total_votes,
|
||||
'up_votes': up_votes,
|
||||
'down_votes': down_votes,
|
||||
|
@ -591,3 +612,23 @@ class website_forum(http.Controller):
|
|||
tags = request.registry['website.forum.tag'].search_read(request.cr, request.uid, [], ['name'], context=request.context)
|
||||
data = [tag['name'] for tag in tags]
|
||||
return simplejson.dumps(data)
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/subscribe', type='http', auth="public", multilang=True, website=True)
|
||||
def subscribe(self, forum, post, **kwarg):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
if not request.session.uid:
|
||||
return login_redirect()
|
||||
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
||||
post_ids = [child.id for child in post.child_ids]
|
||||
post_ids.append(post.id)
|
||||
request.registry['website.forum.post'].message_subscribe( cr, uid, post_ids, [partner_id], context=context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/unsubscribe', type='http', auth="user", multilang=True, website=True)
|
||||
def unsubscribe(self, forum, post, **kwarg):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
||||
post_ids = [child.id for child in post.child_ids]
|
||||
post_ids.append(post.id)
|
||||
request.registry['website.forum.post'].message_unsubscribe( cr, uid, post_ids, [partner_id], context=context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
||||
|
|
|
@ -27,28 +27,28 @@
|
|||
<record id="mt_question_create" model="mail.message.subtype">
|
||||
<field name="name">Asked a question</field>
|
||||
<field name="res_model">website.forum.post</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="description">Asked a question</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_answer_create" model="mail.message.subtype">
|
||||
<field name="name">Answered a question</field>
|
||||
<field name="res_model">website.forum.post</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="description">Answered a question</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_question_edit" model="mail.message.subtype">
|
||||
<field name="name">Question edited</field>
|
||||
<field name="res_model">website.forum.post</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="description">Question edited</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_answer_edit" model="mail.message.subtype">
|
||||
<field name="name">Answer edited</field>
|
||||
<field name="res_model">website.forum.post</field>
|
||||
<field name="default" eval="False"/>
|
||||
<field name="default" eval="True"/>
|
||||
<field name="description">Answer edited</field>
|
||||
</record>
|
||||
|
||||
|
|
|
@ -126,6 +126,35 @@
|
|||
<div class="col-sm-3" id="right-column">
|
||||
<a class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a>
|
||||
<div t-field="forum.right_column"/>
|
||||
<div t-if="question_data">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading text-center">
|
||||
<h3 class="panel-title">Question tools</h3>
|
||||
</div>
|
||||
<div class="panel-body text-center">
|
||||
<a class="btn btn-block btn-default btn-md" t-if="not following"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/subscribe">Follow</a>
|
||||
<a class="btn btn-block btn-default btn-md" t-if="following"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/unsubscribe">UnFollow</a>
|
||||
<div class="mt8">
|
||||
<strong><t t-raw="len(question.message_follower_ids)"/></strong> follower
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-heading text-center">
|
||||
<h3 class="panel-title ">Stats</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table class="table">
|
||||
<thead><tr><td> Asked: <strong><span t-field="question.create_date" t-field-options='{"format":"short"}'/></strong></td></tr></thead>
|
||||
<tr><td> Seen: <strong><t t-raw="question.views"/></strong>
|
||||
<span t-if="question.views>1">times</span>
|
||||
<span t-if="question.views<=1">time</span>
|
||||
</td></tr>
|
||||
<tr><td> Last updated: <strong><span t-field="question.write_date" t-field-options='{"format":"short"}'/></strong></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -744,9 +773,11 @@
|
|||
<div class="tab-pane" id="badges">
|
||||
<t t-call="website_forum.user_badges"/>
|
||||
</div>
|
||||
<!--div class="tab-pane" id="followed_question">
|
||||
<h1>Followed Questions</h1>
|
||||
</div-->
|
||||
<div class="tab-pane" id="followed_question">
|
||||
<div t-foreach="followed" t-as="question">
|
||||
<t t-call="website_forum.post_list"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" id="votes">
|
||||
<t t-call="website_forum.user_votes"/>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue