2014-02-21 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2014-02-22 17:19:37 +00:00
|
|
|
import re
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-02-22 17:19:37 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
|
|
|
from openerp.osv import osv, fields
|
2014-02-21 13:16:08 +00:00
|
|
|
from openerp.tools.translate import _
|
|
|
|
|
|
|
|
from openerp.addons.website.models.website import slug
|
|
|
|
|
2014-02-22 06:27:15 +00:00
|
|
|
#TODO: Do we need a forum object like blog object ? Need to check with BE team
|
2014-02-22 17:19:37 +00:00
|
|
|
class Forum(osv.Model):
|
|
|
|
_name = 'website.forum'
|
2014-03-03 19:17:48 +00:00
|
|
|
_description = 'Forums'
|
2014-02-22 17:19:37 +00:00
|
|
|
_inherit = ['mail.thread', 'website.seo.metadata']
|
|
|
|
_order = 'name'
|
|
|
|
_columnss = {
|
2014-03-03 19:17:48 +00:00
|
|
|
'name': fields.char('Name', required=True, translate=True),
|
|
|
|
'faq': fields.html('FAQ'),
|
|
|
|
'right_column': fields.html('FAQ'),
|
2014-02-22 17:19:37 +00:00
|
|
|
}
|
2014-02-22 06:27:15 +00:00
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class Post(osv.Model):
|
2014-02-22 17:19:37 +00:00
|
|
|
_name = 'website.forum.post'
|
2014-02-22 06:02:01 +00:00
|
|
|
_description = "Question"
|
2014-02-21 13:16:08 +00:00
|
|
|
_inherit = ['mail.thread', 'website.seo.metadata']
|
|
|
|
|
|
|
|
_columns = {
|
2014-03-03 19:17:48 +00:00
|
|
|
'forum_id': fields.many2one('website.forum', 'Forum', required=True),
|
2014-02-21 13:16:08 +00:00
|
|
|
'name': fields.char('Topic', size=64),
|
2014-02-25 10:42:42 +00:00
|
|
|
'content': fields.text('Contents', help='contents'),
|
2014-02-22 06:02:01 +00:00
|
|
|
'create_date': fields.datetime('Asked on', select=True, readonly=True),
|
|
|
|
'create_uid': fields.many2one('res.users', 'Asked by', select=True, readonly=True ),
|
|
|
|
'write_date': fields.datetime('Update on', select=True, readonly=True ),
|
|
|
|
'write_uid': fields.many2one('res.users', 'Update by', select=True, readonly=True),
|
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
2014-02-22 17:19:37 +00:00
|
|
|
'vote_ids':fields.one2many('website.forum.post.vote', 'post_id', 'Vote'),
|
2014-02-22 06:02:01 +00:00
|
|
|
|
|
|
|
'favourite_ids': fields.many2many('res.users', 'forum_favourite_rel', 'forum_id', 'user_id', 'Favourite'),
|
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
'state': fields.selection([('active', 'Active'),('close', 'Close'),('offensive', 'Offensive')], 'Status'),
|
2014-02-22 06:02:01 +00:00
|
|
|
'active': fields.boolean('Active'),
|
|
|
|
'views': fields.integer('Views'),
|
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
'parent_id': fields.many2one('website.forum.post', 'Parent'),
|
|
|
|
'child_ids': fields.one2many('website.forum.post', 'parent_id', 'Child'),
|
2014-02-22 06:02:01 +00:00
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
# TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
|
|
|
'website_message_ids': fields.one2many(
|
|
|
|
'mail.message', 'res_id',
|
|
|
|
domain=lambda self: [
|
|
|
|
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
|
|
|
],
|
2014-02-22 06:02:01 +00:00
|
|
|
string='Post Messages',
|
|
|
|
help="Comments on forum post",
|
2014-02-21 13:16:08 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'state': 'active',
|
2014-02-22 06:02:01 +00:00
|
|
|
'active': True
|
2014-02-21 13:16:08 +00:00
|
|
|
}
|
2014-02-23 07:15:16 +00:00
|
|
|
|
|
|
|
def create_history(self, cr, uid, ids, vals, context=None):
|
2014-03-03 09:06:16 +00:00
|
|
|
for post in ids:
|
2014-02-23 07:15:16 +00:00
|
|
|
history = self.pool.get('website.forum.post.history')
|
|
|
|
if vals.get('content'):
|
|
|
|
create_date = vals.get('create_date')
|
|
|
|
res = {
|
|
|
|
'name': 'Update %s - %s' % (create_date, vals.get('name')),
|
|
|
|
'content': vals.get('content', ''),
|
2014-03-03 09:06:16 +00:00
|
|
|
'post_id': post
|
2014-02-23 07:15:16 +00:00
|
|
|
}
|
|
|
|
if vals.get('version'):
|
|
|
|
res.update({'version':vals.get('version')})
|
|
|
|
|
|
|
|
if vals.get('tags'):
|
|
|
|
res.update({'tags':vals.get('tags')})
|
|
|
|
|
|
|
|
history.create(cr, uid, res)
|
|
|
|
|
|
|
|
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_history(cr, uid, [post_id], vals, context)
|
|
|
|
return post_id
|
|
|
|
|
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
|
|
|
result = super(Post, self).write(cr, uid, ids, vals, context)
|
|
|
|
self.create_history(cr, uid, ids, vals, context)
|
|
|
|
return result
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-02-22 06:27:15 +00:00
|
|
|
class Users(osv.Model):
|
|
|
|
_inherit = 'res.users'
|
|
|
|
_columns = {
|
2014-03-03 20:34:25 +00:00
|
|
|
# TODO: Remove these 3 field and compute number in /user controller
|
2014-02-26 06:58:45 +00:00
|
|
|
'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)]),
|
2014-02-22 06:27:15 +00:00
|
|
|
'vote_ids': fields.one2many('website.forum.post.vote', 'user_id', 'Votes'),
|
2014-03-03 20:34:25 +00:00
|
|
|
|
|
|
|
# Field to remove
|
2014-02-26 06:58:45 +00:00
|
|
|
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
2014-03-03 20:34:25 +00:00
|
|
|
|
2014-03-03 11:06:20 +00:00
|
|
|
'create_date': fields.datetime('Create Date', select=True, readonly=True),
|
2014-03-03 20:34:25 +00:00
|
|
|
'karma': fields.integer('Karma'), # Use Gamification for this
|
|
|
|
'forum': fields.boolean('Is Forum Member')
|
2014-03-03 19:17:48 +00:00
|
|
|
|
2014-02-22 17:19:37 +00:00
|
|
|
# TODO: 'tag_ids':fields.function()
|
2014-03-03 19:17:48 +00:00
|
|
|
# Badges : use the gamification module
|
2014-02-22 06:27:15 +00:00
|
|
|
}
|
2014-03-03 20:34:25 +00:00
|
|
|
_defaults = {
|
|
|
|
'forum': False
|
|
|
|
}
|
2014-02-22 06:27:15 +00:00
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class PostHistory(osv.Model):
|
|
|
|
_name = 'website.forum.post.history'
|
2014-02-22 06:27:15 +00:00
|
|
|
_description = 'Post History'
|
2014-02-22 06:02:01 +00:00
|
|
|
_inherit = ['website.seo.metadata']
|
|
|
|
_columns = {
|
|
|
|
'post_id': fields.many2one('website.forum.post', 'Post'),
|
2014-02-22 06:27:15 +00:00
|
|
|
'create_date': fields.datetime('Created on', select=True, readonly=True),
|
|
|
|
'create_uid': fields.many2one('res.users', 'Created by', select=True, readonly=True),
|
|
|
|
'version': fields.integer('Version'),
|
2014-02-22 06:02:01 +00:00
|
|
|
'name': fields.char('Update Notes', size=64, required=True),
|
2014-02-23 07:15:16 +00:00
|
|
|
'content': fields.html('Contents', help='Automatically sanitized HTML contents'),
|
2014-02-22 06:02:01 +00:00
|
|
|
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
|
|
|
}
|
|
|
|
|
|
|
|
class Vote(osv.Model):
|
2014-02-22 06:27:15 +00:00
|
|
|
_name = 'website.forum.post.vote'
|
2014-02-22 17:19:37 +00:00
|
|
|
_description = 'Vote'
|
|
|
|
_columns = {
|
2014-02-22 06:02:01 +00:00
|
|
|
'post_id': fields.many2one('website.forum.post', 'Post'),
|
|
|
|
'user_id': fields.many2one('res.users', 'User'),
|
2014-02-22 17:19:37 +00:00
|
|
|
'vote': fields.integer('rate'),
|
2014-02-22 06:02:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 20:26:18 +00:00
|
|
|
class ForumActivity(osv.Model):
|
|
|
|
_name = "website.forum.activity"
|
|
|
|
_description = "Activity"
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Order Reference', size=64, required=True),
|
|
|
|
'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),
|
|
|
|
'create_uid': fields.many2one('res.users', 'Created by', select=True, readonly=True),
|
2014-03-03 19:17:48 +00:00
|
|
|
# Use the gamification module instead!
|
2014-02-22 20:26:18 +00:00
|
|
|
'badge_id': fields.many2one('res.groups', 'Badge'),
|
|
|
|
'karma_add': fields.integer('Added Karma'),
|
|
|
|
'karma_sub': fields.integer('Karma Removed')
|
|
|
|
}
|
|
|
|
|
2014-02-22 06:02:01 +00:00
|
|
|
class Tags(osv.Model):
|
2014-02-21 13:16:08 +00:00
|
|
|
_name = "website.forum.tag"
|
2014-02-22 06:27:15 +00:00
|
|
|
_description = "Tag"
|
2014-02-21 13:16:08 +00:00
|
|
|
_inherit = ['website.seo.metadata']
|
|
|
|
_columns = {
|
2014-02-22 20:26:18 +00:00
|
|
|
'name': fields.char('Name', size=64, required=True),
|
2014-02-22 06:27:15 +00:00
|
|
|
'post_ids': fields.many2many('website.forum.post', 'forum_tag_que_rel', 'tag_id', 'forum_id', 'Questions', readonly=True),
|
2014-03-03 19:17:48 +00:00
|
|
|
'forum_id': fields.many2one('website.forum', 'Forum', required=True)
|
2014-02-22 17:19:37 +00:00
|
|
|
}
|
2014-03-03 19:17:48 +00:00
|
|
|
|