[IMP] remove activity object and use mail.message
bzr revid: tpa@tinyerp.com-20140311125949-50uxmckmcal11hdf
This commit is contained in:
parent
777a5a3c8f
commit
41876d0379
|
@ -146,22 +146,26 @@ class website_forum(http.Controller):
|
|||
User = request.registry['res.users']
|
||||
Post = request.registry['website.forum.post']
|
||||
Vote = request.registry['website.forum.post.vote']
|
||||
Activity = request.registry['website.forum.activity']
|
||||
Activity = request.registry['mail.message']
|
||||
|
||||
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('create_uid', '=', user.id), ('parent_id', '=', False)], context=context)
|
||||
questions = Post.browse(cr, uid, question_ids, context=context)
|
||||
user_questions = Post.browse(cr, uid, question_ids, context=context)
|
||||
|
||||
#TODO: showing questions in which user answered
|
||||
#showing questions in which user answered
|
||||
obj_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('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]
|
||||
user_answers = Post.browse(cr, uid, obj_ids, context=context)
|
||||
answers = [answer.parent_id for answer in user_answers]
|
||||
|
||||
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)
|
||||
down_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
|
||||
|
||||
activity_ids = Activity.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('user_id', '=', user.id)], context=context)
|
||||
user_post_ids = user_questions + obj_ids
|
||||
activity_ids = Activity.search(cr, uid, [('res_id', 'in', user_post_ids), ('model', '=', 'website.forum.post')], context=context)
|
||||
activities = Activity.browse(cr, uid, activity_ids, context=context)
|
||||
posts = {}
|
||||
for rec in user_answers + user_questions:
|
||||
posts[rec.id] = rec
|
||||
post['users'] = 'True'
|
||||
|
||||
values = {
|
||||
|
@ -169,12 +173,13 @@ class website_forum(http.Controller):
|
|||
'main_object': user,
|
||||
'searches': post,
|
||||
'forum': forum,
|
||||
'questions': questions,
|
||||
'questions': user_questions,
|
||||
'answers': answers,
|
||||
'total_votes': total_votes,
|
||||
'up_votes': up_votes,
|
||||
'down_votes': down_votes,
|
||||
'activities': activities
|
||||
'activities': activities,
|
||||
'posts': posts
|
||||
}
|
||||
return request.website.render("website_forum.user_detail_full", values)
|
||||
|
||||
|
|
|
@ -164,53 +164,27 @@ class Post(osv.Model):
|
|||
|
||||
History.create(cr, uid, res, context=context)
|
||||
|
||||
def create_activity(self, cr, uid, ids, method, context=None):
|
||||
Activity = self.pool['website.forum.activity']
|
||||
for post in self.browse(cr, uid, ids, context=context):
|
||||
res = {
|
||||
'name': post.name,
|
||||
'post_id': post.id,
|
||||
'user_id': uid,
|
||||
}
|
||||
|
||||
if post.parent_id:
|
||||
res.update({'type': 'edited_answer'})
|
||||
if method == 'create':
|
||||
res.update({'type': 'answered_question'})
|
||||
if method == 'unlink':
|
||||
res.update({'type': 'deleted_answer'})
|
||||
if method == 'vote':
|
||||
res.update({'type': 'voted_answer'})
|
||||
|
||||
else:
|
||||
res.update({'type': 'edited_question'})
|
||||
if method == 'create':
|
||||
res.update({'type': 'asked_question'})
|
||||
if method == 'unlink':
|
||||
res.update({'type': 'deleted_question'})
|
||||
if method == 'vote':
|
||||
res.update({'type': 'voted_question'})
|
||||
|
||||
Activity.create(cr, uid, res, context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
create_context = dict(context, mail_create_nolog=True)
|
||||
post_id = super(Post, self).create(cr, uid, vals, context=create_context)
|
||||
self.create_activity(cr, uid, [post_id], method='create', context=context)
|
||||
body = "asked a question"
|
||||
if vals.get("parent_id"):
|
||||
body = "answered a question"
|
||||
self.message_post(cr, uid, [post_id], body=body, context=context)
|
||||
return post_id
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
self.create_history(cr, uid, ids, vals, context=context)
|
||||
result = super(Post, self).write(cr, uid, ids, vals, context=context)
|
||||
self.create_activity(cr, uid, ids, method='write', context=context)
|
||||
for post in self.browse(cr, uid, ids, context=context):
|
||||
body = "edited question"
|
||||
if post.parent_id:
|
||||
body = "edited answer"
|
||||
self.message_post(cr, uid, ids, body=body, context=context)
|
||||
return result
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
self.create_activity(cr, uid, ids, method='unlink', context=context)
|
||||
return super(Post, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
class Users(osv.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
|
@ -225,6 +199,7 @@ class Users(osv.Model):
|
|||
'bronze_badge': badge_user_obj.search(cr, uid, [('badge_id.level', '=', 'bronze'), ('user_id', '=', id)], context=context, count=True),
|
||||
}
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'create_date': fields.datetime('Create Date', select=True, readonly=True),
|
||||
'karma': fields.integer('Karma'), # Use Gamification for this
|
||||
|
@ -265,7 +240,12 @@ class Vote(osv.Model):
|
|||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
vote_id = super(Vote, self).create(cr, uid, vals, context=context)
|
||||
self.pool['website.forum.post'].create_activity(cr, uid, [int(vals.get('post_id'))], method='vote', context=context)
|
||||
Post = self.pool["website.forum.post"]
|
||||
record = Post.browse(cr, uid, vals.get('post_id'), context=context)
|
||||
body = "voted question"
|
||||
if record.parent_id:
|
||||
body = "voted answer"
|
||||
Post.message_post(cr, uid, [record.id], body=body, context=context)
|
||||
return vote_id
|
||||
|
||||
class Badge(osv.Model):
|
||||
|
@ -279,34 +259,6 @@ class Badge(osv.Model):
|
|||
'level': 'bronze'
|
||||
}
|
||||
|
||||
|
||||
# TODO:
|
||||
# remove this object and replace by mail.message of type notes on related post
|
||||
# type = message types
|
||||
class ForumActivity(osv.Model):
|
||||
_name = "website.forum.activity"
|
||||
_description = "Activity"
|
||||
_order = "id desc"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64),
|
||||
'post_id': fields.many2one('website.forum.post', 'Post'),
|
||||
'user_id': fields.many2one('res.users', 'User'),
|
||||
'create_date': fields.datetime('Created on', select=True, readonly=True),
|
||||
# Use the gamification module instead!
|
||||
'badge_id': fields.many2one('res.groups', 'Badge'),
|
||||
#NOTE: we can create new ForumActivityType object instead of selection
|
||||
'type': fields.selection([('asked_question', 'asked a question'), ('answered_question', 'answered a question'),
|
||||
('edited_question', 'edited question'), ('edited_answer', 'edited answer'),
|
||||
('commented_question', 'commented question'), ('commented_answer', 'commented answer'),
|
||||
('deleted_question', 'deleted question'), ('deleted_answer', 'deleted answer'),
|
||||
('voted_question', 'voted question'), ('voted_answer', 'voted answer'),
|
||||
('received_badge', 'received badge'),
|
||||
], 'Activity Type'),
|
||||
# merge these 2 fields into one: karma: fields.integer (that can be positive or negative)
|
||||
'karma_add': fields.integer('Added Karma'),
|
||||
'karma_sub': fields.integer('Karma Removed')
|
||||
}
|
||||
|
||||
class Tags(osv.Model):
|
||||
_name = "website.forum.tag"
|
||||
_description = "Tag"
|
||||
|
|
|
@ -4,5 +4,4 @@ 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
|
||||
access_website_forum_activity,website.forum.activity,model_website_forum_activity,base.group_public,1,0,0,0
|
||||
access_website_forum_tag,website.forum.tag,model_website_forum_tag,base.group_public,1,0,0,0
|
||||
|
|
|
|
@ -605,15 +605,16 @@
|
|||
<template id="user_activity">
|
||||
<ul class="media-list">
|
||||
<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"
|
||||
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"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ activity.post_id.parent_id.id }"/>
|
||||
<t t-set="post" t-value="posts.get(activity.res_id)"/>
|
||||
<small t-esc="activity.date" class="pull-left"/>
|
||||
<span t-field="activity.body" class="label label-info pull-left"/>
|
||||
<a t-esc="post.name" t-if="not post.parent_id"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ activity.res_id }"/>
|
||||
<t t-if="post.parent_id">
|
||||
<a t-esc="post.parent_id.name"
|
||||
t-attf-href="/forum/#{ slug(forum) }/question/#{ post.parent_id.id }"/>
|
||||
<span class="glyphicon glyphicon-play"/>
|
||||
<t t-esc="activity.post_id.content[0:100]"/>
|
||||
<t t-esc="post.content[0:100]"/>
|
||||
<strong> ... </strong>
|
||||
</t>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue