diff --git a/addons/website_forum/__openerp__.py b/addons/website_forum/__openerp__.py index 741dc3b01b0..d01816c387e 100644 --- a/addons/website_forum/__openerp__.py +++ b/addons/website_forum/__openerp__.py @@ -23,7 +23,7 @@ { 'name': 'Forum', 'category': 'Website', - 'summary': 'Ask Questions and give Answers', + 'summary': 'Forum, FAQ, Q&A', 'version': '1.0', 'description': """ Ask questions, get answers, no distractions diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index cba4dc9ab6b..62e228f8a1b 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -322,17 +322,4 @@ class website_forum(http.Controller): def post_vote(self, **post): cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id')) Vote = request.registry['website.forum.post.vote'] - Post = request.registry['website.forum.post'] - vote_ids = Vote.search(cr, uid, [('post_id', '=', post_id)], context=context) - - if vote_ids: - Vote.unlink(cr, uid, vote_ids, context=context) - else: - Vote.create(cr, uid, { - 'post_id': post_id, - 'user_id': uid, - 'vote': post.get('vote'), - }, context=context) - record = Post.browse(cr, uid, post_id, context=context) - - return record.vote_count + return Vote.vote(cr, uid, post_id, post.get('vote'), context) diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/website_forum.py index 174063e649b..dba8d0a7163 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/website_forum.py @@ -147,22 +147,16 @@ class Post(osv.Model): } def create_history(self, cr, uid, ids, vals, context=None): - History = self.pool['website.forum.post.history'] - for post in ids: - if vals.get('content'): - create_date = vals.get('create_date') - res = { - 'name': 'Update %s - %s' % (create_date, vals.get('name')), - 'content': vals.get('content', ''), - 'post_id': post - } - 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, context=context) + hist_obj = self.pool['website.forum.post.history'] + for post in self.browse(cr, uid, ids, context=context): + hist_obj.create(cr, uid, { + 'post_id': post.id, + 'content': post.content, + 'name': post.name, + 'tags': [(6,0, [x.id for x in post.tags])], + 'date': post.write_date or post.create_date, + 'user_id': post.write_uid and post.write_uid.id or post.create_uid.id + }, context=context) def create(self, cr, uid, vals, context=None): if context is None: @@ -202,7 +196,7 @@ class Users(osv.Model): _columns = { 'create_date': fields.datetime('Create Date', select=True, readonly=True), - 'karma': fields.integer('Karma'), # Use Gamification for this + 'karma': fields.integer('Karma'), # Use a function field for this 'forum': fields.boolean('Is Forum Member'), 'badges': fields.one2many('gamification.badge.user', 'user_id', 'Badges'), @@ -220,11 +214,10 @@ class PostHistory(osv.Model): _description = 'Post History' _inherit = ['website.seo.metadata'] _columns = { - 'name': fields.char('Update Notes', size=64, required=True), + 'name': fields.char('Post Title') 'post_id': fields.many2one('website.forum.post', 'Post', ondelete='cascade'), - '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'), + 'date': fields.datetime('Created on', select=True, readonly=True), + 'user_id': fields.many2one('res.users', 'Created by', select=True, readonly=True), 'content': fields.html('Contents', help='Automatically sanitized HTML contents'), 'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'), } @@ -235,9 +228,15 @@ class Vote(osv.Model): _columns = { 'post_id': fields.many2one('website.forum.post', 'Post', required=True), 'user_id': fields.many2one('res.users', 'User'), - 'vote': fields.selection([('1', '1'),('-1', '-1')], 'rate'), + 'vote': fields.selection([('1', '1'),('-1', '-1'),('0','0')], 'Vote'), } - + _defaults = { + 'user_id': lambda self, cr, uid, ctx: uid, + 'vote': lambda *args: 1 + } + # TODO: improve this: translate strings _() + # no need to have different text for question/answer + # need different text for upvote, downvote def create(self, cr, uid, vals, context=None): vote_id = super(Vote, self).create(cr, uid, vals, context=context) Post = self.pool["website.forum.post"] @@ -248,33 +247,42 @@ class Vote(osv.Model): Post.message_post(cr, uid, [record.id], body=body, context=context) return vote_id + def vote(self, cr, uid, post_id, vote, context=None): + assert int(vote) in (1, -1, 0), "vote can be -1 or 1, nothing else" + post_obj = self.pool.get('website.forum.post') + vote_ids = self.search(cr, uid, [('post_id', '=', post_id), ('user_id','=',uid)], context=context) + if vote_ids: + self.write(cr, uid, vote_uid, { + 'vote': vote) + }, context=context) + else: + self.create(cr, uid, { + 'post_id': post_id, + 'vote': vote, + }, context=context) + return post_obj.browse(cr, uid, post_id, context=context).vote_count + class Badge(osv.Model): _inherit = 'gamification.badge' _columns = { + # TODO: remove this forum field and use level is not False instead 'forum': fields.boolean('Is a Forum Badge'), - 'level': fields.selection([('bronze', 'bronze'), ('silver', 'silver'), ('gold', 'gold')], 'Badge Level'), - } - _defaults = { - 'forum': False, - 'level': 'bronze' + 'level': fields.selection([('bronze', 'bronze'), ('silver', 'silver'), ('gold', 'gold')], 'Forum Badge Level'), } class Tags(osv.Model): _name = "website.forum.tag" _description = "Tag" _inherit = ['website.seo.metadata'] - - def _get_questions(self, cr, uid, ids, field_name, arg, context=None): + def _get_posts_count(self, cr, uid, ids, field_name, arg, context=None): result = {} Post = self.pool['website.forum.post'] for tag in ids: - question_ids = Post.search(cr, uid , [('tags.id', '=', tag)], context=context) - result[tag] = question_ids + result[tag] = Post.search_count(cr, uid , [('tags', '=', tag)], context=context) return result _columns = { 'name': fields.char('Name', size=64, required=True), 'forum_id': fields.many2one('website.forum', 'Forum', required=True), - 'post_ids': fields.function(_get_questions, type='many2many', relation="website.forum.post", string="Questions", - ), + 'posts_count': fields.function(_get_posts_count, type='integer', string="# of Posts"), } diff --git a/addons/website_forum/tests/__init__.py b/addons/website_forum/tests/__init__.py index 3dcbf31d714..96bcdb5aa14 100644 --- a/addons/website_forum/tests/__init__.py +++ b/addons/website_forum/tests/__init__.py @@ -19,6 +19,3 @@ # ############################################################################## -#import test_ui - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/website_forum/tests/test_ui.py b/addons/website_forum/tests/test_ui.py deleted file mode 100644 index 8337c357c40..00000000000 --- a/addons/website_forum/tests/test_ui.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2013-Today OpenERP SA (). -# -# 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 . -# -############################################################################## - -import openerp.tests - -class TestUi(openerp.tests.HttpCase): - def test_admin(self): - self.phantom_js("/", "openerp.website.Tour.run_test('question')", "openerp.website.Tour") - diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 6fcd176819d..9406b8f4bea 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -425,7 +425,7 @@ - X + X