mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-23 17:08:46 -06:00
use new API
This commit is contained in:
parent
8d97a7ba01
commit
3b1d14196a
@ -18,8 +18,5 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import (
|
||||
document_page,
|
||||
wizard
|
||||
)
|
||||
from . import document_page
|
||||
from . import wizard
|
||||
|
@ -38,8 +38,12 @@ Web pages
|
||||
'security/document_page_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'demo': ['document_page_demo.xml'],
|
||||
'test': ['test/document_page_test00.yml'],
|
||||
'demo': [
|
||||
'document_page_demo.xml'
|
||||
],
|
||||
'test': [
|
||||
'test/document_page_test00.yml'
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'images': [],
|
||||
|
@ -18,67 +18,104 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp import models, fields, _
|
||||
from openerp import exceptions
|
||||
# , fields, api, _
|
||||
import difflib
|
||||
|
||||
|
||||
class document_page(osv.osv):
|
||||
class document_page(models.Model):
|
||||
_name = "document.page"
|
||||
_description = "Document Page"
|
||||
_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 = []
|
||||
for subpage in page.child_ids:
|
||||
index += ["<li>" + self._get_page_index(cr, uid, subpage) +
|
||||
index += ["<li>" + self._get_page_index(subpage) +
|
||||
"</li>"]
|
||||
r = ''
|
||||
if link:
|
||||
r = '<a href="#id=%s">%s</a>' % (page.id, page.name)
|
||||
|
||||
if index:
|
||||
r += "<ul>" + "".join(index) + "</ul>"
|
||||
return r
|
||||
|
||||
def _get_display_content(self, cr, uid, ids, name, args, context=None):
|
||||
res = {}
|
||||
for page in self.browse(cr, uid, ids, context=context):
|
||||
def _get_display_content(self):
|
||||
for page in self:
|
||||
if page.type == "category":
|
||||
content = self._get_page_index(cr, uid, page, link=False)
|
||||
display_content = self._get_page_index(page, link=False)
|
||||
else:
|
||||
content = page.content
|
||||
res[page.id] = 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',
|
||||
}
|
||||
display_content = page.content
|
||||
page.display_content = display_content
|
||||
|
||||
def onchange_parent_id(self, cr, uid, ids, parent_id, content,
|
||||
context=None):
|
||||
@ -112,19 +149,17 @@ class document_page(osv.osv):
|
||||
return result
|
||||
|
||||
|
||||
class document_page_history(osv.osv):
|
||||
class document_page_history(models.Model):
|
||||
_name = "document.page.history"
|
||||
_description = "Document Page History"
|
||||
_order = 'id DESC'
|
||||
_rec_name = "create_date"
|
||||
|
||||
_columns = {
|
||||
'page_id': fields.many2one('document.page', 'Page'),
|
||||
'summary': fields.char('Summary', size=256, select=True),
|
||||
'content': fields.text("Content"),
|
||||
'create_date': fields.datetime("Date"),
|
||||
'create_uid': fields.many2one('res.users', "Modified By"),
|
||||
}
|
||||
page_id = fields.Many2one('document.page', 'Page')
|
||||
summary = fields.Char('Summary', size=256, select=True)
|
||||
content = fields.Text("Content")
|
||||
create_date = fields.Datetime("Date")
|
||||
create_uid = fields.Many2one('res.users', "Modified By")
|
||||
|
||||
def getDiff(self, cr, uid, v1, v2, context=None):
|
||||
history_pool = self.pool.get('document.page.history')
|
||||
@ -136,8 +171,9 @@ class document_page_history(osv.osv):
|
||||
if text2:
|
||||
line2 = text2.splitlines(1)
|
||||
if (not line1 and not line2) or (line1 == line2):
|
||||
raise osv.except_osv(_('Warning!'),
|
||||
_('There are no changes in revisions.'))
|
||||
raise exceptions.Warning(
|
||||
_('There are no changes in revisions.')
|
||||
)
|
||||
diff = difflib.HtmlDiff()
|
||||
return diff.make_table(line1, line2, "Revision-%s" % (v1),
|
||||
"Revision-%s" % (v2), context=True)
|
||||
|
@ -1,8 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<menuitem name="Knowledge" id="knowledge.menu_document"/>
|
||||
<menuitem name="Pages" id="menu_wiki" parent="knowledge.menu_document" sequence="20" />
|
||||
<menuitem name="Knowledge"
|
||||
id="knowledge.menu_document" />
|
||||
|
||||
<menuitem name="Pages"
|
||||
id="menu_wiki"
|
||||
parent="knowledge.menu_document"
|
||||
sequence="20" />
|
||||
|
||||
<!-- wiki tree view -->
|
||||
<record id="view_wiki_tree_children" model="ir.ui.view">
|
||||
@ -18,6 +23,7 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- wiki list view -->
|
||||
<record id="view_wiki_tree" model="ir.ui.view">
|
||||
<field name="name">document.page.list</field>
|
||||
@ -32,6 +38,7 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- wiki Form view -->
|
||||
<record id="view_wiki_form" model="ir.ui.view">
|
||||
<field name="name">document.page.form</field>
|
||||
@ -50,34 +57,52 @@
|
||||
<field name="menu_id" groups="base.group_no_one"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
<div class="oe_edit_only" attrs="{'invisible':[('type','=','content')]}">
|
||||
<label for="content" string="Template"/>
|
||||
that will be used as a content template for all new page of this category.
|
||||
</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">
|
||||
<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>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- page Search view -->
|
||||
<record id="view_wiki_filter" model="ir.ui.view">
|
||||
<field name="name">document.page.search</field>
|
||||
<field name="model">document.page</field>
|
||||
<field name="arch" type="xml">
|
||||
<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="parent_id"/>
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Document Type" domain="[]" context="{'group_by':'parent_id'}"/>
|
||||
<filter string="Author" domain="[]" context="{'group_by':'create_uid'}"/>
|
||||
<filter string="Last Contributor" domain="[]" context="{'group_by':'write_uid'}"/>
|
||||
<filter string="Document Type"
|
||||
domain="[]"
|
||||
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>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- page action -->
|
||||
<record id="action_page" model="ir.actions.act_window">
|
||||
<field name="name">Pages</field>
|
||||
@ -94,7 +119,13 @@
|
||||
</p>
|
||||
</field>
|
||||
</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">
|
||||
<field name="name">Category</field>
|
||||
<field name="res_model">document.page</field>
|
||||
@ -105,7 +136,11 @@
|
||||
<field name="view_id" ref="view_wiki_tree"/>
|
||||
<field name="search_view_id" ref="view_wiki_filter"/>
|
||||
</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 -->
|
||||
<record model="ir.ui.view" id="view_wiki_history_tree">
|
||||
@ -134,6 +169,7 @@
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- History Action -->
|
||||
<record model="ir.actions.act_window" id="action_history">
|
||||
<field name="name">Page history</field>
|
||||
@ -141,7 +177,14 @@
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</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
|
||||
id="action_related_page_history"
|
||||
context="{'search_default_page_id': [active_id], 'default_page_id': active_id}"
|
||||
@ -149,7 +192,8 @@
|
||||
name="Page History"
|
||||
res_model="document.page.history"
|
||||
src_model="document.page"/>
|
||||
<act_window
|
||||
|
||||
<act_window
|
||||
id="action_related_page_create_menu"
|
||||
name="Create Menu"
|
||||
res_model="document.page.create.menu"
|
||||
|
@ -18,8 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import document_page_create_menu
|
||||
import document_page_show_diff
|
||||
from . import document_page_create_menu
|
||||
from . import document_page_show_diff
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
@ -12,15 +12,23 @@
|
||||
<field name="menu_parent_id" />
|
||||
</group>
|
||||
<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
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
<button string="Cancel"
|
||||
class="oe_link"
|
||||
special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- 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="type">ir.actions.act_window</field>
|
||||
<field name="res_model">document.page.create.menu</field>
|
||||
|
Loading…
Reference in New Issue
Block a user