use new API

This commit is contained in:
Giorgio Borelli 2014-11-11 13:25:05 +01:00
parent 8d97a7ba01
commit 3b1d14196a
6 changed files with 165 additions and 77 deletions

View File

@ -18,8 +18,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from . import document_page
from . import ( from . import wizard
document_page,
wizard
)

View File

@ -38,8 +38,12 @@ Web pages
'security/document_page_security.xml', 'security/document_page_security.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
'demo': ['document_page_demo.xml'], 'demo': [
'test': ['test/document_page_test00.yml'], 'document_page_demo.xml'
],
'test': [
'test/document_page_test00.yml'
],
'installable': True, 'installable': True,
'auto_install': False, 'auto_install': False,
'images': [], 'images': [],

View File

@ -18,67 +18,104 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp import models, fields, _
from openerp.osv import fields, osv from openerp import exceptions
from openerp.tools.translate import _ # , fields, api, _
import difflib import difflib
class document_page(osv.osv): class document_page(models.Model):
_name = "document.page" _name = "document.page"
_description = "Document Page" _description = "Document Page"
_order = 'name' _order = 'name'
def _get_page_index(self, cr, uid, page, link=True): name = fields.Char('Title', required=True)
type = fields.Selection(
[('content', 'Content'), ('category', 'Category')],
'Type',
help="Page type",
default="content"
)
parent_id = fields.Many2one(
'document.page',
'Category',
domain=[('type', '=', 'category')]
)
child_ids = fields.One2many(
'document.page',
'parent_id',
'Children'
)
content = fields.Text(
"Content"
)
display_content = fields.Text(
string='Displayed Content',
compute='_get_display_content'
)
history_ids = fields.One2many(
'document.page.history',
'page_id',
'History'
)
menu_id = fields.Many2one(
'ir.ui.menu',
"Menu",
readonly=True
)
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(
"Modification Date",
select=True,
readonly=True)
write_uid = fields.Many2one(
'res.users',
"Last Contributor",
select=True,
readonly=True
)
def _get_page_index(self, page, link=True):
index = [] index = []
for subpage in page.child_ids: for subpage in page.child_ids:
index += ["<li>" + self._get_page_index(cr, uid, subpage) + index += ["<li>" + self._get_page_index(subpage) +
"</li>"] "</li>"]
r = '' r = ''
if link: if link:
r = '<a href="#id=%s">%s</a>' % (page.id, page.name) r = '<a href="#id=%s">%s</a>' % (page.id, page.name)
if index: if index:
r += "<ul>" + "".join(index) + "</ul>" r += "<ul>" + "".join(index) + "</ul>"
return r return r
def _get_display_content(self, cr, uid, ids, name, args, context=None): def _get_display_content(self):
res = {} for page in self:
for page in self.browse(cr, uid, ids, context=context):
if page.type == "category": if page.type == "category":
content = self._get_page_index(cr, uid, page, link=False) display_content = self._get_page_index(page, link=False)
else: else:
content = page.content display_content = page.content
res[page.id] = content page.display_content = display_content
return res
_columns = {
'name': fields.char('Title', required=True),
'type': fields.selection([('content', 'Content'),
('category', 'Category')],
'Type', help="Page type"),
'parent_id': fields.many2one('document.page', 'Category',
domain=[('type', '=', 'category')]),
'child_ids': fields.one2many('document.page', 'parent_id', 'Children'),
'content': fields.text("Content"),
'display_content': fields.function(_get_display_content,
string='Displayed Content',
type='text'),
'history_ids': fields.one2many('document.page.history', 'page_id',
'History'),
'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
'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("Modification Date", select=True,
readonly=True),
'write_uid': fields.many2one('res.users', "Last Contributor",
select=True, readonly=True),
}
_defaults = {
'type': 'content',
}
def onchange_parent_id(self, cr, uid, ids, parent_id, content, def onchange_parent_id(self, cr, uid, ids, parent_id, content,
context=None): context=None):
@ -112,19 +149,17 @@ class document_page(osv.osv):
return result return result
class document_page_history(osv.osv): class document_page_history(models.Model):
_name = "document.page.history" _name = "document.page.history"
_description = "Document Page History" _description = "Document Page History"
_order = 'id DESC' _order = 'id DESC'
_rec_name = "create_date" _rec_name = "create_date"
_columns = { page_id = fields.Many2one('document.page', 'Page')
'page_id': fields.many2one('document.page', 'Page'), summary = fields.Char('Summary', size=256, select=True)
'summary': fields.char('Summary', size=256, select=True), content = fields.Text("Content")
'content': fields.text("Content"), create_date = fields.Datetime("Date")
'create_date': fields.datetime("Date"), create_uid = fields.Many2one('res.users', "Modified By")
'create_uid': fields.many2one('res.users', "Modified By"),
}
def getDiff(self, cr, uid, v1, v2, context=None): def getDiff(self, cr, uid, v1, v2, context=None):
history_pool = self.pool.get('document.page.history') history_pool = self.pool.get('document.page.history')
@ -136,8 +171,9 @@ class document_page_history(osv.osv):
if text2: if text2:
line2 = text2.splitlines(1) line2 = text2.splitlines(1)
if (not line1 and not line2) or (line1 == line2): if (not line1 and not line2) or (line1 == line2):
raise osv.except_osv(_('Warning!'), raise exceptions.Warning(
_('There are no changes in revisions.')) _('There are no changes in revisions.')
)
diff = difflib.HtmlDiff() diff = difflib.HtmlDiff()
return diff.make_table(line1, line2, "Revision-%s" % (v1), return diff.make_table(line1, line2, "Revision-%s" % (v1),
"Revision-%s" % (v2), context=True) "Revision-%s" % (v2), context=True)

View File

@ -1,8 +1,13 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<openerp> <openerp>
<data> <data>
<menuitem name="Knowledge" id="knowledge.menu_document"/> <menuitem name="Knowledge"
<menuitem name="Pages" id="menu_wiki" parent="knowledge.menu_document" sequence="20" /> id="knowledge.menu_document" />
<menuitem name="Pages"
id="menu_wiki"
parent="knowledge.menu_document"
sequence="20" />
<!-- wiki tree view --> <!-- wiki tree view -->
<record id="view_wiki_tree_children" model="ir.ui.view"> <record id="view_wiki_tree_children" model="ir.ui.view">
@ -18,6 +23,7 @@
</tree> </tree>
</field> </field>
</record> </record>
<!-- wiki list view --> <!-- wiki list view -->
<record id="view_wiki_tree" model="ir.ui.view"> <record id="view_wiki_tree" model="ir.ui.view">
<field name="name">document.page.list</field> <field name="name">document.page.list</field>
@ -32,6 +38,7 @@
</tree> </tree>
</field> </field>
</record> </record>
<!-- wiki Form view --> <!-- wiki Form view -->
<record id="view_wiki_form" model="ir.ui.view"> <record id="view_wiki_form" model="ir.ui.view">
<field name="name">document.page.form</field> <field name="name">document.page.form</field>
@ -50,34 +57,52 @@
<field name="menu_id" groups="base.group_no_one"/> <field name="menu_id" groups="base.group_no_one"/>
</group> </group>
</group> </group>
<div class="oe_edit_only" attrs="{'invisible':[('type','=','content')]}"> <div class="oe_edit_only" attrs="{'invisible':[('type','=','content')]}">
<label for="content" string="Template"/> <label for="content" string="Template"/>
that will be used as a content template for all new page of this category. that will be used as a content template for all new page of this category.
</div> </div>
<field name="content" placeholder="e.g. Once upon a time..." class="oe_edit_only" widget="html"/> <field name="content"
placeholder="e.g. Once upon a time..."
class="oe_edit_only"
widget="html" />
<div class="oe_document_page"> <div class="oe_document_page">
<field name="display_content" widget="html" class="oe_view_only" options='{"safe": True}'/> <field name="display_content"
widget="html"
class="oe_view_only"
options='{"safe": True}' />
</div> </div>
</form> </form>
</field> </field>
</record> </record>
<!-- page Search view --> <!-- page Search view -->
<record id="view_wiki_filter" model="ir.ui.view"> <record id="view_wiki_filter" model="ir.ui.view">
<field name="name">document.page.search</field> <field name="name">document.page.search</field>
<field name="model">document.page</field> <field name="model">document.page</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Document Page"> <search string="Document Page">
<field name="name" string="Content" filter_domain="['|', ('name','ilike',self), ('content','ilike',self)]"/> <field name="name"
string="Content"
filter_domain="['|', ('name','ilike',self), ('content','ilike',self)]"/>
<field name="write_uid"/> <field name="write_uid"/>
<field name="parent_id"/> <field name="parent_id"/>
<group expand="0" string="Group By..."> <group expand="0" string="Group By...">
<filter string="Document Type" domain="[]" context="{'group_by':'parent_id'}"/> <filter string="Document Type"
<filter string="Author" domain="[]" context="{'group_by':'create_uid'}"/> domain="[]"
<filter string="Last Contributor" domain="[]" context="{'group_by':'write_uid'}"/> context="{'group_by':'parent_id'}" />
<filter string="Author"
domain="[]"
context="{'group_by':'create_uid'}" />
<filter string="Last Contributor"
domain="[]"
context="{'group_by':'write_uid'}" />
</group> </group>
</search> </search>
</field> </field>
</record> </record>
<!-- page action --> <!-- page action -->
<record id="action_page" model="ir.actions.act_window"> <record id="action_page" model="ir.actions.act_window">
<field name="name">Pages</field> <field name="name">Pages</field>
@ -94,7 +119,13 @@
</p> </p>
</field> </field>
</record> </record>
<menuitem id="menu_page" parent="menu_wiki" name="Pages" action="action_page" sequence="10"/>
<menuitem id="menu_page"
parent="menu_wiki"
name="Pages"
action="action_page"
sequence="10" />
<record id="action_category" model="ir.actions.act_window"> <record id="action_category" model="ir.actions.act_window">
<field name="name">Category</field> <field name="name">Category</field>
<field name="res_model">document.page</field> <field name="res_model">document.page</field>
@ -105,7 +136,11 @@
<field name="view_id" ref="view_wiki_tree"/> <field name="view_id" ref="view_wiki_tree"/>
<field name="search_view_id" ref="view_wiki_filter"/> <field name="search_view_id" ref="view_wiki_filter"/>
</record> </record>
<menuitem id="menu_category" parent="menu_wiki" name="Categories" action="action_category" sequence="20"/> <menuitem id="menu_category"
parent="menu_wiki"
name="Categories"
action="action_category"
sequence="20"/>
<!-- History Tree view --> <!-- History Tree view -->
<record model="ir.ui.view" id="view_wiki_history_tree"> <record model="ir.ui.view" id="view_wiki_history_tree">
@ -134,6 +169,7 @@
</form> </form>
</field> </field>
</record> </record>
<!-- History Action --> <!-- History Action -->
<record model="ir.actions.act_window" id="action_history"> <record model="ir.actions.act_window" id="action_history">
<field name="name">Page history</field> <field name="name">Page history</field>
@ -141,7 +177,14 @@
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
</record> </record>
<menuitem id="menu_page_history" parent="menu_wiki" name="Pages history" action="action_history" sequence="30" groups="base.group_no_one"/>
<menuitem id="menu_page_history"
parent="menu_wiki"
name="Pages history"
action="action_history"
sequence="30"
groups="base.group_no_one" />
<act_window <act_window
id="action_related_page_history" id="action_related_page_history"
context="{'search_default_page_id': [active_id], 'default_page_id': active_id}" context="{'search_default_page_id': [active_id], 'default_page_id': active_id}"
@ -149,7 +192,8 @@
name="Page History" name="Page History"
res_model="document.page.history" res_model="document.page.history"
src_model="document.page"/> src_model="document.page"/>
<act_window
<act_window
id="action_related_page_create_menu" id="action_related_page_create_menu"
name="Create Menu" name="Create Menu"
res_model="document.page.create.menu" res_model="document.page.create.menu"

View File

@ -18,8 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from . import document_page_create_menu
import document_page_create_menu from . import document_page_show_diff
import document_page_show_diff
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -12,15 +12,23 @@
<field name="menu_parent_id" /> <field name="menu_parent_id" />
</group> </group>
<footer> <footer>
<button name="document_page_menu_create" string="Create Menu" type="object" class="oe_highlight"/> <button name="document_page_menu_create"
string="Create Menu"
type="object"
class="oe_highlight" />
or or
<button string="Cancel" class="oe_link" special="cancel" /> <button string="Cancel"
class="oe_link"
special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
<!-- Create Menu Action --> <!-- Create Menu Action -->
<record id="action_wiki_create_menu" model="ir.actions.act_window"> <record id="action_wiki_create_menu"
model="ir.actions.act_window">
<field name="name">Create Menu</field> <field name="name">Create Menu</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="res_model">document.page.create.menu</field> <field name="res_model">document.page.create.menu</field>