[ADD] website_doc: modue based on website_forum to show documentatoin based on questions and best answers.
bzr revid: tpa@tinyerp.com-20140416105122-2368jv31gy26ek32
This commit is contained in:
parent
1c5ed2973e
commit
cd25de6989
|
@ -0,0 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import controllers
|
||||
import models
|
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014-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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
'name': 'Documentation',
|
||||
'category': 'Website',
|
||||
'summary': 'Forum, Documentation',
|
||||
'version': '1.0',
|
||||
'description': """
|
||||
Documentation based on question and pertinent answers of Forum
|
||||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': [
|
||||
'website_forum'
|
||||
],
|
||||
'data': [
|
||||
'data/doc_data.xml',
|
||||
'views/doc.xml',
|
||||
'views/website_doc.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/*.xml'
|
||||
],
|
||||
'demo': [
|
||||
'data/doc_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import main
|
|
@ -0,0 +1,61 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from datetime import datetime
|
||||
import werkzeug.urls
|
||||
import simplejson
|
||||
|
||||
from openerp import tools
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.controllers.main import login_redirect
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.addons.website.controllers.main import Website as controllers
|
||||
from openerp.addons.website.models.website import slug
|
||||
from openerp.addons.website_forum.controllers.main import WebsiteForum
|
||||
|
||||
controllers = controllers()
|
||||
|
||||
class WebsiteDoc(http.Controller):
|
||||
|
||||
@http.route(['/doc'], type='http', auth="public", website=True, multilang=True)
|
||||
def documentation(self, content='', **kwargs):
|
||||
cr, uid, context, toc_id = request.cr, request.uid, request.context, False
|
||||
TOC = request.registry['documentation.toc']
|
||||
obj_ids = TOC.search(cr, uid, [], context=context)
|
||||
toc = TOC.browse(cr, uid, obj_ids, context=context)
|
||||
if content:
|
||||
toc_ids = TOC.search(cr, uid, [('name', '=', content)], context=context)
|
||||
toc_id = TOC.browse(cr, uid, toc_ids, context=context)[0]
|
||||
value = {
|
||||
'documentaion_toc': toc,
|
||||
'toc_id': toc_id,
|
||||
}
|
||||
return request.website.render("website_doc.documentation", value)
|
||||
|
||||
@http.route('/doc/new', type='http', auth="user", multilang=True, website=True)
|
||||
def create_table_of_content(self, toc_name="New Table Of Content", **kwargs):
|
||||
toc_id = request.registry['documentation.toc'].create(request.cr, request.uid, {
|
||||
'name': toc_name,
|
||||
}, context=request.context)
|
||||
return request.redirect("/doc/%s" % slug(toc_id))
|
||||
|
||||
#---------------------
|
||||
# Forum Posts
|
||||
# --------------------
|
||||
|
||||
class WebsiteForum(WebsiteForum):
|
||||
|
||||
def prepare_question_values(self, forum, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
TOC = request.registry['documentation.toc']
|
||||
obj_ids = TOC.search(cr, uid, [], context=context)
|
||||
toc = TOC.browse(cr, uid, obj_ids, context=context)
|
||||
values = super(WebsiteForum, self).prepare_question_values(forum=forum, kwargs=kwargs)
|
||||
values.update({'documentaion_toc': toc})
|
||||
return values
|
||||
|
||||
@http.route('/forum/question/toc', type='json', auth="user", multilang=True, website=True)
|
||||
def post_toc(self, post_id, toc_id):
|
||||
toc_id = int(toc_id) if toc_id else False
|
||||
request.registry['forum.post'].write(request.cr, request.uid, [int(post_id)], {'toc_id': toc_id}, context=request.context)
|
||||
return True
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="menu_questions" model="website.menu">
|
||||
<field name="name">Documentation</field>
|
||||
<field name="url" eval="'/doc'"/>
|
||||
<field name="parent_id" ref="website.main_menu"/>
|
||||
<field name="sequence" type="int">65</field>
|
||||
</record>
|
||||
|
||||
<!-- JUMP TO DOCUMENTATION AT INSTALL -->
|
||||
<record id="action_open_documentation" model="ir.actions.act_url">
|
||||
<field name="name">Documentation</field>
|
||||
<field name="target">self</field>
|
||||
<field name="url" eval="'/doc'"/>
|
||||
</record>
|
||||
<record id="base.open_menu" model="ir.actions.todo">
|
||||
<field name="action_id" ref="action_open_documentation"/>
|
||||
<field name="state">open</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Table Of Content -->
|
||||
<record id="toc_0" model="documentation.toc">
|
||||
<field name="name">CMS & eCommerce</field>
|
||||
</record>
|
||||
<record id="toc_1" model="documentation.toc">
|
||||
<field name="name">Employee Contract</field>
|
||||
</record>
|
||||
|
||||
<!-- Questions -->
|
||||
<record id="website_forum.question_0" model="forum.post">
|
||||
<field name="toc_id" ref="toc_1"/>
|
||||
</record>
|
||||
<record id="website_forum.question_1" model="forum.post">
|
||||
<field name="toc_id" ref="toc_0"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import doc
|
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import openerp
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
class Documentation(osv.Model):
|
||||
_name = 'documentation.toc'
|
||||
_description = 'Table Of Content For Documentation'
|
||||
_inherit = ['website.seo.metadata']
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', required=True, translate=True),
|
||||
'post_ids': fields.one2many('forum.post', 'toc_id', 'Posts'),
|
||||
}
|
||||
|
||||
class Post(osv.Model):
|
||||
_inherit = 'forum.post'
|
||||
|
||||
def _get_pertinent_answer(self, cr, uid, ids, field_name=False, arg={}, context=None):
|
||||
'''Set answer which have been accepted or have maximum votes'''
|
||||
res = {}
|
||||
for post in self.browse(cr, uid, ids, context=context):
|
||||
pertinent_answer_ids = self.search(cr, uid, [('parent_id', '=', post.id)], order='is_correct, vote_count desc', context=context)
|
||||
res[post.id] = pertinent_answer_ids[0] if pertinent_answer_ids else False
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Title', size=128),
|
||||
'toc_id': fields.many2one('documentation.toc', 'Table of Content'),
|
||||
'pertinent_answer_id':fields.function(_get_pertinent_answer, string="Pertinent Answer", type='many2one', relation="forum.post",
|
||||
store={
|
||||
'forum.post': (lambda self, cr, uid, ids, c={}: ids, [], 10),
|
||||
}
|
||||
),
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_documentation_toc,documentation.toc,model_documentation_toc,,1,0,0,0
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
all: website_doc.css
|
||||
%.css: %.sass
|
||||
sass -t expanded --compass --unix-newlines $< $@
|
||||
watch:
|
||||
sass -t expanded --compass --unix-newlines --watch .:.
|
|
@ -0,0 +1,31 @@
|
|||
(function() {
|
||||
"use strict";
|
||||
|
||||
var website = openerp.website;
|
||||
var _t = openerp._t;
|
||||
website.add_template_file('/website_doc/static/src/xml/website_doc.xml');
|
||||
|
||||
website.is_editable = true;
|
||||
website.EditorBar.include({
|
||||
start: function() {
|
||||
website.is_editable_button = website.is_editable_button || !!$("#wrap").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_toc]': function (ev) {
|
||||
ev.preventDefault();
|
||||
website.prompt({
|
||||
id: "editor_new_toc",
|
||||
window_title: _t("New Table Of Content"),
|
||||
input: "Table Of Content Name",
|
||||
}).then(function (toc_name) {
|
||||
website.form('/doc/new', 'POST', {
|
||||
toc_name: toc_name
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
})();
|
|
@ -0,0 +1,12 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
$('.post_toc').change(function (ev) {
|
||||
var $option = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/question/toc", 'call', {
|
||||
'post_id' : $('#question').attr("value"),
|
||||
'toc_id': $option.attr("value"),
|
||||
})
|
||||
return true;
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
<templates id="template" xml:space="preserve">
|
||||
<t t-extend="website.editorbar">
|
||||
<t t-jquery="ul.oe_content_menu" t-operation="append">
|
||||
<li><a href="#" data-action="new_doc">New Table Of Content</a></li>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- DOCUMENTATION TOC VIEWS -->
|
||||
<record id="view_documentation_toc_list" model="ir.ui.view">
|
||||
<field name="name">documentation.toc.list</field>
|
||||
<field name="model">documentation.toc</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Documentation TOC">
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_documentation_toc_form" model="ir.ui.view">
|
||||
<field name="name">documentation.toc.form</field>
|
||||
<field name="model">documentation.toc</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Documentation TOC" version="7.0">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
</group>
|
||||
<separator string="Posts"/>
|
||||
<field name="post_ids"/>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_documentation_toc" model="ir.actions.act_window">
|
||||
<field name="name">Documentation TOC</field>
|
||||
<field name="res_model">documentation.toc</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_documentation" parent="website_forum.menu_website_forum" name="Documentation TOC" action="action_documentation_toc" sequence="10"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Editor custo -->
|
||||
<template id="editor_head" inherit_id="website.editor_head"
|
||||
name="Event Editor">
|
||||
<xpath expr="//script[@id='website_tour_js']" position="after">
|
||||
<script type="text/javascript" src="/website_doc/static/src/js/website_doc.editor.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Layout add nav and footer -->
|
||||
<template id="header_footer_custom" inherit_id="website.layout"
|
||||
name="Footer Documentation Link">
|
||||
<xpath expr="//footer//ul[@name='products']" position="inside">
|
||||
<li><a href="/doc">Documentation</a></li>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Page Index -->
|
||||
<template id="documentation" name="Documentation Index">
|
||||
<t t-call="website.layout">
|
||||
<t t-set="head">
|
||||
<link rel='stylesheet' href='/website_doc/static/src/css/website_doc.css'/>
|
||||
<script type="text/javascript" src="/website_doc/static/src/js/website_doc.js"/>
|
||||
</t>
|
||||
<div class="container mt16">
|
||||
<div class="col-md-3 css_noprint bs-sidebar" id="left_column">
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<t t-foreach="documentaion_toc" t-as="toc">
|
||||
<li t-att-class="content == toc.name and 'active' or ''">
|
||||
<a t-attf-href="/doc?{{ keep_query(content=toc.name) }}">
|
||||
<t t-esc="toc.name"/>
|
||||
<!--span class="badge pull-right" t-if="toc.post_ids"><t t-esc="toc.post_ids"/></span-->
|
||||
</a>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-9" t-if="toc_id">
|
||||
<div>
|
||||
<h2 t-esc="toc_id.name" class="text-center"/>
|
||||
</div>
|
||||
<div t-foreach="toc_id.post_ids" t-as="post">
|
||||
<h2><a class="faq-question"><t t-esc="post.name"/></a></h2>
|
||||
<div t-if="post.pertinent_answer_id">
|
||||
<p><t t-raw="post.pertinent_answer_id.content"/></p>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<a class="" t-attf-href="/forum/#{ slug(post.forum_id) }/question/#{ slug(post) }">Read More About This..</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oe_structure"/>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<!--TOC ON FORUM POST-->
|
||||
<template id="forum_question_right_column" inherit_id="website_forum.header" name="Table of Content">
|
||||
<xpath expr="//script[@src='/website_forum/static/src/js/website_forum.js']" position="after">
|
||||
<script type="text/javascript" src="/website_doc/static/src/js/website_doc.js"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='about_forum']" position="before">
|
||||
<div t-if="header.get('question_data')">
|
||||
<span type="hidden" t-attf-value="#{question.id}" id="question"/>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading" id="about_forum">
|
||||
<h3 class="panel-title">Documentation</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<select class="form-control post_toc" t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/toc" name="Table of Content">
|
||||
<option value="">Table of Content...</option>
|
||||
<t t-foreach="documentaion_toc or []" t-as="toc">
|
||||
<option t-att-value="toc.id" t-att-selected="toc.id == question.toc_id.id"><t t-esc="toc.name"/></option>
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -170,6 +170,11 @@ class WebsiteForum(http.Controller):
|
|||
}, context=context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), new_question_id))
|
||||
|
||||
def prepare_question_values(self, forum=None, **kwargs):
|
||||
'''Overwrite value in website_doc'''
|
||||
values = self._prepare_forum_values(forum=forum, searches=kwargs)
|
||||
return values
|
||||
|
||||
@http.route(['/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
||||
def question(self, forum, question, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
@ -177,7 +182,7 @@ class WebsiteForum(http.Controller):
|
|||
request.registry['forum.post'].set_viewed(cr, SUPERUSER_ID, [question.id], context=context)
|
||||
|
||||
filters = 'question'
|
||||
values = self._prepare_forum_values(forum=forum, searches=post)
|
||||
values = self.prepare_question_values(forum=forum, kwargs=post)
|
||||
values.update({
|
||||
'question': question,
|
||||
'header': {'question_data': True},
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
<div class="col-sm-3" id="right-column">
|
||||
<a t-if="not header.get('ask_hide')" class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{slug(forum)}/ask">Ask a Question</a>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-heading" id="about_forum">
|
||||
<h3 class="panel-title">About This Forum</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
|
|
Loading…
Reference in New Issue