mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-14 01:41:26 -06:00
[IMP] document_page: black, isort
This commit is contained in:
parent
6aa4dece1f
commit
4cf81af527
@ -3,36 +3,31 @@
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Document Page',
|
"name": "Document Page",
|
||||||
'version': '12.0.1.1.0',
|
"version": "12.0.1.1.0",
|
||||||
'category': 'Knowledge Management',
|
"category": "Knowledge Management",
|
||||||
'author': 'OpenERP SA, Odoo Community Association (OCA)',
|
"author": "OpenERP SA, Odoo Community Association (OCA)",
|
||||||
'images': [
|
"images": [
|
||||||
'images/category_list.png',
|
"images/category_list.png",
|
||||||
'images/create_category.png',
|
"images/create_category.png",
|
||||||
'images/page_list.png',
|
"images/page_list.png",
|
||||||
'images/create_page.png',
|
"images/create_page.png",
|
||||||
'images/customer_invoice.jpeg',
|
"images/customer_invoice.jpeg",
|
||||||
'images/page_history.png',
|
"images/page_history.png",
|
||||||
],
|
],
|
||||||
'website': 'https://github.com/OCA/knowledge',
|
"website": "https://github.com/OCA/knowledge",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'depends': [
|
"depends": ["mail", "knowledge"],
|
||||||
'mail',
|
"data": [
|
||||||
'knowledge',
|
"security/document_page_security.xml",
|
||||||
],
|
"security/ir.model.access.csv",
|
||||||
'data': [
|
"wizard/document_page_create_menu.xml",
|
||||||
'security/document_page_security.xml',
|
"wizard/document_page_show_diff.xml",
|
||||||
'security/ir.model.access.csv',
|
"views/document_page.xml",
|
||||||
'wizard/document_page_create_menu.xml',
|
"views/document_page_category.xml",
|
||||||
'wizard/document_page_show_diff.xml',
|
"views/document_page_history.xml",
|
||||||
'views/document_page.xml',
|
"views/document_page_assets.xml",
|
||||||
'views/document_page_category.xml',
|
"views/report_document_page.xml",
|
||||||
'views/document_page_history.xml',
|
|
||||||
'views/document_page_assets.xml',
|
|
||||||
'views/report_document_page.xml',
|
|
||||||
],
|
|
||||||
'demo': [
|
|
||||||
'demo/document_page.xml'
|
|
||||||
],
|
],
|
||||||
|
"demo": ["demo/document_page.xml"],
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
@ -9,48 +9,42 @@ class DocumentPage(models.Model):
|
|||||||
"""This class is use to manage Document."""
|
"""This class is use to manage Document."""
|
||||||
|
|
||||||
_name = "document.page"
|
_name = "document.page"
|
||||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
_inherit = ["mail.thread", "mail.activity.mixin"]
|
||||||
_description = "Document Page"
|
_description = "Document Page"
|
||||||
_order = 'name'
|
_order = "name"
|
||||||
|
|
||||||
name = fields.Char('Title', required=True)
|
name = fields.Char("Title", required=True)
|
||||||
type = fields.Selection(
|
type = fields.Selection(
|
||||||
[('content', 'Content'), ('category', 'Category')],
|
[("content", "Content"), ("category", "Category")],
|
||||||
'Type',
|
"Type",
|
||||||
help="Page type",
|
help="Page type",
|
||||||
default="content"
|
default="content",
|
||||||
)
|
)
|
||||||
active = fields.Boolean(default=True)
|
active = fields.Boolean(default=True)
|
||||||
parent_id = fields.Many2one(
|
parent_id = fields.Many2one(
|
||||||
'document.page',
|
"document.page", "Category", domain=[("type", "=", "category")]
|
||||||
'Category',
|
|
||||||
domain=[('type', '=', 'category')]
|
|
||||||
)
|
|
||||||
child_ids = fields.One2many(
|
|
||||||
'document.page',
|
|
||||||
'parent_id',
|
|
||||||
'Children'
|
|
||||||
)
|
)
|
||||||
|
child_ids = fields.One2many("document.page", "parent_id", "Children")
|
||||||
content = fields.Text(
|
content = fields.Text(
|
||||||
"Content",
|
"Content",
|
||||||
compute='_compute_content',
|
compute="_compute_content",
|
||||||
inverse='_inverse_content',
|
inverse="_inverse_content",
|
||||||
search='_search_content',
|
search="_search_content",
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# no-op computed field
|
# no-op computed field
|
||||||
draft_name = fields.Char(
|
draft_name = fields.Char(
|
||||||
string='Name',
|
string="Name",
|
||||||
help='Name for the changes made',
|
help="Name for the changes made",
|
||||||
compute=lambda x: x,
|
compute=lambda x: x,
|
||||||
inverse=lambda x: x,
|
inverse=lambda x: x,
|
||||||
)
|
)
|
||||||
|
|
||||||
# no-op computed field
|
# no-op computed field
|
||||||
draft_summary = fields.Char(
|
draft_summary = fields.Char(
|
||||||
string='Summary',
|
string="Summary",
|
||||||
help='Describe the changes made',
|
help="Describe the changes made",
|
||||||
compute=lambda x: x,
|
compute=lambda x: x,
|
||||||
inverse=lambda x: x,
|
inverse=lambda x: x,
|
||||||
)
|
)
|
||||||
@ -58,58 +52,54 @@ class DocumentPage(models.Model):
|
|||||||
template = fields.Html(
|
template = fields.Html(
|
||||||
"Template",
|
"Template",
|
||||||
help="Template that will be used as a content template "
|
help="Template that will be used as a content template "
|
||||||
"for all new page of this category.",
|
"for all new page of this category.",
|
||||||
)
|
)
|
||||||
history_head = fields.Many2one(
|
history_head = fields.Many2one(
|
||||||
'document.page.history',
|
"document.page.history",
|
||||||
'HEAD',
|
"HEAD",
|
||||||
compute='_compute_history_head',
|
compute="_compute_history_head",
|
||||||
store=True,
|
store=True,
|
||||||
auto_join=True,
|
auto_join=True,
|
||||||
)
|
)
|
||||||
history_ids = fields.One2many(
|
history_ids = fields.One2many(
|
||||||
'document.page.history',
|
"document.page.history",
|
||||||
'page_id',
|
"page_id",
|
||||||
'History',
|
"History",
|
||||||
order='create_date DESC',
|
order="create_date DESC",
|
||||||
readonly=True,
|
|
||||||
)
|
|
||||||
menu_id = fields.Many2one(
|
|
||||||
'ir.ui.menu',
|
|
||||||
"Menu",
|
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
|
menu_id = fields.Many2one("ir.ui.menu", "Menu", readonly=True)
|
||||||
content_date = fields.Datetime(
|
content_date = fields.Datetime(
|
||||||
'Last Contribution Date',
|
"Last Contribution Date",
|
||||||
related='history_head.create_date',
|
related="history_head.create_date",
|
||||||
store=True,
|
store=True,
|
||||||
index=True,
|
index=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
content_uid = fields.Many2one(
|
content_uid = fields.Many2one(
|
||||||
'res.users',
|
"res.users",
|
||||||
'Last Contributor',
|
"Last Contributor",
|
||||||
related='history_head.create_uid',
|
related="history_head.create_uid",
|
||||||
store=True,
|
store=True,
|
||||||
index=True,
|
index=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
'res.company',
|
"res.company",
|
||||||
'Company',
|
"Company",
|
||||||
help='If set, page is accessible only from this company',
|
help="If set, page is accessible only from this company",
|
||||||
index=True,
|
index=True,
|
||||||
ondelete='cascade',
|
ondelete="cascade",
|
||||||
)
|
)
|
||||||
backend_url = fields.Char(
|
backend_url = fields.Char(
|
||||||
string='Backend URL',
|
string="Backend URL",
|
||||||
help='Use it to link resources univocally',
|
help="Use it to link resources univocally",
|
||||||
compute='_compute_backend_url',
|
compute="_compute_backend_url",
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('menu_id', 'parent_id.menu_id')
|
@api.depends("menu_id", "parent_id.menu_id")
|
||||||
def _compute_backend_url(self):
|
def _compute_backend_url(self):
|
||||||
tmpl = '/web#id={}&model=document.page&view_type=form'
|
tmpl = "/web#id={}&model=document.page&view_type=form"
|
||||||
for rec in self:
|
for rec in self:
|
||||||
url = tmpl.format(rec.id)
|
url = tmpl.format(rec.id)
|
||||||
# retrieve action
|
# retrieve action
|
||||||
@ -119,13 +109,13 @@ class DocumentPage(models.Model):
|
|||||||
action = parent.menu_id.action
|
action = parent.menu_id.action
|
||||||
parent = parent.parent_id
|
parent = parent.parent_id
|
||||||
if action:
|
if action:
|
||||||
url += '&action={}'.format(action.id)
|
url += "&action={}".format(action.id)
|
||||||
rec.backend_url = url
|
rec.backend_url = url
|
||||||
|
|
||||||
@api.constrains('parent_id')
|
@api.constrains("parent_id")
|
||||||
def _check_parent_id(self):
|
def _check_parent_id(self):
|
||||||
if not self._check_recursion():
|
if not self._check_recursion():
|
||||||
raise ValidationError(_('You cannot create recursive categories.'))
|
raise ValidationError(_("You cannot create recursive categories."))
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _get_page_index(self, link=True):
|
def _get_page_index(self, link=True):
|
||||||
@ -134,7 +124,7 @@ class DocumentPage(models.Model):
|
|||||||
index = []
|
index = []
|
||||||
for subpage in self.child_ids:
|
for subpage in self.child_ids:
|
||||||
index += ["<li>" + subpage._get_page_index() + "</li>"]
|
index += ["<li>" + subpage._get_page_index() + "</li>"]
|
||||||
r = ''
|
r = ""
|
||||||
if link:
|
if link:
|
||||||
r = '<a href="{}">{}</a>'.format(self.backend_url, self.name)
|
r = '<a href="{}">{}</a>'.format(self.backend_url, self.name)
|
||||||
if index:
|
if index:
|
||||||
@ -142,35 +132,36 @@ class DocumentPage(models.Model):
|
|||||||
return r
|
return r
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('history_head')
|
@api.depends("history_head")
|
||||||
def _compute_content(self):
|
def _compute_content(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.type == 'category':
|
if rec.type == "category":
|
||||||
rec.content = rec._get_page_index(link=False)
|
rec.content = rec._get_page_index(link=False)
|
||||||
else:
|
else:
|
||||||
if rec.history_head:
|
if rec.history_head:
|
||||||
rec.content = rec.history_head.content
|
rec.content = rec.history_head.content
|
||||||
else:
|
else:
|
||||||
# html widget's default, so it doesn't trigger ghost save
|
# html widget's default, so it doesn't trigger ghost save
|
||||||
rec.content = '<p><br></p>'
|
rec.content = "<p><br></p>"
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _inverse_content(self):
|
def _inverse_content(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.type == 'content' and \
|
if rec.type == "content" and rec.content != rec.history_head.content:
|
||||||
rec.content != rec.history_head.content:
|
rec._create_history(
|
||||||
rec._create_history({
|
{
|
||||||
'name': rec.draft_name,
|
"name": rec.draft_name,
|
||||||
'summary': rec.draft_summary,
|
"summary": rec.draft_summary,
|
||||||
'content': rec.content,
|
"content": rec.content,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _search_content(self, operator, value):
|
def _search_content(self, operator, value):
|
||||||
return [('history_head.content', operator, value)]
|
return [("history_head.content", operator, value)]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('history_ids')
|
@api.depends("history_ids")
|
||||||
def _compute_history_head(self):
|
def _compute_history_head(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.history_ids:
|
if rec.history_ids:
|
||||||
@ -179,20 +170,20 @@ class DocumentPage(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def _create_history(self, vals):
|
def _create_history(self, vals):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
history = self.env['document.page.history']
|
history = self.env["document.page.history"]
|
||||||
vals['page_id'] = self.id
|
vals["page_id"] = self.id
|
||||||
return history.create(vals)
|
return history.create(vals)
|
||||||
|
|
||||||
@api.onchange("parent_id")
|
@api.onchange("parent_id")
|
||||||
def _onchange_parent_id(self):
|
def _onchange_parent_id(self):
|
||||||
"""We Set it the right content to the new parent."""
|
"""We Set it the right content to the new parent."""
|
||||||
if not self.content or self.content == '<p><br></p>':
|
if not self.content or self.content == "<p><br></p>":
|
||||||
if self.parent_id and self.parent_id.type == "category":
|
if self.parent_id and self.parent_id.type == "category":
|
||||||
self.content = self.parent_id.template
|
self.content = self.parent_id.template
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
menus = self.mapped('menu_id')
|
menus = self.mapped("menu_id")
|
||||||
res = super().unlink()
|
res = super().unlink()
|
||||||
menus.unlink()
|
menus.unlink()
|
||||||
return res
|
return res
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
from odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
from odoo.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
|
||||||
@ -11,19 +12,19 @@ class DocumentPageHistory(models.Model):
|
|||||||
|
|
||||||
_name = "document.page.history"
|
_name = "document.page.history"
|
||||||
_description = "Document Page History"
|
_description = "Document Page History"
|
||||||
_order = 'id DESC'
|
_order = "id DESC"
|
||||||
|
|
||||||
page_id = fields.Many2one('document.page', 'Page', ondelete='cascade')
|
page_id = fields.Many2one("document.page", "Page", ondelete="cascade")
|
||||||
name = fields.Char(index=True)
|
name = fields.Char(index=True)
|
||||||
summary = fields.Char(index=True)
|
summary = fields.Char(index=True)
|
||||||
content = fields.Text()
|
content = fields.Text()
|
||||||
diff = fields.Text(compute='_compute_diff')
|
diff = fields.Text(compute="_compute_diff")
|
||||||
|
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
'res.company',
|
"res.company",
|
||||||
'Company',
|
"Company",
|
||||||
help='If set, page is accessible only from this company',
|
help="If set, page is accessible only from this company",
|
||||||
related='page_id.company_id',
|
related="page_id.company_id",
|
||||||
store=True,
|
store=True,
|
||||||
index=True,
|
index=True,
|
||||||
readonly=True,
|
readonly=True,
|
||||||
@ -32,13 +33,16 @@ class DocumentPageHistory(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def _compute_diff(self):
|
def _compute_diff(self):
|
||||||
"""Shows a diff between this version and the previous version"""
|
"""Shows a diff between this version and the previous version"""
|
||||||
history = self.env['document.page.history']
|
history = self.env["document.page.history"]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
prev = history.search([
|
prev = history.search(
|
||||||
('page_id', '=', rec.page_id.id),
|
[
|
||||||
('create_date', '<', rec.create_date)],
|
("page_id", "=", rec.page_id.id),
|
||||||
|
("create_date", "<", rec.create_date),
|
||||||
|
],
|
||||||
limit=1,
|
limit=1,
|
||||||
order='create_date DESC')
|
order="create_date DESC",
|
||||||
|
)
|
||||||
if prev:
|
if prev:
|
||||||
rec.diff = self._get_diff(prev.id, rec.id)
|
rec.diff = self._get_diff(prev.id, rec.id)
|
||||||
else:
|
else:
|
||||||
@ -47,23 +51,24 @@ class DocumentPageHistory(models.Model):
|
|||||||
@api.model
|
@api.model
|
||||||
def _get_diff(self, v1, v2):
|
def _get_diff(self, v1, v2):
|
||||||
"""Return the difference between two version of document version."""
|
"""Return the difference between two version of document version."""
|
||||||
text1 = v1 and self.browse(v1).content or ''
|
text1 = v1 and self.browse(v1).content or ""
|
||||||
text2 = v2 and self.browse(v2).content or ''
|
text2 = v2 and self.browse(v2).content or ""
|
||||||
# Include line breaks to make it more readable
|
# Include line breaks to make it more readable
|
||||||
# TODO: consider using a beautify library directly on the content
|
# TODO: consider using a beautify library directly on the content
|
||||||
text1 = text1.replace('</p><p>', '</p>\r\n<p>')
|
text1 = text1.replace("</p><p>", "</p>\r\n<p>")
|
||||||
text2 = text2.replace('</p><p>', '</p>\r\n<p>')
|
text2 = text2.replace("</p><p>", "</p>\r\n<p>")
|
||||||
line1 = text1.splitlines(True)
|
line1 = text1.splitlines(True)
|
||||||
line2 = text2.splitlines(True)
|
line2 = text2.splitlines(True)
|
||||||
if line1 == line2:
|
if line1 == line2:
|
||||||
return _('There are no changes in revisions.')
|
return _("There are no changes in revisions.")
|
||||||
else:
|
else:
|
||||||
diff = difflib.HtmlDiff()
|
diff = difflib.HtmlDiff()
|
||||||
return diff.make_table(
|
return diff.make_table(
|
||||||
line1, line2,
|
line1,
|
||||||
|
line2,
|
||||||
"Revision-{}".format(v1),
|
"Revision-{}".format(v1),
|
||||||
"Revision-{}".format(v2),
|
"Revision-{}".format(v2),
|
||||||
context=True
|
context=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@ -26,4 +26,3 @@ table.diff .diff_chg {
|
|||||||
table.diff .diff_sub {
|
table.diff .diff_sub {
|
||||||
background-color:#ffaaaa
|
background-color:#ffaaaa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,55 +3,49 @@ from odoo.tests import common
|
|||||||
|
|
||||||
|
|
||||||
class TestDocumentPage(common.TransactionCase):
|
class TestDocumentPage(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDocumentPage, self).setUp()
|
super(TestDocumentPage, self).setUp()
|
||||||
self.page_obj = self.env['document.page']
|
self.page_obj = self.env["document.page"]
|
||||||
self.history_obj = self.env['document.page.history']
|
self.history_obj = self.env["document.page.history"]
|
||||||
self.category1 = self.env.ref('document_page.demo_category1')
|
self.category1 = self.env.ref("document_page.demo_category1")
|
||||||
self.page1 = self.env.ref('document_page.demo_page1')
|
self.page1 = self.env.ref("document_page.demo_page1")
|
||||||
|
|
||||||
def test_page_creation(self):
|
def test_page_creation(self):
|
||||||
page = self.page_obj.create({
|
page = self.page_obj.create(
|
||||||
'name': 'Test Page 1',
|
{
|
||||||
'parent_id': self.category1.id,
|
"name": "Test Page 1",
|
||||||
'content': 'Test content'
|
"parent_id": self.category1.id,
|
||||||
})
|
"content": "Test content",
|
||||||
self.assertEqual(page.content, 'Test content')
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(page.content, "Test content")
|
||||||
self.assertEqual(len(page.history_ids), 1)
|
self.assertEqual(len(page.history_ids), 1)
|
||||||
page.content = 'New content for Demo Page'
|
page.content = "New content for Demo Page"
|
||||||
self.assertEqual(len(page.history_ids), 2)
|
self.assertEqual(len(page.history_ids), 2)
|
||||||
|
|
||||||
def test_category_template(self):
|
def test_category_template(self):
|
||||||
page = self.page_obj.create({
|
page = self.page_obj.create(
|
||||||
'name': 'Test Page 2',
|
{"name": "Test Page 2", "parent_id": self.category1.id}
|
||||||
'parent_id': self.category1.id,
|
)
|
||||||
})
|
|
||||||
page._onchange_parent_id()
|
page._onchange_parent_id()
|
||||||
self.assertEqual(page.content, self.category1.template)
|
self.assertEqual(page.content, self.category1.template)
|
||||||
|
|
||||||
def test_page_history_diff(self):
|
def test_page_history_diff(self):
|
||||||
page = self.page_obj.create({
|
page = self.page_obj.create({"name": "Test Page 3", "content": "Test content"})
|
||||||
'name': 'Test Page 3',
|
page.content = "New content"
|
||||||
'content': 'Test content'
|
|
||||||
})
|
|
||||||
page.content = 'New content'
|
|
||||||
self.assertIsNotNone(page.history_ids[0].diff)
|
self.assertIsNotNone(page.history_ids[0].diff)
|
||||||
|
|
||||||
def test_page_link(self):
|
def test_page_link(self):
|
||||||
page = self.page_obj.create({
|
page = self.page_obj.create({"name": "Test Page 3", "content": "Test content"})
|
||||||
'name': 'Test Page 3',
|
|
||||||
'content': 'Test content'
|
|
||||||
})
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
page.backend_url,
|
page.backend_url,
|
||||||
'/web#id={}&model=document.page&view_type=form'.format(page.id)
|
"/web#id={}&model=document.page&view_type=form".format(page.id),
|
||||||
)
|
)
|
||||||
menu = self.env.ref('knowledge.menu_document')
|
menu = self.env.ref("knowledge.menu_document")
|
||||||
page.menu_id = menu
|
page.menu_id = menu
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
page.backend_url,
|
page.backend_url,
|
||||||
'/web#id={}&model=document.page&view_type=form&action={}'.format(
|
"/web#id={}&model=document.page&view_type=form&action={}".format(
|
||||||
page.id, menu.action.id
|
page.id, menu.action.id
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
@ -7,23 +7,23 @@ class TestDocumentPageCreateMenu(common.TransactionCase):
|
|||||||
|
|
||||||
def test_page_menu_creation(self):
|
def test_page_menu_creation(self):
|
||||||
"""Test page menu creation."""
|
"""Test page menu creation."""
|
||||||
menu_parent = self.env.ref('knowledge.menu_document')
|
menu_parent = self.env.ref("knowledge.menu_document")
|
||||||
|
|
||||||
menu_created = self.env['document.page.create.menu'].create(
|
menu_created = self.env["document.page.create.menu"].create(
|
||||||
{'menu_name': 'Wiki Test menu', 'menu_parent_id': menu_parent.id}
|
{"menu_name": "Wiki Test menu", "menu_parent_id": menu_parent.id}
|
||||||
)
|
)
|
||||||
|
|
||||||
menu = self.env['document.page.create.menu'].search(
|
menu = self.env["document.page.create.menu"].search(
|
||||||
[('id', '=', menu_created.id)]
|
[("id", "=", menu_created.id)]
|
||||||
)
|
)
|
||||||
menu.with_context(
|
menu.with_context(
|
||||||
active_id=[self.ref('document_page.demo_page1')]
|
active_id=[self.ref("document_page.demo_page1")]
|
||||||
).document_page_menu_create()
|
).document_page_menu_create()
|
||||||
|
|
||||||
fields_list = ["menu_name", "menu_name"]
|
fields_list = ["menu_name", "menu_name"]
|
||||||
|
|
||||||
res = menu.with_context(
|
res = menu.with_context(
|
||||||
active_id=[self.ref('document_page.demo_page1')]
|
active_id=[self.ref("document_page.demo_page1")]
|
||||||
).default_get(fields_list)
|
).default_get(fields_list)
|
||||||
|
|
||||||
self.assertEqual(res['menu_name'], 'OpenERP 6.1. Functional Demo')
|
self.assertEqual(res["menu_name"], "OpenERP 6.1. Functional Demo")
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
@ -7,14 +6,14 @@ class TestDocumentPageHistory(common.TransactionCase):
|
|||||||
|
|
||||||
def test_page_history_demo_page1(self):
|
def test_page_history_demo_page1(self):
|
||||||
"""Test page history demo page1."""
|
"""Test page history demo page1."""
|
||||||
page = self.env.ref('document_page.demo_page1')
|
page = self.env.ref("document_page.demo_page1")
|
||||||
page.content = 'Test content updated'
|
page.content = "Test content updated"
|
||||||
history_document = self.env['document.page.history']
|
history_document = self.env["document.page.history"]
|
||||||
history_pages = history_document.search([('page_id', '=', page.id)])
|
history_pages = history_document.search([("page_id", "=", page.id)])
|
||||||
active_ids = [i.id for i in history_pages]
|
active_ids = [i.id for i in history_pages]
|
||||||
|
|
||||||
result = history_document._get_diff(active_ids[0], active_ids[0])
|
result = history_document._get_diff(active_ids[0], active_ids[0])
|
||||||
self.assertEqual(result, 'There are no changes in revisions.')
|
self.assertEqual(result, "There are no changes in revisions.")
|
||||||
|
|
||||||
result = history_document._get_diff(active_ids[0], active_ids[1])
|
result = history_document._get_diff(active_ids[0], active_ids[1])
|
||||||
self.assertNotEqual(result, 'There are no changes in revisions.')
|
self.assertNotEqual(result, "There are no changes in revisions.")
|
||||||
|
@ -8,12 +8,12 @@ class TestDocumentPageShowDiff(common.TransactionCase):
|
|||||||
|
|
||||||
def test_show_demo_page1_diff(self):
|
def test_show_demo_page1_diff(self):
|
||||||
"""Show test page history difference."""
|
"""Show test page history difference."""
|
||||||
page = self.env.ref('document_page.demo_page1')
|
page = self.env.ref("document_page.demo_page1")
|
||||||
|
|
||||||
show_diff_object = self.env['wizard.document.page.history.show_diff']
|
show_diff_object = self.env["wizard.document.page.history.show_diff"]
|
||||||
|
|
||||||
history_document = self.env['document.page.history']
|
history_document = self.env["document.page.history"]
|
||||||
history_pages = history_document.search([('page_id', '=', page.id)])
|
history_pages = history_document.search([("page_id", "=", page.id)])
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
show_diff_object.with_context(
|
show_diff_object.with_context(
|
||||||
@ -21,10 +21,10 @@ class TestDocumentPageShowDiff(common.TransactionCase):
|
|||||||
)._get_diff()
|
)._get_diff()
|
||||||
)
|
)
|
||||||
|
|
||||||
page.write({'content': 'Text content updated'})
|
page.write({"content": "Text content updated"})
|
||||||
page.write({'content': 'Text updated'})
|
page.write({"content": "Text updated"})
|
||||||
|
|
||||||
history_pages = history_document.search([('page_id', '=', page.id)])
|
history_pages = history_document.search([("page_id", "=", page.id)])
|
||||||
|
|
||||||
with self.assertRaises(UserError):
|
with self.assertRaises(UserError):
|
||||||
show_diff_object.with_context(
|
show_diff_object.with_context(
|
||||||
|
@ -10,65 +10,58 @@ class DocumentPageCreateMenu(models.TransientModel):
|
|||||||
_name = "document.page.create.menu"
|
_name = "document.page.create.menu"
|
||||||
_description = "Wizard Create Menu"
|
_description = "Wizard Create Menu"
|
||||||
|
|
||||||
menu_name = fields.Char(
|
menu_name = fields.Char("Menu Name", required=True)
|
||||||
'Menu Name',
|
menu_parent_id = fields.Many2one("ir.ui.menu", "Parent Menu", required=True)
|
||||||
required=True
|
|
||||||
)
|
|
||||||
menu_parent_id = fields.Many2one(
|
|
||||||
'ir.ui.menu',
|
|
||||||
'Parent Menu',
|
|
||||||
required=True
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
"""Get Page name of the menu."""
|
"""Get Page name of the menu."""
|
||||||
res = super(DocumentPageCreateMenu, self).default_get(fields_list)
|
res = super(DocumentPageCreateMenu, self).default_get(fields_list)
|
||||||
page_id = self.env.context.get('active_id')
|
page_id = self.env.context.get("active_id")
|
||||||
obj_page = self.env['document.page']
|
obj_page = self.env["document.page"]
|
||||||
page = obj_page.browse(page_id)
|
page = obj_page.browse(page_id)
|
||||||
res['menu_name'] = page.name
|
res["menu_name"] = page.name
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def document_page_menu_create(self):
|
def document_page_menu_create(self):
|
||||||
"""Menu creation."""
|
"""Menu creation."""
|
||||||
obj_page = self.env['document.page']
|
obj_page = self.env["document.page"]
|
||||||
obj_menu = self.env['ir.ui.menu']
|
obj_menu = self.env["ir.ui.menu"]
|
||||||
obj_action = self.env['ir.actions.act_window']
|
obj_action = self.env["ir.actions.act_window"]
|
||||||
obj_model_data = self.env['ir.model.data']
|
obj_model_data = self.env["ir.model.data"]
|
||||||
page_id = self.env.context.get('active_id', False)
|
page_id = self.env.context.get("active_id", False)
|
||||||
page = obj_page.browse(page_id)
|
page = obj_page.browse(page_id)
|
||||||
|
|
||||||
data = self[0]
|
data = self[0]
|
||||||
view_id = obj_model_data.sudo().get_object_reference(
|
view_id = obj_model_data.sudo().get_object_reference(
|
||||||
'document_page', 'view_wiki_menu_form')[1]
|
"document_page", "view_wiki_menu_form"
|
||||||
|
)[1]
|
||||||
value = {
|
value = {
|
||||||
'name': 'Document Page',
|
"name": "Document Page",
|
||||||
'view_type': 'form',
|
"view_type": "form",
|
||||||
'view_mode': 'form,tree',
|
"view_mode": "form,tree",
|
||||||
'res_model': 'document.page',
|
"res_model": "document.page",
|
||||||
'view_id': view_id,
|
"view_id": view_id,
|
||||||
'type': 'ir.actions.act_window',
|
"type": "ir.actions.act_window",
|
||||||
'target': 'current',
|
"target": "current",
|
||||||
}
|
}
|
||||||
value['domain'] = "[('parent_id','=',%d)]" % page.id
|
value["domain"] = "[('parent_id','=',%d)]" % page.id
|
||||||
value['res_id'] = page.id
|
value["res_id"] = page.id
|
||||||
|
|
||||||
# only the super user is allowed to create menu due to security rules
|
# only the super user is allowed to create menu due to security rules
|
||||||
# on ir.values
|
# on ir.values
|
||||||
# see.: http://goo.gl/Y99S7V
|
# see.: http://goo.gl/Y99S7V
|
||||||
action_id = obj_action.sudo().create(value)
|
action_id = obj_action.sudo().create(value)
|
||||||
|
|
||||||
menu_id = obj_menu.sudo().create({
|
menu_id = obj_menu.sudo().create(
|
||||||
'name': data.menu_name,
|
{
|
||||||
'parent_id': data.menu_parent_id.id,
|
"name": data.menu_name,
|
||||||
'action': 'ir.actions.act_window,' + str(action_id.id),
|
"parent_id": data.menu_parent_id.id,
|
||||||
})
|
"action": "ir.actions.act_window," + str(action_id.id),
|
||||||
|
}
|
||||||
|
)
|
||||||
if page.menu_id:
|
if page.menu_id:
|
||||||
page.menu_id.unlink()
|
page.menu_id.unlink()
|
||||||
page.write({'menu_id': menu_id.id})
|
page.write({"menu_id": menu_id.id})
|
||||||
return {
|
return {"type": "ir.actions.client", "tag": "reload"}
|
||||||
'type': 'ir.actions.client',
|
|
||||||
'tag': 'reload',
|
|
||||||
}
|
|
||||||
|
@ -9,13 +9,13 @@ from odoo.tools.translate import _
|
|||||||
class DocumentPageShowDiff(models.TransientModel):
|
class DocumentPageShowDiff(models.TransientModel):
|
||||||
"""Display Difference for History."""
|
"""Display Difference for History."""
|
||||||
|
|
||||||
_name = 'wizard.document.page.history.show_diff'
|
_name = "wizard.document.page.history.show_diff"
|
||||||
_description = 'Document Page Show Diff'
|
_description = "Document Page Show Diff"
|
||||||
|
|
||||||
def _get_diff(self):
|
def _get_diff(self):
|
||||||
"""Return the Difference between two document."""
|
"""Return the Difference between two document."""
|
||||||
history = self.env["document.page.history"]
|
history = self.env["document.page.history"]
|
||||||
ids = self.env.context.get('active_ids', [])
|
ids = self.env.context.get("active_ids", [])
|
||||||
diff = False
|
diff = False
|
||||||
if len(ids) == 2:
|
if len(ids) == 2:
|
||||||
if ids[0] > ids[1]:
|
if ids[0] > ids[1]:
|
||||||
@ -25,11 +25,7 @@ class DocumentPageShowDiff(models.TransientModel):
|
|||||||
elif len(ids) == 1:
|
elif len(ids) == 1:
|
||||||
diff = history.browse(ids[0]).diff
|
diff = history.browse(ids[0]).diff
|
||||||
else:
|
else:
|
||||||
raise UserError(
|
raise UserError(_("Select one or maximum two history revisions!"))
|
||||||
_("Select one or maximum two history revisions!"))
|
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
diff = fields.Text(
|
diff = fields.Text(readonly=True, default=_get_diff)
|
||||||
readonly=True,
|
|
||||||
default=_get_diff,
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user