Turkesh Patel (Open ERP) 2014-03-18 17:36:59 +05:30
commit 603cc77da7
2 changed files with 43 additions and 14 deletions

View File

@ -162,6 +162,7 @@ class website_forum(http.Controller):
Activity = request.registry['mail.message'] Activity = request.registry['mail.message']
Data = request.registry["ir.model.data"] Data = request.registry["ir.model.data"]
#questions asked by user.
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('create_uid', '=', user.id), ('parent_id', '=', False)], context=context) question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('create_uid', '=', user.id), ('parent_id', '=', False)], context=context)
user_questions = Post.browse(cr, uid, question_ids, context=context) user_questions = Post.browse(cr, uid, question_ids, context=context)
@ -170,16 +171,21 @@ class website_forum(http.Controller):
user_answers = Post.browse(cr, uid, obj_ids, context=context) user_answers = Post.browse(cr, uid, obj_ids, context=context)
answers = [answer.parent_id for answer in user_answers] answers = [answer.parent_id for answer in user_answers]
#votes which given on users questions and answers.
total_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id)], count=True, context=context) total_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id)], count=True, context=context)
up_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '1')], count=True, context=context) up_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '1')], count=True, context=context)
down_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context) down_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
#Votes which given by users on others questions and answers.
post_votes = Vote.search(cr, uid, [('user_id', '=', uid)], context=context)
vote_ids = Vote.browse(cr, uid, post_votes, context=context)
#activity by user.
user_post_ids = question_ids + obj_ids user_post_ids = question_ids + obj_ids
model, comment = Data.get_object_reference(cr, uid, 'mail', 'mt_comment') 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) 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) activities = Activity.browse(cr, uid, activity_ids, context=context)
posts = {} posts = {}
for act in activities: for act in activities:
posts[act.res_id] = True posts[act.res_id] = True
@ -200,7 +206,8 @@ class website_forum(http.Controller):
'up_votes': up_votes, 'up_votes': up_votes,
'down_votes': down_votes, 'down_votes': down_votes,
'activities': activities, 'activities': activities,
'posts': posts 'posts': posts,
'vote_post':vote_ids,
} }
return request.website.render("website_forum.user_detail_full", values) return request.website.render("website_forum.user_detail_full", values)

View File

@ -66,7 +66,7 @@
<template id="header" name="Forum Index"> <template id="header" name="Forum Index">
<t t-call="website.layout"> <t t-call="website.layout">
<t t-set="head"> <t t-set="head">
<link rel='stylesheet' href='/website_forum/static/src/css/website_forum.css' /> <link rel='stylesheet' href='/website_forum/static/src/css/website_forum.css'/>
</t> </t>
<div class="container mt16"> <div class="container mt16">
<div class="navbar navbar-default"> <div class="navbar navbar-default">
@ -100,7 +100,7 @@
<div class="form-group"> <div class="form-group">
<input type="search" class="form-control" <input type="search" class="form-control"
name="search" placeholder="Search a question..." name="search" placeholder="Search a question..."
t-att-value="searches.get('search') or ''" /> t-att-value="searches.get('search') or ''"/>
<button type="submit" class="btn btn-default">Search</button> <button type="submit" class="btn btn-default">Search</button>
</div> </div>
</form> </form>
@ -189,9 +189,9 @@
</small> </small>
</h1> </h1>
<div t-foreach="question_ids" t-as="question" class="mb16"> <div t-foreach="question_ids" t-as="question" class="mb16">
<t t-call="website_forum.post_list" /> <t t-call="website_forum.post_list"/>
</div> </div>
<t t-call="website.pager" /> <t t-call="website.pager"/>
</t> </t>
</template> </template>
@ -380,7 +380,7 @@
</div> </div>
</div> </div>
<div style="margin-left: 95px;" class="clearfix"> <div style="margin-left: 95px;" class="clearfix">
<t t-raw="answer.content" /> <t t-raw="answer.content"/>
<div class="mt16"> <div class="mt16">
<ul class="list-inline pull-right"> <ul class="list-inline pull-right">
<li> <li>
@ -450,7 +450,7 @@
<div class="row"> <div class="row">
<div class="col-sm-3 mt16" t-foreach="tags" t-as="tag"> <div class="col-sm-3 mt16" t-foreach="tags" t-as="tag">
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }" class="badge"> <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }" class="badge">
<span t-field="tag.name" /> <span t-field="tag.name"/>
</a> </a>
<span> <span>
X <t t-esc="tag.posts_count"/> X <t t-esc="tag.posts_count"/>
@ -477,7 +477,7 @@
<span t-if="badge.level == 'gold'" class="fa fa-circle badge-gold"/> <span t-if="badge.level == 'gold'" class="fa fa-circle badge-gold"/>
<span t-if="badge.level == 'silver'" class="fa fa-circle badge-silver"/> <span t-if="badge.level == 'silver'" class="fa fa-circle badge-silver"/>
<span t-if="badge.level == 'bronze'" class="fa fa-circle badge-bronze"/> <span t-if="badge.level == 'bronze'" class="fa fa-circle badge-bronze"/>
<span t-field="badge.name" /> <span t-field="badge.name"/>
</a> </a>
</td><td> </td><td>
<b t-esc="badge.stat_count_distinct"/> <b t-esc="badge.stat_count_distinct"/>
@ -531,7 +531,7 @@
</div> </div>
</div> </div>
<div class="pull-left"> <div class="pull-left">
<t t-call="website.pager" /> <t t-call="website.pager"/>
</div> </div>
</t> </t>
</template> </template>
@ -656,26 +656,32 @@
<li> <li>
<a href="#followed_question" data-toggle="tab">Followed Question</a> <a href="#followed_question" data-toggle="tab">Followed Question</a>
</li> </li>
<li>
<a href="#votes" data-toggle="tab">Votes</a>
</li>
</ul> </ul>
<div class="tab-content mt16"> <div class="tab-content mt16">
<div class="tab-pane active" id="questions"> <div class="tab-pane active" id="questions">
<div t-foreach="questions" t-as="question"> <div t-foreach="questions" t-as="question">
<t t-call="website_forum.post_list" /> <t t-call="website_forum.post_list"/>
</div> </div>
</div><div class="tab-pane" id="answers"> </div><div class="tab-pane" id="answers">
<div t-foreach="answers" t-as="question"> <div t-foreach="answers" t-as="question">
<t t-call="website_forum.post_list" /> <t t-call="website_forum.post_list"/>
</div> </div>
</div> </div>
<div class="tab-pane" id="karma"> <div class="tab-pane" id="karma">
<h1>Karma</h1> <h1>Karma</h1>
</div> </div>
<div class="tab-pane" id="badges"> <div class="tab-pane" id="badges">
<t t-call="website_forum.user_badges" /> <t t-call="website_forum.user_badges"/>
</div> </div>
<div class="tab-pane" id="followed_question"> <div class="tab-pane" id="followed_question">
<h1>Followed Questions</h1> <h1>Followed Questions</h1>
</div> </div>
<div class="tab-pane" id="votes">
<t t-call="website_forum.user_votes"/>
</div>
<div class="tab-pane" id="activity"> <div class="tab-pane" id="activity">
<ul class="list-unstyled"> <ul class="list-unstyled">
<li t-foreach="activities" t-as="activity"> <li t-foreach="activities" t-as="activity">
@ -701,7 +707,7 @@
<div class="row mb16"> <div class="row mb16">
<div class="col-sm-3 mt16" t-foreach="user.badges" t-as="badge"> <div class="col-sm-3 mt16" t-foreach="user.badges" t-as="badge">
<a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge.badge_id) }" class="badge"> <a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge.badge_id) }" class="badge">
<span t-field="badge.badge_id.name" /> <span t-field="badge.badge_id.name"/>
</a> </a>
<span> <span>
X <t t-esc="badge.badge_id.stat_count_distinct"/> X <t t-esc="badge.badge_id.stat_count_distinct"/>
@ -714,5 +720,21 @@
</div> </div>
</template> </template>
<template id="user_votes">
<div t-foreach="vote_post" t-as="vote">
<t t-esc="vote.post_id.create_date"/>
<span t-if="vote.vote == '1'" class="fa fa-thumbs-up text-success" style="margin-left:30px"/>
<span t-if="vote.vote == '-1'" class="fa fa-thumbs-down text-warning" style="margin-left:30px"/>
<t t-if="vote.post_id.parent_id">
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.parent_id.id }/#answer-#{ vote.post_id.id }" t-esc="vote.post_id.parent_id.name" style="margin-left:10px"/>
</t>
<t t-if="not vote.post_id.parent_id">
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.id }" style=" color:black;margin-left:10px" t-esc="vote.post_id.name"/>
</t>
</div>
<div class="mb16" t-if="not vote_post">
<b>No vote given by you yet!</b>
</div>
</template>
</data> </data>
</openerp> </openerp>