[IMP] Some improvements in code

bzr revid: fp@tinyerp.com-20140421084749-uygi1h2vwpc1wk9x
This commit is contained in:
Fabien Pinckaers 2014-04-21 10:47:49 +02:00
parent f5645469b6
commit 2d601a4194
26 changed files with 306 additions and 229 deletions

View File

@ -1,58 +0,0 @@
# -*- 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', '/doc/<model("documentation.toc"):toc>'], type='http', auth="public", website=True, multilang=True)
def documentation(self, toc='', **kwargs):
cr, uid, context, toc_id = request.cr, request.uid, request.context, False
TOC = request.registry['documentation.toc']
obj_ids = TOC.search(cr, uid, [('parent_id', '=', False)], context=context)
toc_ids = TOC.browse(cr, uid, obj_ids, context=context)
value = {
'documentaion_toc': toc_ids,
'topic': toc or toc_ids[0],
}
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" % 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, [('child_ids', '=', False)], 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/<model("forum.forum"):forum>/question/<model("forum.post"):post>/toc', type='http', auth="user", multilang=True, website=True)
def post_toc(self, forum, post, **kwargs):
toc_id = int(kwargs.get('content')) if kwargs.get('content') else False
request.registry['forum.post'].write(request.cr, request.uid, [post.id], {'toc_id': toc_id}, context=request.context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))

View File

@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
import doc
import res_users

View File

@ -1,64 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- DOCUMENTATION TOC VIEWS -->
<record id="view_documentation_toc_hierarchy" model="ir.ui.view">
<field name="name">documentation.toc.list</field>
<field name="model">documentation.toc</field>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<tree string="Documentation TOC">
<field name="name"/>
</tree>
</field>
</record>
<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"/>
<field name="parent_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_documentation_toc" model="ir.actions.act_window">
<field name="name">Documentation</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" groups="website_doc.group_documentaion_moderator" name="Documentation" action="action_documentation_toc" sequence="20"/>
<record id="action_documentation_toc_hierarchy" model="ir.actions.act_window">
<field name="name">Documentation Hierarchy</field>
<field name="res_model">documentation.toc</field>
<field name="view_type">tree</field>
<field name="view_mode">tree</field>
<field name="domain">[('parent_id','=',False)]</field>
<field name="view_id" ref="view_documentation_toc_hierarchy"/>
</record>
<menuitem id="menu_documentation_hierarchy" parent="website_forum.menu_website_forum" groups="website_doc.group_documentaion_moderator" name="Documentation Hierarchy" action="action_documentation_toc_hierarchy" sequence="25"/>
</data>
</openerp>

View File

@ -1,100 +0,0 @@
<?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 document">
<div class="col-md-3 mt32 css_noprint bs-sidebar menu-tree">
<t t-call="website_doc.side_panel"><t t-set="documentation" t-value="documentaion_toc"/></t>
</div>
<div class="col-md-9 mt32 document_page">
<strong><h2 t-esc="topic.name" class="text-center"/></strong>
<div t-foreach="topic.post_ids" t-as="post">
<h2><p class="faq-question" t-esc="post.name"/></h2>
<div t-if="post.pertinent_answer_id">
<p><t t-raw="post.pertinent_answer_id.content"/></p>
</div>
<div class="pull-right">
<a 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>
<!--MENU LIST-->
<template id="side_panel">
<ul class="nav nav-pills nav-stacked">
<t t-foreach="documentation" t-as="toc">
<li t-attf-class="tree_toggler #{ topic==toc and 'active' or ''}">
<a t-attf-href="/doc/#{ slug(toc) }" t-if="not toc.child_ids">
<t t-esc="toc.name"/>
</a>
<a t-attf-href="" t-if="toc.child_ids">
<t t-esc="toc.name"/>
</a>
<t t-if="toc.child_ids">
<t t-call="website_doc.side_panel"><t t-set="documentation" t-value="toc.child_ids"/></t>
</t>
</li>
</t>
</ul>
</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')" groups="website_doc.group_documentaion_moderator">
<div class="panel panel-default">
<div class="panel-heading" id="about_forum">
<h3 class="panel-title">Documentation</h3>
</div>
<div class="panel-body">
<form t-attf-action="/forum/#{ slug(forum) }/question/#{ slug(question) }/toc" role="form" method="post">
<div class="input-group navbar-right">
<select class="form-control" name="content">
<option value=""></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>
<span class="input-group-btn">
<button class="btn btn-primary ">save</button>
</span>
</div>
</form>
</div>
</div>
</div>
</xpath>
</template>
</data>
</openerp>

View File

@ -39,9 +39,6 @@ Documentation based on question and pertinent answers of Forum
'views/doc.xml',
'views/website_doc.xml',
],
'qweb': [
'static/src/xml/*.xml'
],
'demo': [
'data/doc_demo.xml',
],

View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.models.website import slug
# from openerp.addons.website.controllers.main import Website as controllers
# import werkzeug.urls
# from datetime import datetime
# import simplejson
# from openerp import tools
# from openerp import SUPERUSER_ID
# from openerp.addons.web.controllers.main import login_redirect
# from openerp.addons.website_forum.controllers.main import WebsiteForum
#
# controllers = controllers()
class WebsiteDoc(http.Controller):
@http.route(['/forum/how-to', '/forum/how-to/<model("documentation.toc"):toc>'], type='http', auth="public", website=True, multilang=True)
def toc(self, toc=None, **kwargs):
cr, uid, context, toc_id = request.cr, request.uid, request.context, False
if toc:
toc = [toc]
else:
toc_obj = request.registry['forum.documentation.toc']
obj_ids = toc_obj.search(cr, uid, [('parent_id', '=', False)], context=context)
toc = toc_obj.browse(cr, uid, obj_ids, context=context)
value = {
'sections': toc,
}
return request.website.render("website_forum_doc.documentation", value)
@http.route(['/forum/how-to/<model("documentation.toc"):toc>/<model("forum.post"):post>'], type='http', auth="public", website=True, multilang=True)
def how_to(self, toc, post, **kwargs):
assert post.documentation_toc_id.id == toc.id, "Wrong post, should implement a redirect here"
value = {
'section': toc,
'post': post
}
return request.website.render("website_forum_doc.documentation.post", value)
#---------------------
# 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, [('child_ids', '=', False)], 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/<model("forum.forum"):forum>/question/<model("forum.post"):post>/toc', type='http', auth="user", multilang=True, website=True)
# def post_toc(self, forum, post, **kwargs):
# toc_id = int(kwargs.get('content')) if kwargs.get('content') else False
# request.registry['forum.post'].write(request.cr, request.uid, [post.id], {'toc_id': toc_id}, context=request.context)
# return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))

View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
import documentation

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import openerp
from openerp.osv import osv, fields
class Documentation(osv.Model):
_name = 'forum.documentation.toc'
_description = 'Documentation ToC'
_inherit = ['website.seo.metadata']
_order = "parent_left"
_parent_order = "sequence, name"
_parent_store = True
_columns = {
'sequence': fields.integer('Sequence'),
'name': fields.char('Name', required=True, translate=True),
'parent_id': fields.many2one('documentation.toc', 'Parent Table Of Content'),
'child_ids': fields.one2many('documentation.toc', 'parent_id', 'Children Table Of Content'),
'parent_left': fields.integer('Left Parent', select=True),
'parent_right': fields.integer('Right Parent', select=True),
'post_ids': fields.one2many('forum.post', 'documentation_toc_id', 'Posts'),
}
_constraints = [
(osv.osv._check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id'])
]
class DocumentationStage(osv.Model):
_name = 'forum.documentation.stage'
_description = 'Post Stage'
_order = 'sequence'
_columns = {
'sequence': fields.integer('Sequence'),
'name': fields.char('Stage Name', required=True, translate=True),
}
class Post(osv.Model):
_inherit = 'forum.post'
_columns = {
'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC'),
'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage')
}

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -0,0 +1,104 @@
<?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" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="parent_id"/>
</tree>
</field>
</record>
<record id="action_documentation_toc" model="ir.actions.act_window">
<field name="name">Documentation</field>
<field name="res_model">documentation.toc</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>
<menuitem id="menu_documentation"
parent="website_forum.menu_website_forum" groups="base.group_user"
name="Documentation ToC" action="action_documentation_toc" sequence="20"/>
<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" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="parent_id"/>
</tree>
</field>
</record>
<record id="action_documentation_toc" model="ir.actions.act_window">
<field name="name">Documentation</field>
<field name="res_model">documentation.toc</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>
<menuitem id="menu_documentation"
parent="website_forum.menu_website_forum" groups="base.group_user"
name="Documentation ToC" action="action_documentation_toc" sequence="20"/>
<!-- Project Task Kanban View -->
<record model="ir.ui.view" id="view_forum_post_kanban">
<field name="name">forum.post.kanban</field>
<field name="model">forum.post</field>
<field name="arch" type="xml">
<kanban default_group_by="documentation_stage_id" >
<field name="stage_id"/>
<field name="create_uid"/>
<field name="color"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click">
<div class="oe_dropdown_toggle oe_dropdown_kanban" groups="base.group_user">
<span class="oe_e">í</span>
<ul class="oe_dropdown_menu">
<li t-if="widget.view.is_action_enabled('edit')"><a type="edit">Edit...</a></li>
<li t-if="widget.view.is_action_enabled('delete')"><a type="delete">Delete</a></li>
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
</ul>
</div>
<div class="oe_kanban_content">
<div><b><field name="name"/></b></div>
<div>
<field name="documentation_toc_id"/>
</div>
<div class="oe_kanban_bottom_right">
<img t-att-src="kanban_image('res.users', 'image_small', record.create_id.raw_value)" t-att-title="record.create_uid.value" width="24" height="24" class="oe_kanban_avatar"/>
</div>
</div>
<div class="oe_clear"></div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
<record id="action_forum_doc_post" model="ir.actions.act_window">
<field name="name">Documentation Posts</field>
<field name="res_model">forum.post</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="domain">[('documentation_toc_id','&lt;&gt;', False)]</field>
</record>
<menuitem id="menu_forum_doc_posts"
parent="menu_website_forum" name="Documentation Posts"
action="action_forum_doc_post" sequence="25"/>
</data>
</openerp>

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- 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="/forum/how-to">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_forum_doc/static/src/css/website_doc.css'/>
<script type="text/javascript" src="/website_forum_doc/static/src/js/website_doc.js"/>
</t>
<div class="container mt16 document">
<div class="col-md-3 mt32 css_noprint bs-sidebar menu-tree">
<t t-call="website_doc.side_panel"><t t-set="documentation" t-value="documentaion_toc"/></t>
</div>
<div class="col-md-9 mt32 document_page">
<strong><h2 t-esc="topic.name" class="text-center"/></strong>
<div t-foreach="topic.post_ids" t-as="post">
<h2><p class="faq-question" t-esc="post.name"/></h2>
<div t-if="post.pertinent_answer_id">
<p><t t-raw="post.pertinent_answer_id.content"/></p>
</div>
<div class="pull-right">
<a 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>
<!--MENU LIST-->
<template id="side_panel">
<ul class="nav nav-pills nav-stacked">
<t t-foreach="documentation" t-as="toc">
<li t-attf-class="tree_toggler #{ topic==toc and 'active' or ''}">
<a t-attf-href="/forum/how-to/#{ slug(toc) }" t-if="not toc.child_ids">
<t t-esc="toc.name"/>
</a>
<a t-attf-href="" t-if="toc.child_ids">
<t t-esc="toc.name"/>
</a>
<t t-if="toc.child_ids">
<t t-call="website_doc.side_panel"><t t-set="documentation" t-value="toc.child_ids"/></t>
</t>
</li>
</t>
</ul>
</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')" groups="website_doc.group_documentaion_moderator">
<div class="panel panel-default">
<div class="panel-heading" id="about_forum">
<h3 class="panel-title">Documentation</h3>
</div>
<div class="panel-body">
<form t-attf-action="/forum/#{ slug(forum) }/question/#{ slug(question) }/toc" role="form" method="post">
<div class="input-group navbar-right">
<select class="form-control" name="content">
<option value=""></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>
<span class="input-group-btn">
<button class="btn btn-primary ">save</button>
</span>
</div>
</form>
</div>
</div>
</div>
</xpath>
</template>
</data>
</openerp>