From d743ac0a8369860b950b3d137c2fa648585e070e Mon Sep 17 00:00:00 2001 From: "Turkesh Patel (Open ERP)" Date: Fri, 21 Feb 2014 18:46:08 +0530 Subject: [PATCH] [ADD] website_forum for question and answer bzr revid: tpa@tinyerp.com-20140221131608-e37a88h2u8ljkomr --- addons/website_event/controllers/main.py | 4 + addons/website_forum/__init__.py | 23 ++ addons/website_forum/__openerp__.py | 25 ++ addons/website_forum/controllers/__init__.py | 3 + addons/website_forum/controllers/main.py | 94 ++++++ addons/website_forum/data/forum_data.xml | 22 ++ addons/website_forum/data/forum_demo.xml | 71 +++++ addons/website_forum/doc/changelog.rst | 9 + addons/website_forum/doc/index.rst | 10 + addons/website_forum/models/__init__.py | 1 + addons/website_forum/models/forum.py | 85 +++++ .../security/ir.model.access.csv | 2 + .../website_forum/security/website_forum.xml | 6 + addons/website_forum/static/src/css/Makefile | 2 + .../static/src/css/website_forum.css | 55 ++++ .../static/src/css/website_forum.sass | 5 + .../static/src/js/website.tour.forum.js | 31 ++ .../static/src/js/website_forum.editor.js | 31 ++ .../static/src/xml/website_forum.xml | 7 + addons/website_forum/tests/__init__.py | 24 ++ addons/website_forum/tests/test_ui.py | 6 + addons/website_forum/views/website_forum.xml | 292 ++++++++++++++++++ 22 files changed, 808 insertions(+) create mode 100644 addons/website_forum/__init__.py create mode 100644 addons/website_forum/__openerp__.py create mode 100644 addons/website_forum/controllers/__init__.py create mode 100644 addons/website_forum/controllers/main.py create mode 100644 addons/website_forum/data/forum_data.xml create mode 100644 addons/website_forum/data/forum_demo.xml create mode 100644 addons/website_forum/doc/changelog.rst create mode 100644 addons/website_forum/doc/index.rst create mode 100644 addons/website_forum/models/__init__.py create mode 100644 addons/website_forum/models/forum.py create mode 100644 addons/website_forum/security/ir.model.access.csv create mode 100644 addons/website_forum/security/website_forum.xml create mode 100644 addons/website_forum/static/src/css/Makefile create mode 100644 addons/website_forum/static/src/css/website_forum.css create mode 100644 addons/website_forum/static/src/css/website_forum.sass create mode 100644 addons/website_forum/static/src/js/website.tour.forum.js create mode 100644 addons/website_forum/static/src/js/website_forum.editor.js create mode 100644 addons/website_forum/static/src/xml/website_forum.xml create mode 100644 addons/website_forum/tests/__init__.py create mode 100644 addons/website_forum/tests/test_ui.py create mode 100644 addons/website_forum/views/website_forum.xml diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py index 2a6e1d134e3..21d259a3b70 100644 --- a/addons/website_event/controllers/main.py +++ b/addons/website_event/controllers/main.py @@ -35,6 +35,7 @@ import werkzeug.urls class website_event(http.Controller): @http.route(['/event/', '/event/page/'], type='http', auth="public", website=True, multilang=True) def events(self, page=1, **searches): + print "events----------------",self,page,searches cr, uid, context = request.cr, request.uid, request.context event_obj = request.registry['event.event'] type_obj = request.registry['event.type'] @@ -162,6 +163,7 @@ class website_event(http.Controller): @http.route(['/event//page/'], type='http', auth="public", website=True, multilang=True) def event_page(self, event, page, **post): + print "event_page-------------------" values = { 'event': event, 'main_object': event @@ -170,6 +172,7 @@ class website_event(http.Controller): @http.route(['/event/'], type='http', auth="public", website=True, multilang=True) def event(self, event, **post): + print "in event---------------" if event.menu_id and event.menu_id.child_id: target_url = event.menu_id.child_id[0].url else: @@ -180,6 +183,7 @@ class website_event(http.Controller): @http.route(['/event//register'], type='http', auth="public", website=True, multilang=True) def event_register(self, event, **post): + print "event_register-------------------" values = { 'event': event, 'main_object': event, diff --git a/addons/website_forum/__init__.py b/addons/website_forum/__init__.py new file mode 100644 index 00000000000..708d6ce4669 --- /dev/null +++ b/addons/website_forum/__init__.py @@ -0,0 +1,23 @@ +# -*- 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 controllers +import models diff --git a/addons/website_forum/__openerp__.py b/addons/website_forum/__openerp__.py new file mode 100644 index 00000000000..5bc52222ba8 --- /dev/null +++ b/addons/website_forum/__openerp__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +{ + 'name': 'Forum', + 'category': 'Website', + 'summary': 'Ask Questions and give Answers', + 'version': '1.0', + 'description': """ +Ask questions, get answers, no distractions + """, + 'author': 'OpenERP SA', + 'depends': ['website', 'website_mail'], + 'data': [ + 'data/forum_data.xml', + 'views/website_forum.xml', + 'security/ir.model.access.csv', + 'security/website_forum.xml', + ], + 'qweb': ['static/src/xml/*.xml'], + 'demo': [ + 'data/forum_demo.xml' + ], + 'installable': True, + 'application': True, +} diff --git a/addons/website_forum/controllers/__init__.py b/addons/website_forum/controllers/__init__.py new file mode 100644 index 00000000000..bbd183e955b --- /dev/null +++ b/addons/website_forum/controllers/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import main diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py new file mode 100644 index 00000000000..3605085188d --- /dev/null +++ b/addons/website_forum/controllers/main.py @@ -0,0 +1,94 @@ +# -*- 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 . +# +############################################################################## + +from openerp import SUPERUSER_ID +from openerp.addons.web import http +from openerp.addons.web.http import request +from openerp.tools.translate import _ +from openerp.addons.website.controllers.main import Website as controllers +controllers = controllers() + + +from datetime import datetime, timedelta +from dateutil.relativedelta import relativedelta +from openerp import tools +import werkzeug.urls + +class website_forum(http.Controller): + @http.route(['/question/', '/question/page/'], type='http', auth="public", website=True, multilang=True) + def questions(self, page=1, **searches): + print "questions----------------",self,page,searches + cr, uid, context = request.cr, request.uid, request.context + forum_obj = request.registry['website.forum.post'] + tag_obj = request.registry['website.forum.tag'] + + step = 5 + question_count = forum_obj.search( + request.cr, request.uid, [], count=True, + context=request.context) + pager = request.website.pager(url="/question/", total=question_count, page=page, step=step, scope=5) + + obj_ids = forum_obj.search( + request.cr, request.uid, [], limit=step, + offset=pager['offset'], context=request.context) + question_ids = forum_obj.browse(request.cr, request.uid, obj_ids, + context=request.context) + + print "question_ids----",question_ids + values = { + 'question_ids': question_ids, + 'pager': pager, + 'searches': searches, + } + + return request.website.render("website_forum.index", values) + + @http.route(['/question//page/'], type='http', auth="public", website=True, multilang=True) + def question_page(self, question, page, **post): + values = { + 'question': question, + 'main_object': question + } + return request.website.render(page, values) + + @http.route(['/question/'], type='http', auth="public", website=True, multilang=True) + def question_register(self, question, **post): + values = { + 'question': question, + 'main_object': question, + 'range': range, + } + return request.website.render("website_forum.question_description_full", values) + + @http.route('/question/add_question/', type='http', auth="user", multilang=True, methods=['POST'], website=True) + def add_question(self, question_name="New question", **kwargs): + return self._add_question(question_name, request.context, **kwargs) + + def _add_question(self, question_name=None, context={}, **kwargs): + if not question_name: + question_name = _("New Question") + Question = request.registry.get('website.forum.post') + date_begin = datetime.today() + timedelta(days=(14)) + vals = { + 'topic': question_name, + } + question_id = Question.create(request.cr, request.uid, vals, context=context) + return request.redirect("/question/%s/?enable_editor=1" % question_id) diff --git a/addons/website_forum/data/forum_data.xml b/addons/website_forum/data/forum_data.xml new file mode 100644 index 00000000000..bd6e56f673e --- /dev/null +++ b/addons/website_forum/data/forum_data.xml @@ -0,0 +1,22 @@ + + + + + + Questions + /question + + 40 + + + + + diff --git a/addons/website_forum/data/forum_demo.xml b/addons/website_forum/data/forum_demo.xml new file mode 100644 index 00000000000..92891bba371 --- /dev/null +++ b/addons/website_forum/data/forum_demo.xml @@ -0,0 +1,71 @@ + + + + + + How to configure alerts for employee contract expiration. + 45 + + + + How to get translated state through browse ? + Hello everybody, + +I use a XML-RPC to access to invoices, I want to get the states of invoices, but always I get paid instead of PayƩ (French) + 45 + + + + Restrain the user from confirming the Purchase requisition + 45 + Can anybody tell me how to restrict the user from confirming the purchase requisition? In my case when a user is creating a purchase requisition than the user after saving it is able to send it to the supplier rather I want the user to just generate the purchase requisition and let the manager do the remaining works like sending the purchase requisition to the supplier and than receiving the goods. Please help me out. Thanks in advance. + + + + Offline installing for add-ons + 45 + How can I install web based addons without Internet connections (I'm using OpenERP over LAN)? + +P.S. + +AFAIK current version (7.x) supports web interface while the desktop clients became deprecated. +BTW, I left OpenERP since ver. 6.x to use PostBooks instead but I recently decided to use OpenERP once again after recent new features. + + + + CMS replacement for ERP and eCommerce + 45 + I use Wordpress as a CMS and eCommerce platform. The developing in Wordpress is too easy and solid but it missing ERP feature (there is single plugin to integrate with Frontaccounting) so I wonder: + +Can I use OpenERP as a replacement CMS of Wordpress + eCommerce plugin? + +In simple words does OpenERP became CMS+ERP platform? + + + + Register payment using XMLRPC + 45 + Hi there, + +I have been trying to register an invoice payment through OpenERP. I have been able to manually create and approve the invoice, the voucher and its line + +I'm currently creating the voucher using this information: + + + + Create one field on two modules + 45 + Hello, + +I shall like creating a field "x" on an order form ( stock.picking.form ) and to reveal it also on the delivery slip ( stock.picking.form ). + +Thank you in advance + + + + access rights to one2many field + 45 + Now i create new group , assign user and access right as READ & CREATE to object stock.picking.ads but nothing is reflected , iam able to delete and write which should not happen. Very Strange!!! + + + diff --git a/addons/website_forum/doc/changelog.rst b/addons/website_forum/doc/changelog.rst new file mode 100644 index 00000000000..51036d22b70 --- /dev/null +++ b/addons/website_forum/doc/changelog.rst @@ -0,0 +1,9 @@ +.. _changelog: + +Changelog +========= + +`trunk (saas-3)` +---------------- + + - created ``website_forum`` diff --git a/addons/website_forum/doc/index.rst b/addons/website_forum/doc/index.rst new file mode 100644 index 00000000000..104e0473263 --- /dev/null +++ b/addons/website_forum/doc/index.rst @@ -0,0 +1,10 @@ +Website Forum Module documentation topics +''''''''''''''''''''''''''''''''''''''''' + +Changelog +''''''''' + +.. toctree:: + :maxdepth: 1 + + changelog.rst diff --git a/addons/website_forum/models/__init__.py b/addons/website_forum/models/__init__.py new file mode 100644 index 00000000000..55d2f069a75 --- /dev/null +++ b/addons/website_forum/models/__init__.py @@ -0,0 +1 @@ +import forum diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py new file mode 100644 index 00000000000..087e3a1e5ec --- /dev/null +++ b/addons/website_forum/models/forum.py @@ -0,0 +1,85 @@ +# -*- 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 . +# +############################################################################## + +from openerp.osv import osv, fields +from openerp import SUPERUSER_ID + +from openerp.tools.translate import _ +import re + +from openerp.addons.website.models.website import slug + +#class WebsiteForum(osv.Model): +# _inhrit = "website" + +class website_form_post_rate(osv.Model): + _name = "website.forum.post.rate" + _column = { + 'post_id': fields.many2one('website.forum.post', 'Forum Post'), + 'user_id': fields.many2one('res.users', 'User'), + 'rate': fields.integer('rate'), + } + +class website_forum_post(osv.Model): + _name = "website.forum.post" + _description = "Website forum post" + _inherit = ['mail.thread', 'website.seo.metadata'] + + _columns = { + #add version and category , instead of page use category in website, + 'name': fields.char('Topic', size=64), + 'body': fields.html('Contents', help='Automatically sanitized HTML contents'), + #'forum_id': fields.many2one('website.forum', 'Forum'), + 'create_date': fields.datetime('Created on', select=True, readonly=True), + 'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True ), + 'write_date': fields.datetime('Last Modified on', select=True, readonly=True ), + 'write_uid': fields.many2one('res.users', 'Last Contributor', select=True, readonly=True), + 'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'), + 'up_votes': fields.many2many('res.users', 'forum_user_upvotes_rel', 'forum_id', 'user_id', 'Up votes'), + 'favourite_que_ids': fields.many2many('res.users', 'forum_user_fav_rel', 'forum_id', 'user_id', 'Down votes'), + 'views': fields.integer('Views'), + 'state': fields.selection([('active', 'Active'),('close', 'Close'),('offensive', 'Offensive')], 'Status'), + 'parent_id': fields.many2one('website.forum.post', 'Parent'), + 'child_ids': fields.one2many('website.forum.post', 'parent_id', 'Child'), + # 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') + ], + string='Website Messages', + help="Website communication history", + ), + } + _defaults = { + 'state': 'active', + } + +class website_forum_tag(osv.Model): + _name = "website.forum.tag" + _description = "Website forum tag" + _inherit = ['website.seo.metadata'] + _columns = { + 'name': fields.char('Order Reference', size=64, required=True), + #'forum_id': fields.many2one('website.forum', 'Forum'), + 'post_ids': fields.many2many('website.forum.post', 'forum_tag_que_rel', 'tag_id', 'forum_id', 'Question', readonly=True), + } + diff --git a/addons/website_forum/security/ir.model.access.csv b/addons/website_forum/security/ir.model.access.csv new file mode 100644 index 00000000000..08145a00f54 --- /dev/null +++ b/addons/website_forum/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink + diff --git a/addons/website_forum/security/website_forum.xml b/addons/website_forum/security/website_forum.xml new file mode 100644 index 00000000000..b3570a73da0 --- /dev/null +++ b/addons/website_forum/security/website_forum.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/addons/website_forum/static/src/css/Makefile b/addons/website_forum/static/src/css/Makefile new file mode 100644 index 00000000000..8d2edfb2ed2 --- /dev/null +++ b/addons/website_forum/static/src/css/Makefile @@ -0,0 +1,2 @@ +sass: + sass --compass --unix-newlines -t expanded website_forum.sass:website_forum.css diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css new file mode 100644 index 00000000000..46e39282f90 --- /dev/null +++ b/addons/website_forum/static/src/css/website_forum.css @@ -0,0 +1,55 @@ +@charset "utf-8"; +@import url(compass/css3.css); + +.MainBody{ + max-width: 700px; +} +.AskButton{ + float: right; +} +.search-navbar{ + width: 80%; +} +.user-profile-image{ + height: 32px; + width: 32px; +} +.action-links{ + margin-left: 10px; + margin-right: 10px; +} +.like{ + color: green; +} +.badge-gold{ + color : #FFD700; + text-shadow: 0px 0px 10px yellow; +} +.badge-silver{ + color : #C0C0C0; + text-shadow: 0px 0px 10px yellow; +} +.badge-bronze{ + color : #8c7853; + text-shadow: 0px 0px 10px yellow; +} +.-heading{ + background-color: #428bca; + color: white; +} +.user-name-pannel{ + height: 20px; +} +.custom-arrow-height{ + height: 15px; + } +.custom-vote-height{ + height: 30px; +} +.correct-answer{ + color: green; +} +.user-big-profile-image{ + height: 140px; + width: 140px; +} \ No newline at end of file diff --git a/addons/website_forum/static/src/css/website_forum.sass b/addons/website_forum/static/src/css/website_forum.sass new file mode 100644 index 00000000000..02b3490d630 --- /dev/null +++ b/addons/website_forum/static/src/css/website_forum.sass @@ -0,0 +1,5 @@ +@charset "utf-8" + +@import "compass/css3" + + diff --git a/addons/website_forum/static/src/js/website.tour.forum.js b/addons/website_forum/static/src/js/website.tour.forum.js new file mode 100644 index 00000000000..143996e5c38 --- /dev/null +++ b/addons/website_forum/static/src/js/website.tour.forum.js @@ -0,0 +1,31 @@ +(function () { + 'use strict'; + + var website = openerp.website; + var _t = openerp._t; + + website.EditorBar.include({ + start: function () { + this.registerTour(new website.QuestionTour(this)); + return this._super(); + }, + }); + + website.QuestionTour = website.Tour.extend({ + id: 'question', + name: "Create a question", + testPath: '/question(/[0-9]+/register)?', + init: function (editor) { + var self = this; + self.steps = [ + { + title: _t("Create a question"), + content: _t("Let's go through the first steps to create a new question."), + popover: { next: _("Start Tutorial"), end: _("Skip It") }, + }, + ]; + return this._super(); + } + }); + +}()); diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js new file mode 100644 index 00000000000..fc4dd863739 --- /dev/null +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -0,0 +1,31 @@ +(function() { + "use strict"; + + var website = openerp.website; + var _t = openerp._t; + website.add_template_file('/website_forum/static/src/xml/website_forum.xml'); + + website.is_editable = true; + website.EditorBar.include({ + start: function() { + website.is_editable_button = website.is_editable_button || !!$("#wrap.js_event").size(); + var res = this._super(); + this.$(".dropdown:has(.oe_content_menu)").removeClass("hidden"); + return res; + }, + events: _.extend({}, website.EditorBar.prototype.events, { + 'click a[data-action=new_question]': function (ev) { + ev.preventDefault(); + website.prompt({ + id: "editor_new_question", + window_title: _t("New Question"), + input: "Question Name", + }).then(function (question_name) { + website.form('/forum/add_question', 'POST', { + question_name: question_name + }); + }); + } + }), + }); +})(); diff --git a/addons/website_forum/static/src/xml/website_forum.xml b/addons/website_forum/static/src/xml/website_forum.xml new file mode 100644 index 00000000000..78042288b23 --- /dev/null +++ b/addons/website_forum/static/src/xml/website_forum.xml @@ -0,0 +1,7 @@ + + + +
  • New Question
  • +
    +
    +
    diff --git a/addons/website_forum/tests/__init__.py b/addons/website_forum/tests/__init__.py new file mode 100644 index 00000000000..3dcbf31d714 --- /dev/null +++ b/addons/website_forum/tests/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Business Applications +# Copyright (c) 20123TODAY OpenERP S.A. +# +# 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 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 new file mode 100644 index 00000000000..fe95435e4df --- /dev/null +++ b/addons/website_forum/tests/test_ui.py @@ -0,0 +1,6 @@ +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 new file mode 100644 index 00000000000..f8fdc5e7d06 --- /dev/null +++ b/addons/website_forum/views/website_forum.xml @@ -0,0 +1,292 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +