[IMP] remove one2many fields from user object for question,answer,vote,activity and improved other code.
bzr revid: tpa@tinyerp.com-20140307110329-dsa3j5f4pm7v5kag
This commit is contained in:
parent
f5b14f1122
commit
b6f540d5dd
|
@ -52,50 +52,43 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/view'], type='http', auth="public", website=True, multilang=True)
|
||||
def view_forum(self, forum, **searches):
|
||||
values = {
|
||||
'forum': forum,
|
||||
}
|
||||
return request.website.render("website_forum.forum", values)
|
||||
return request.website.render("website_forum.forum", {'forum': forum })
|
||||
|
||||
@http.route('/forum/add_forum/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def add_forum(self, forum_name="New Forum", **kwargs):
|
||||
vals = {
|
||||
forum_id = request.registry['website.forum'].create(request.cr, request.uid, {
|
||||
'name': forum_name,
|
||||
'faq': 'F.A.Q'
|
||||
}
|
||||
forum_id = request.registry['website.forum'].create(request.cr, request.uid, vals, context=request.context)
|
||||
}, context=request.context)
|
||||
return request.redirect("/forum/%s/view/?enable_editor=1" % forum_id)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/', '/forum/<model("website.forum"):forum>/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def questions(self, forum, page=1, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
forum_obj = request.registry['website.forum.post']
|
||||
user_obj = request.registry['res.users']
|
||||
Forum = request.registry['website.forum.post']
|
||||
domain = [('forum_id', '=', forum.id), ('parent_id', '=', False)]
|
||||
search = searches.get('search',False)
|
||||
type = searches.get('type',False)
|
||||
|
||||
if not type:
|
||||
searches['type'] = 'all'
|
||||
search = searches.get('search',False)
|
||||
if search:
|
||||
domain += ['|',
|
||||
('name', 'ilike', search),
|
||||
('content', 'ilike', search)]
|
||||
|
||||
type = searches.get('type',False)
|
||||
if not type:
|
||||
searches['type'] = 'all'
|
||||
if type == 'unanswered':
|
||||
domain += [ ('child_ids', '=', False) ]
|
||||
#TODO: update domain to show followed questions of user
|
||||
if type == 'followed':
|
||||
user = user_obj.browse(cr, uid, uid, context=context)
|
||||
domain += [ ('id', 'in', [que.id for que in user.question_ids]) ]
|
||||
domain += [ ('create_uid', '=', uid) ]
|
||||
|
||||
step = 10
|
||||
question_count = forum_obj.search(cr, uid, domain, count=True, context=context)
|
||||
pager = request.website.pager(url="/forum/%s/" % slug(forum), total=question_count, page=page, step=step, scope=10)
|
||||
question_count = Forum.search(cr, uid, domain, count=True, context=context)
|
||||
pager = request.website.pager(url="/forum/%s/" % slug(forum), total=question_count, page=page, step=10, scope=10)
|
||||
|
||||
obj_ids = forum_obj.search(cr, uid, domain, limit=step, offset=pager['offset'], context=context)
|
||||
question_ids = forum_obj.browse(cr, uid, obj_ids, context=context)
|
||||
obj_ids = Forum.search(cr, uid, domain, limit=step, offset=pager['offset'], context=context)
|
||||
question_ids = Forum.browse(cr, uid, obj_ids, context=context)
|
||||
|
||||
#If dose not get any related question then redirect to ask question form.
|
||||
values = {
|
||||
'total_questions': question_count,
|
||||
'question_ids': question_ids,
|
||||
|
@ -113,17 +106,13 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/ask'], type='http', auth="public", website=True, multilang=True)
|
||||
def question_ask(self, forum, **post):
|
||||
values = {
|
||||
'searches': {},
|
||||
'forum': forum
|
||||
}
|
||||
values = { 'searches': {}, 'forum': forum }
|
||||
return request.website.render("website_forum.ask_question", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>/page/<page:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def question(self, forum, question, page, **post):
|
||||
values = {
|
||||
'question': question,
|
||||
'main_object': question,
|
||||
'forum': forum
|
||||
}
|
||||
return request.website.render(page, values)
|
||||
|
@ -136,7 +125,6 @@ class website_forum(http.Controller):
|
|||
answer_done = True
|
||||
values = {
|
||||
'question': question,
|
||||
'main_object': question,
|
||||
'searches': post,
|
||||
'answer_done': answer_done,
|
||||
'forum': forum,
|
||||
|
@ -167,15 +155,38 @@ class website_forum(http.Controller):
|
|||
|
||||
@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 = {}
|
||||
for answer in user.answer_ids:
|
||||
answers[answer.parent_id] = True
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
User = request.registry['res.users']
|
||||
Post = request.registry['website.forum.post']
|
||||
Vote = request.registry['website.forum.post.vote']
|
||||
Activity = request.registry['website.forum.activity']
|
||||
|
||||
question_ids = Post.search(cr, uid, [('create_uid', '=', user.id), ('parent_id', '=', False)], context=context)
|
||||
questions = Post.browse(cr, uid, question_ids, context=context)
|
||||
|
||||
#TODO: showing questions in which user answered
|
||||
obj_ids = Post.search(cr, uid, [('create_uid', '=', user.id), ('parent_id', '!=', False)], context=context)
|
||||
answer_ids = Post.browse(cr, uid, obj_ids, context=context)
|
||||
answers = [answer.parent_id for answer in answer_ids]
|
||||
|
||||
total_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id)], count=True, context=context)
|
||||
up_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id), ('vote', '=', '1')], count=True, context=context)
|
||||
down_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
|
||||
|
||||
activity_ids = Activity.search(cr, uid, [('user_id', '=', user.id)], context=context)
|
||||
activities = Activity.browse(cr, uid, activity_ids, context=context)
|
||||
|
||||
values = {
|
||||
'user': user,
|
||||
'main_object': user,
|
||||
'searches': post,
|
||||
'forum': forum,
|
||||
'answers': answers.keys()
|
||||
'questions': questions,
|
||||
'answers': answers,
|
||||
'total_votes': total_votes,
|
||||
'up_votes': up_votes,
|
||||
'down_votes': down_votes,
|
||||
'activities': activities
|
||||
}
|
||||
return request.website.render("website_forum.user_detail_full", values)
|
||||
|
||||
|
@ -196,7 +207,6 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route('/forum/<model("website.forum"):forum>/question/postanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def post_answer(self, forum ,post_id, **question):
|
||||
# TODO: set forum on user to True
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
||||
|
||||
|
@ -215,7 +225,6 @@ class website_forum(http.Controller):
|
|||
def edit_answer(self, forum, post, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
||||
post = request.registry['website.forum.post'].browse(cr, uid, post.id, context=context)
|
||||
for answer in post.child_ids:
|
||||
if answer.create_uid.id == request.uid:
|
||||
post_answer = answer
|
||||
|
@ -239,9 +248,7 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/tag/<model("website.forum.tag"):tag>'], type='http', auth="public", website=True, multilang=True)
|
||||
def tag_questions(self, forum, tag, page=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
step = 10
|
||||
pager = request.website.pager(url="/forum/%s/tag" % slug(forum), total=len(tag.post_ids), page=page, step=step, scope=10)
|
||||
pager = request.website.pager(url="/forum/%s/tag" % slug(forum), total=len(tag.post_ids), page=page, step=10, scope=10)
|
||||
|
||||
values = {
|
||||
'question_ids': tag.post_ids,
|
||||
|
@ -249,15 +256,14 @@ class website_forum(http.Controller):
|
|||
'forum': forum,
|
||||
'searches': kwargs
|
||||
}
|
||||
|
||||
return request.website.render("website_forum.index", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/tags'], type='http', auth="public", website=True, multilang=True)
|
||||
def tags(self, forum, page=1, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
tag_obj = request.registry['website.forum.tag']
|
||||
obj_ids = tag_obj.search(cr, uid, [], limit=None, context=context)
|
||||
tags = tag_obj.browse(cr, uid, obj_ids, context=context)
|
||||
Tag = request.registry['website.forum.tag']
|
||||
obj_ids = Tag.search(cr, uid, [], limit=None, context=context)
|
||||
tags = Tag.browse(cr, uid, obj_ids, context=context)
|
||||
values = {
|
||||
'tags': tags,
|
||||
'forum': forum,
|
||||
|
@ -279,34 +285,28 @@ class website_forum(http.Controller):
|
|||
return request.website.render("website_forum.badge", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/badge/<model("gamification.badge"):badge>'], type='http', auth="public", website=True, multilang=True)
|
||||
def badge_users(self, forum, badge, page=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
step = 10
|
||||
pager = request.website.pager(url="/forum/%s/badge" % slug(forum), total=len(badge.owner_ids), page=page, step=step, scope=10)
|
||||
|
||||
def badge_users(self, forum, badge, **kwargs):
|
||||
users = [badge_user.user_id for badge_user in badge.owner_ids]
|
||||
print users
|
||||
|
||||
values = {
|
||||
'badge': badge,
|
||||
'users': users,
|
||||
'pager': pager,
|
||||
'forum': forum,
|
||||
'searches': kwargs
|
||||
}
|
||||
|
||||
return request.website.render("website_forum.badge_user", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/users', '/forum/users/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def users(self, forum, page=1, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
user_obj = request.registry['res.users']
|
||||
User = request.registry['res.users']
|
||||
|
||||
step = 30
|
||||
tag_count = user_obj.search(cr, uid, [('forum','=',True)], count=True, context=context)
|
||||
tag_count = User.search(cr, uid, [('forum','=',True)], count=True, context=context)
|
||||
pager = request.website.pager(url="/forum/users/", total=tag_count, page=page, step=step, scope=30)
|
||||
|
||||
obj_ids = user_obj.search(cr, uid, [('forum','=',True)], limit=step, offset=pager['offset'], context=context)
|
||||
users = user_obj.browse(cr, uid, obj_ids, context=context)
|
||||
obj_ids = User.search(cr, uid, [('forum','=',True)], limit=step, offset=pager['offset'], context=context)
|
||||
users = User.browse(cr, uid, obj_ids, context=context)
|
||||
searches['users'] = 'True'
|
||||
|
||||
values = {
|
||||
|
|
|
@ -42,7 +42,8 @@ class Post(osv.Model):
|
|||
_name = 'website.forum.post'
|
||||
_description = "Question"
|
||||
_inherit = ['mail.thread', 'website.seo.metadata']
|
||||
|
||||
_order = "id desc"
|
||||
|
||||
def _get_votes(self, cr, uid, ids, field_name, arg, context):
|
||||
res = dict.fromkeys(ids, False)
|
||||
for post in self.browse(cr, uid, ids, context=context):
|
||||
|
@ -187,12 +188,6 @@ class Users(osv.Model):
|
|||
}
|
||||
return result
|
||||
_columns = {
|
||||
# TODO: Remove these 3 field and compute number in /user controller
|
||||
'question_ids':fields.one2many('website.forum.post', 'create_uid', 'Questions', domain=[('parent_id', '=', False)]),
|
||||
'answer_ids':fields.one2many('website.forum.post', 'create_uid', 'Answers', domain=[('parent_id', '!=', False)]),
|
||||
'vote_ids': fields.one2many('website.forum.post.vote', 'user_id', 'Votes'),
|
||||
'activity_ids': fields.one2many('website.forum.activity', 'user_id', 'Activity'),
|
||||
|
||||
# Field to remove
|
||||
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
||||
|
||||
|
|
|
@ -561,26 +561,26 @@
|
|||
</div>
|
||||
</div>
|
||||
<h2>
|
||||
<t t-esc="len(user.vote_ids)" />
|
||||
<t t-esc="total_votes"/>
|
||||
<span>Votes</span>
|
||||
</h2>
|
||||
<h3>
|
||||
<span class="glyphicon glyphicon-thumbs-up"></span>
|
||||
<b> 15 </b>
|
||||
<b> <t t-esc="up_votes" /> </b>
|
||||
</h3>
|
||||
<h3>
|
||||
<span class="glyphicon glyphicon-thumbs-down"></span>
|
||||
<b> 0 </b>
|
||||
<b> <t t-esc="down_votes" /> </b>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active">
|
||||
<a href="#questions" data-toggle="tab"><t t-esc="len(user.question_ids)"/> Questions</a>
|
||||
<a href="#questions" data-toggle="tab"><t t-esc="len(questions)"/> Questions</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#answers" data-toggle="tab"><t t-esc="len(user.answer_ids)"/> Answers</a>
|
||||
<a href="#answers" data-toggle="tab"><t t-esc="len(answers)"/> Answers</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#activity" data-toggle="tab">Activity</a>
|
||||
|
@ -594,7 +594,7 @@
|
|||
</ul>
|
||||
<div class="tab-content mt16">
|
||||
<div class="tab-pane active" id="questions">
|
||||
<div t-foreach="user.question_ids" t-as="question">
|
||||
<div t-foreach="questions" t-as="question">
|
||||
<t t-call="website_forum.post_list" />
|
||||
</div>
|
||||
</div><div class="tab-pane" id="answers">
|
||||
|
@ -620,7 +620,7 @@
|
|||
|
||||
<template id="user_activity">
|
||||
<ul class="media-list">
|
||||
<li t-foreach="user.activity_ids" t-as="activity" class="media">
|
||||
<li t-foreach="activities" 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"
|
||||
|
|
Loading…
Reference in New Issue