2014-02-21 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-03-09 18:41:19 +00:00
|
|
|
import openerp
|
2014-04-09 16:50:59 +00:00
|
|
|
|
2014-02-22 17:19:37 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2014-04-10 10:16:58 +00:00
|
|
|
from openerp.addons.website.models.website import slug
|
2014-02-22 17:19:37 +00:00
|
|
|
from openerp.osv import osv, fields
|
2014-02-21 13:16:08 +00:00
|
|
|
from openerp.tools.translate import _
|
|
|
|
|
|
|
|
|
2014-02-22 17:19:37 +00:00
|
|
|
class Forum(osv.Model):
|
2014-04-18 13:29:05 +00:00
|
|
|
"""TDE TODO: set karma values for actions dynamic for a given forum"""
|
2014-04-10 13:39:28 +00:00
|
|
|
_name = 'forum.forum'
|
2014-03-03 19:17:48 +00:00
|
|
|
_description = 'Forums'
|
2014-04-10 13:39:28 +00:00
|
|
|
_inherit = ['website.seo.metadata']
|
2014-04-18 13:29:05 +00:00
|
|
|
# karma values
|
|
|
|
_karma_upvote = 5 # done
|
|
|
|
_karma_downvote = 50 # done
|
|
|
|
_karma_answer_accept_own = 20 # done
|
|
|
|
_karma_answer_own_question_immediately = 50
|
|
|
|
_karma_editor_link_files = 30 # done
|
|
|
|
_karma_editor_clickable_link = 50
|
|
|
|
_karma_modo_retag = 75
|
|
|
|
_karma_modo_close_own = 100
|
|
|
|
_karma_modo_edit_all = 300
|
|
|
|
_karma_modo_unlink_comment = 400
|
|
|
|
_karma_modo_close_all = 900
|
|
|
|
_karma_modo_unlink_all = 1000
|
|
|
|
# karma generation
|
|
|
|
_karma_gen_quest_new = 2 # done
|
|
|
|
_karma_gen_upvote_quest = 5 # done
|
|
|
|
_karma_gen_downvote_quest = -2 # done
|
|
|
|
_karma_gen_upvote_ans = 10 # done
|
|
|
|
_karma_gen_downvote_ans = -2 # done
|
|
|
|
_karma_gen_ans_accept = 2 # done
|
|
|
|
_karma_gen_ans_accepted = 15 # done
|
|
|
|
_karma_gen_ans_flagged = -100
|
2014-03-28 09:03:57 +00:00
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
_columns = {
|
2014-03-03 19:17:48 +00:00
|
|
|
'name': fields.char('Name', required=True, translate=True),
|
2014-03-09 18:58:47 +00:00
|
|
|
'faq': fields.html('Guidelines'),
|
2014-04-10 13:39:28 +00:00
|
|
|
'description': fields.html('Description'),
|
2014-02-22 17:19:37 +00:00
|
|
|
}
|
2014-04-09 16:50:59 +00:00
|
|
|
|
|
|
|
def _get_default_faq(self, cr, uid, context=None):
|
2014-03-09 18:41:19 +00:00
|
|
|
fname = openerp.modules.get_module_resource('website_forum', 'data', 'forum_default_faq.html')
|
|
|
|
with open(fname, 'r') as f:
|
|
|
|
return f.read()
|
|
|
|
return False
|
|
|
|
|
|
|
|
_defaults = {
|
2014-04-09 16:50:59 +00:00
|
|
|
'description': 'This community is for professionals and enthusiasts of our products and services.',
|
2014-03-09 18:58:47 +00:00
|
|
|
'faq': _get_default_faq,
|
2014-03-09 18:41:19 +00:00
|
|
|
}
|
2014-02-22 06:27:15 +00:00
|
|
|
|
2014-04-10 10:16:58 +00:00
|
|
|
def create(self, cr, uid, values, context=None):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
create_context = dict(context, mail_create_nolog=True)
|
|
|
|
return super(Forum, self).create(cr, uid, values, context=create_context)
|
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class Post(osv.Model):
|
2014-04-10 13:39:28 +00:00
|
|
|
_name = 'forum.post'
|
|
|
|
_description = 'Forum Post'
|
2014-02-21 13:16:08 +00:00
|
|
|
_inherit = ['mail.thread', 'website.seo.metadata']
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-04-10 13:39:28 +00:00
|
|
|
def _get_user_vote(self, cr, uid, ids, field_name, arg, context):
|
|
|
|
res = dict.fromkeys(ids, 0)
|
|
|
|
vote_ids = self.pool['forum.post.vote'].search(cr, uid, [('post_id', 'in', ids), ('user_id', '=', uid)], context=context)
|
|
|
|
for vote in self.pool['forum.post.vote'].browse(cr, uid, vote_ids, context=context):
|
|
|
|
res[vote.post_id.id] = vote.vote
|
|
|
|
return res
|
|
|
|
|
2014-03-06 13:17:36 +00:00
|
|
|
def _get_vote_count(self, cr, uid, ids, field_name, arg, context):
|
2014-03-06 09:40:42 +00:00
|
|
|
res = dict.fromkeys(ids, 0)
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
2014-04-10 13:39:28 +00:00
|
|
|
for vote in post.vote_ids:
|
|
|
|
res[post.id] += int(vote.vote)
|
2014-03-06 09:40:42 +00:00
|
|
|
return res
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-04-10 13:39:28 +00:00
|
|
|
def _get_post_from_vote(self, cr, uid, ids, context=None):
|
2014-03-11 09:25:17 +00:00
|
|
|
result = {}
|
2014-04-10 13:39:28 +00:00
|
|
|
for vote in self.pool['forum.post.vote'].browse(cr, uid, ids, context=context):
|
2014-03-11 09:25:17 +00:00
|
|
|
result[vote.post_id.id] = True
|
|
|
|
return result.keys()
|
|
|
|
|
2014-04-10 13:39:28 +00:00
|
|
|
def _get_user_favourite(self, cr, uid, ids, field_name, arg, context):
|
|
|
|
res = dict.fromkeys(ids, False)
|
2014-03-12 09:16:02 +00:00
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
2014-04-11 13:29:39 +00:00
|
|
|
if uid in [f.id for f in post.favourite_ids]:
|
2014-04-10 13:39:28 +00:00
|
|
|
res[post.id] = True
|
2014-03-12 09:16:02 +00:00
|
|
|
return res
|
|
|
|
|
2014-04-10 13:39:28 +00:00
|
|
|
def _get_favorite_count(self, cr, uid, ids, field_name, arg, context):
|
2014-04-07 07:20:32 +00:00
|
|
|
res = dict.fromkeys(ids, 0)
|
2014-04-10 13:39:28 +00:00
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
2014-04-11 13:29:39 +00:00
|
|
|
res[post.id] += len(post.favourite_ids)
|
2014-04-07 07:20:32 +00:00
|
|
|
return res
|
|
|
|
|
2014-04-10 13:39:28 +00:00
|
|
|
def _get_post_from_hierarchy(self, cr, uid, ids, context=None):
|
|
|
|
post_ids = set(ids)
|
|
|
|
for post in self.browse(cr, SUPERUSER_ID, ids, context=context):
|
|
|
|
if post.parent_id:
|
|
|
|
post_ids.add(post.parent_id.id)
|
|
|
|
return list(post_ids)
|
|
|
|
|
|
|
|
def _get_child_count(self, cr, uid, ids, field_name=False, arg={}, context=None):
|
|
|
|
res = dict.fromkeys(ids, 0)
|
2014-04-07 07:20:32 +00:00
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
2014-04-10 13:39:28 +00:00
|
|
|
if post.parent_id:
|
|
|
|
res[post.parent_id.id] = len(post.parent_id.child_ids)
|
|
|
|
else:
|
|
|
|
res[post.id] = len(post.child_ids)
|
2014-04-07 07:20:32 +00:00
|
|
|
return res
|
|
|
|
|
2014-04-11 13:29:39 +00:00
|
|
|
def _get_uid_answered(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = dict.fromkeys(ids, False)
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
res[post.id] = any(answer.create_uid.id == uid for answer in post.child_ids)
|
|
|
|
return res
|
|
|
|
|
2014-04-18 13:29:05 +00:00
|
|
|
def _get_has_validated_answer(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = dict.fromkeys(ids, False)
|
|
|
|
ans_ids = self.search(cr, uid, [('parent_id', 'in', ids), ('is_correct', '=', True)], context=context)
|
|
|
|
for answer in self.browse(cr, uid, ans_ids, context=context):
|
|
|
|
res[answer.parent_id.id] = True
|
|
|
|
return res
|
|
|
|
|
2014-04-14 14:54:15 +00:00
|
|
|
def _is_self_reply(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = dict.fromkeys(ids, False)
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
res[post.id] = post.parent_id and post.parent_id.create_uid == post.create_uid or False
|
|
|
|
return res
|
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
_columns = {
|
2014-03-09 18:41:19 +00:00
|
|
|
'name': fields.char('Title', size=128),
|
2014-04-10 13:39:28 +00:00
|
|
|
'forum_id': fields.many2one('forum.forum', 'Forum', required=True),
|
|
|
|
'content': fields.html('Content'),
|
|
|
|
'tag_ids': fields.many2many('forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tags'),
|
2014-04-09 16:50:59 +00:00
|
|
|
'state': fields.selection([('active', 'Active'), ('close', 'Close'), ('offensive', 'Offensive')], 'Status'),
|
|
|
|
'views': fields.integer('Number of Views'),
|
2014-04-10 13:39:28 +00:00
|
|
|
'active': fields.boolean('Active'),
|
|
|
|
'is_correct': fields.boolean('Valid Answer', help='Correct Answer/ Answer on this question accepted.'),
|
2014-02-21 13:16:08 +00:00
|
|
|
'website_message_ids': fields.one2many(
|
|
|
|
'mail.message', 'res_id',
|
|
|
|
domain=lambda self: [
|
|
|
|
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
|
|
|
],
|
2014-04-10 13:39:28 +00:00
|
|
|
string='Post Messages', help="Comments on forum post",
|
2014-02-21 13:16:08 +00:00
|
|
|
),
|
2014-04-10 13:39:28 +00:00
|
|
|
# history
|
|
|
|
'create_date': fields.datetime('Asked on', select=True, readonly=True),
|
|
|
|
'create_uid': fields.many2one('res.users', 'Created by', select=True, readonly=True),
|
|
|
|
'write_date': fields.datetime('Update on', select=True, readonly=True),
|
|
|
|
'write_uid': fields.many2one('res.users', 'Updated by', select=True, readonly=True),
|
|
|
|
# vote fields
|
|
|
|
'vote_ids': fields.one2many('forum.post.vote', 'post_id', 'Votes'),
|
|
|
|
'user_vote': fields.function(_get_user_vote, string='My Vote', type='integer'),
|
2014-04-09 16:50:59 +00:00
|
|
|
'vote_count': fields.function(
|
|
|
|
_get_vote_count, string="Votes", type='integer',
|
2014-03-11 09:25:17 +00:00
|
|
|
store={
|
2014-04-10 13:39:28 +00:00
|
|
|
'forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
|
|
|
|
'forum.post.vote': (_get_post_from_vote, [], 10),
|
|
|
|
}),
|
|
|
|
# favorite fields
|
2014-04-11 13:29:39 +00:00
|
|
|
'favourite_ids': fields.many2many('res.users', string='Favourite'),
|
2014-04-10 13:39:28 +00:00
|
|
|
'user_favourite': fields.function(_get_user_favourite, string="My Favourite", type='boolean'),
|
2014-04-11 13:29:39 +00:00
|
|
|
'favourite_count': fields.function(
|
2014-04-10 13:39:28 +00:00
|
|
|
_get_favorite_count, string='Favorite Count', type='integer',
|
|
|
|
store={
|
2014-04-11 13:29:39 +00:00
|
|
|
'forum.post': (lambda self, cr, uid, ids, c={}: ids, ['favourite_ids'], 10),
|
2014-04-10 13:39:28 +00:00
|
|
|
}),
|
|
|
|
# hierarchy
|
|
|
|
'parent_id': fields.many2one('forum.post', 'Question', ondelete='cascade'),
|
2014-04-18 13:29:05 +00:00
|
|
|
'self_reply': fields.function(
|
|
|
|
_is_self_reply, 'Reply to own question', type='boolean',
|
2014-04-14 14:54:15 +00:00
|
|
|
store={
|
|
|
|
'forum.post': (lambda self, cr, uid, ids, c={}: ids, ['parent_id', 'create_uid'], 10),
|
|
|
|
}),
|
2014-04-10 13:39:28 +00:00
|
|
|
'child_ids': fields.one2many('forum.post', 'parent_id', 'Answers'),
|
|
|
|
'child_count': fields.function(
|
|
|
|
_get_child_count, string="Answers", type='integer',
|
|
|
|
store={
|
|
|
|
'forum.post': (_get_post_from_hierarchy, ['parent_id', 'child_ids'], 10),
|
|
|
|
}),
|
2014-04-11 13:29:39 +00:00
|
|
|
'uid_has_answered': fields.function(
|
|
|
|
_get_uid_answered, string='Has Answered', type='boolean',
|
|
|
|
),
|
2014-04-18 13:29:05 +00:00
|
|
|
'has_validated_answer': fields.function(
|
|
|
|
_get_has_validated_answer, string='Has a Validated Answered', type='boolean',
|
|
|
|
store={
|
|
|
|
'forum.post': (_get_post_from_hierarchy, ['parent_id', 'child_ids', 'is_correct'], 10),
|
|
|
|
}
|
|
|
|
),
|
2014-04-10 13:39:28 +00:00
|
|
|
# closing
|
|
|
|
'closed_reason_id': fields.many2one('forum.post.reason', 'Reason'),
|
|
|
|
'closed_uid': fields.many2one('res.users', 'Closed by', select=1),
|
2014-03-21 12:57:47 +00:00
|
|
|
'closed_date': fields.datetime('Closed on', readonly=True),
|
2014-02-21 13:16:08 +00:00
|
|
|
}
|
2014-04-09 16:50:59 +00:00
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
_defaults = {
|
|
|
|
'state': 'active',
|
2014-04-09 17:25:22 +00:00
|
|
|
'views': 0,
|
2014-03-12 09:16:02 +00:00
|
|
|
'active': True,
|
2014-04-11 15:37:24 +00:00
|
|
|
'vote_ids': list(),
|
|
|
|
'favourite_ids': list(),
|
|
|
|
'child_ids': list(),
|
2014-02-21 13:16:08 +00:00
|
|
|
}
|
2014-03-05 13:07:24 +00:00
|
|
|
|
2014-02-23 07:15:16 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
create_context = dict(context, mail_create_nolog=True)
|
2014-04-09 16:50:59 +00:00
|
|
|
post_id = super(Post, self).create(cr, uid, vals, context=create_context)
|
|
|
|
# post message + subtype depending on parent_id
|
2014-03-11 12:59:49 +00:00
|
|
|
if vals.get("parent_id"):
|
2014-04-10 10:16:58 +00:00
|
|
|
parent = self.browse(cr, SUPERUSER_ID, vals['parent_id'], context=context)
|
|
|
|
body = _('<p><a href="forum/%s/question/%s">New Answer Posted</a></p>' % (slug(parent.forum_id), slug(parent)))
|
2014-04-11 18:06:15 +00:00
|
|
|
self.message_post(cr, uid, parent.id, subject=_('Re: %s') % parent.name, body=body, subtype='website_forum.mt_answer_new', context=context)
|
2014-04-09 16:50:59 +00:00
|
|
|
else:
|
2014-04-15 13:19:29 +00:00
|
|
|
self.message_post(cr, uid, post_id, subject=vals.get('name', ''), body=_('New Question Created'), subtype='website_forum.mt_question_new', context=context)
|
2014-04-18 13:29:05 +00:00
|
|
|
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [uid], self.pool['forum.forum']._karma_gen_quest_new, context=context)
|
2014-02-23 07:15:16 +00:00
|
|
|
return post_id
|
|
|
|
|
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
2014-04-18 13:29:05 +00:00
|
|
|
Forum = self.pool['forum.forum']
|
|
|
|
# update karma when accepting/rejecting answers
|
|
|
|
if 'is_correct' in vals:
|
|
|
|
mult = 1 if vals['is_correct'] else -1
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
if vals['is_correct'] != post.is_correct:
|
|
|
|
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id], Forum._karma_gen_ans_accepted * mult, context=context)
|
|
|
|
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [uid], Forum._karma_gen_ans_accept * mult, context=context)
|
2014-04-09 16:50:59 +00:00
|
|
|
res = super(Post, self).write(cr, uid, ids, vals, context=context)
|
|
|
|
# if post content modify, notify followers
|
|
|
|
if 'content' in vals or 'name' in vals:
|
2014-03-13 08:41:30 +00:00
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
if post.parent_id:
|
2014-04-11 18:06:15 +00:00
|
|
|
body, subtype = _('Answer Edited'), 'website_forum.mt_answer_edit'
|
|
|
|
obj_id = post.parent_id.id
|
2014-04-09 16:50:59 +00:00
|
|
|
else:
|
2014-04-11 18:06:15 +00:00
|
|
|
body, subtype = _('Question Edited'), 'website_forum.mt_question_edit'
|
|
|
|
obj_id = post.id
|
|
|
|
self.message_post(cr, uid, obj_id, body=_(body), subtype=subtype, context=context)
|
2014-04-09 16:50:59 +00:00
|
|
|
return res
|
|
|
|
|
2014-04-09 17:39:41 +00:00
|
|
|
def vote(self, cr, uid, ids, upvote=True, context=None):
|
2014-04-10 13:39:28 +00:00
|
|
|
Vote = self.pool['forum.post.vote']
|
2014-04-09 17:39:41 +00:00
|
|
|
vote_ids = Vote.search(cr, uid, [('post_id', 'in', ids), ('user_id', '=', uid)], context=context)
|
|
|
|
if vote_ids:
|
|
|
|
for vote in Vote.browse(cr, uid, vote_ids, context=context):
|
|
|
|
if upvote:
|
|
|
|
new_vote = '0' if vote.vote == '-1' else '1'
|
|
|
|
else:
|
|
|
|
new_vote = '0' if vote.vote == '1' else '-1'
|
|
|
|
Vote.write(cr, uid, vote_ids, {'vote': new_vote}, context=context)
|
|
|
|
else:
|
|
|
|
for post_id in ids:
|
|
|
|
new_vote = '1' if upvote else '-1'
|
|
|
|
Vote.create(cr, uid, {'post_id': post_id, 'vote': new_vote}, context=context)
|
|
|
|
return {'vote_count': self._get_vote_count(cr, uid, ids, None, None, context=context)[ids[0]]}
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-04-09 17:25:22 +00:00
|
|
|
def set_viewed(self, cr, uid, ids, context=None):
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
self.write(cr, uid, [post.id], {'views': post.views + 1}, context=context)
|
|
|
|
return True
|
|
|
|
|
2014-03-25 11:34:09 +00:00
|
|
|
|
2014-03-24 07:11:52 +00:00
|
|
|
class PostReason(osv.Model):
|
2014-04-10 13:39:28 +00:00
|
|
|
_name = "forum.post.reason"
|
|
|
|
_description = "Post Closing Reason"
|
2014-03-24 07:11:52 +00:00
|
|
|
_columns = {
|
2014-04-10 13:39:28 +00:00
|
|
|
'name': fields.char('Post Reason', required=True),
|
2014-03-24 07:11:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class Vote(osv.Model):
|
2014-04-10 13:39:28 +00:00
|
|
|
_name = 'forum.post.vote'
|
2014-02-22 17:19:37 +00:00
|
|
|
_description = 'Vote'
|
|
|
|
_columns = {
|
2014-04-10 13:39:28 +00:00
|
|
|
'post_id': fields.many2one('forum.post', 'Post', ondelete='cascade', required=True),
|
2014-04-15 13:19:29 +00:00
|
|
|
'user_id': fields.many2one('res.users', 'User', required=True),
|
2014-04-09 16:50:59 +00:00
|
|
|
'vote': fields.selection([('1', '1'), ('-1', '-1'), ('0', '0')], 'Vote', required=True),
|
2014-03-20 08:51:49 +00:00
|
|
|
'create_date': fields.datetime('Create Date', select=True, readonly=True),
|
2014-02-22 06:02:01 +00:00
|
|
|
}
|
2014-03-12 08:46:47 +00:00
|
|
|
_defaults = {
|
|
|
|
'user_id': lambda self, cr, uid, ctx: uid,
|
2014-04-09 16:50:59 +00:00
|
|
|
'vote': lambda *args: '1',
|
2014-03-12 08:46:47 +00:00
|
|
|
}
|
2014-03-13 08:41:30 +00:00
|
|
|
|
2014-03-05 13:07:24 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
|
|
|
vote_id = super(Vote, self).create(cr, uid, vals, context=context)
|
2014-04-18 13:29:05 +00:00
|
|
|
if vals.get('vote', '1') == '1':
|
|
|
|
karma = self.pool['forum.forum']._karma_upvote
|
|
|
|
elif vals.get('vote', '1') == '-1':
|
|
|
|
karma = self.pool['forum.forum']._karma_downvote
|
|
|
|
post = self.pool['forum.post'].browse(cr, uid, vals['post_id'], context=context)
|
|
|
|
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [post.create_uid.id], karma, context=context)
|
2014-03-05 13:07:24 +00:00
|
|
|
return vote_id
|
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
def write(self, cr, uid, ids, values, context=None):
|
2014-04-18 13:29:05 +00:00
|
|
|
def _get_karma_value(old_vote, new_vote, up_karma, down_karma):
|
|
|
|
_karma_upd = {
|
|
|
|
'-1': {'-1': 0, '0': -1 * down_karma, '1': -1 * down_karma + up_karma},
|
|
|
|
'0': {'-1': 1 * down_karma, '0': 0, '1': up_karma},
|
|
|
|
'1': {'-1': -1 * up_karma + down_karma, '0': -1 * up_karma, '1': 0}
|
|
|
|
}
|
|
|
|
return _karma_upd[old_vote][new_vote]
|
2014-04-09 16:50:59 +00:00
|
|
|
if 'vote' in values:
|
2014-04-18 13:29:05 +00:00
|
|
|
Forum = self.pool['forum.forum']
|
2014-04-09 16:50:59 +00:00
|
|
|
for vote in self.browse(cr, uid, ids, context=context):
|
2014-04-18 13:29:05 +00:00
|
|
|
if vote.post_id.parent_id:
|
|
|
|
karma_value = _get_karma_value(vote.vote, values['vote'], Forum._karma_gen_upvote_ans, Forum._karma_gen_downvote_ans)
|
|
|
|
else:
|
|
|
|
karma_value = _get_karma_value(vote.vote, values['vote'], Forum._karma_gen_upvote_quest, Forum._karma_gen_downvote_quest)
|
|
|
|
self.pool['res.users'].add_karma(cr, SUPERUSER_ID, [vote.post_id.create_uid.id], karma_value, context=context)
|
2014-04-15 13:19:29 +00:00
|
|
|
res = super(Vote, self).write(cr, uid, ids, values, context=context)
|
2014-04-09 16:50:59 +00:00
|
|
|
return res
|
|
|
|
|
2014-03-18 09:01:54 +00:00
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class Tags(osv.Model):
|
2014-04-10 13:39:28 +00:00
|
|
|
_name = "forum.tag"
|
2014-02-22 06:27:15 +00:00
|
|
|
_description = "Tag"
|
2014-02-21 13:16:08 +00:00
|
|
|
_inherit = ['website.seo.metadata']
|
2014-03-19 13:04:13 +00:00
|
|
|
|
2014-03-12 08:46:47 +00:00
|
|
|
def _get_posts_count(self, cr, uid, ids, field_name, arg, context=None):
|
2014-04-10 13:39:28 +00:00
|
|
|
return dict((tag_id, self.pool['forum.post'].search_count(cr, uid, [('tag_ids', 'in', tag_id)], context=context)) for tag_id in ids)
|
2014-03-11 09:25:17 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
def _get_tag_from_post(self, cr, uid, ids, context=None):
|
|
|
|
return list(set(
|
2014-04-10 13:39:28 +00:00
|
|
|
[tag.id for post in self.pool['forum.post'].browse(cr, SUPERUSER_ID, ids, context=context) for tag in post.tag_ids]
|
2014-04-09 16:50:59 +00:00
|
|
|
))
|
2014-03-19 13:04:13 +00:00
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
_columns = {
|
2014-04-10 13:39:28 +00:00
|
|
|
'name': fields.char('Name', required=True),
|
|
|
|
'forum_id': fields.many2one('forum.forum', 'Forum', required=True),
|
|
|
|
'post_ids': fields.many2many('forum.post', 'forum_tag_rel', 'tag_id', 'post_id', 'Posts'),
|
2014-04-09 16:50:59 +00:00
|
|
|
'posts_count': fields.function(
|
2014-04-10 13:39:28 +00:00
|
|
|
_get_posts_count, type='integer', string="Number of Posts",
|
2014-03-19 13:04:13 +00:00
|
|
|
store={
|
2014-04-10 13:39:28 +00:00
|
|
|
'forum.post': (_get_tag_from_post, ['tag_ids'], 10),
|
2014-03-19 13:04:13 +00:00
|
|
|
}
|
|
|
|
),
|
2014-04-15 10:18:42 +00:00
|
|
|
'create_uid': fields.many2one('res.users', 'Created by', readonly=True),
|
2014-04-09 16:50:59 +00:00
|
|
|
}
|