diff --git a/document_page/README.rst b/document_page/README.rst new file mode 100644 index 00000000..efbfb619 --- /dev/null +++ b/document_page/README.rst @@ -0,0 +1,68 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============= +Document Page +============= + +This module allows you to write web pages for internal documentation. + +Installation +============ + +This module depends on module knowledge. So make sure to have it in your addons list. + +Configuration +============= + +No configuration required + +Usage +===== + +To use this module, you need to: + +* Go to Knowledge menu +* Click on Categories to create the document's category you need with the template +* Click on Pages to create pages and select the previous category to use the template + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/118/9.0 + +Known issues / Roadmap +====================== + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. + +Credits +======= + +Contributors +------------ + +* Odoo SA +* Savoir-faire Linux +* Gervais Naoussi + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/document_page/__init__.py b/document_page/__init__.py index d11fab84..a7385355 100644 --- a/document_page/__init__.py +++ b/document_page/__init__.py @@ -18,5 +18,5 @@ # along with this program. If not, see . # ############################################################################## -from . import document_page +from . import models from . import wizard diff --git a/document_page/__openerp__.py b/document_page/__openerp__.py index e11755ab..8c129f3e 100644 --- a/document_page/__openerp__.py +++ b/document_page/__openerp__.py @@ -21,35 +21,29 @@ { 'name': 'Document Page', - 'version': '8.0.1.0.1', + 'version': '9.0.1.0.1', 'category': 'Knowledge Management', - 'description': """ -Pages -===== -Web pages - """, - 'author': ['OpenERP SA'], + 'author': 'OpenERP SA, Odoo Community Association (OCA)', + 'images': ['images/category_list.png', 'images/create_category.png', + 'images/page_list.png', 'images/create_page.png', + 'images/customer_invoice.jpeg', 'images/page_history.png'], 'website': 'http://www.openerp.com/', 'license': 'AGPL-3', 'depends': [ - 'knowledge', 'mail', + 'knowledge', ], 'data': [ - 'wizard/document_page_create_menu_view.xml', - 'wizard/document_page_show_diff_view.xml', - 'document_page_view.xml', + 'wizard/document_page_create_menu.xml', + 'wizard/document_page_show_diff.xml', + 'views/document_page.xml', 'security/document_page_security.xml', 'security/ir.model.access.csv', ], 'demo': [ - 'document_page_demo.xml' - ], - 'test': [ - 'test/document_page_test00.yml' + 'demo/document_page.xml' ], 'installable': True, 'auto_install': False, - 'images': [], 'css': ['static/src/css/document_page.css'], } diff --git a/document_page/document_page_data.xml b/document_page/data/document_page.xml similarity index 80% rename from document_page/document_page_data.xml rename to document_page/data/document_page.xml index 1cef6569..9cd3c0dd 100644 --- a/document_page/document_page_data.xml +++ b/document_page/data/document_page.xml @@ -1,17 +1,17 @@ - + - The OpenERP wiki + The Odoo wiki help, quick start, wiki, formatting 0 1 Initial Page - ==The OpenERP wiki== - -[[File:http://www.openerp.com/sites/all/themes/openerp/logo.png OpenERP]] + == The Odoo wiki == -The OpenERP wiki allows you to manage your enterprise's contents using wiki +[[File:https://www.odoo.com/openerp_website/static/src/img/logo_transparent_198px.png Odoo]] + +The Odoo wiki allows you to manage your enterprise's contents using wiki restructured texts. This module provides a collaborative way to manage internal FAQs, quality manuals, technical references, etc. @@ -38,4 +38,4 @@ FAQs, quality manuals, technical references, etc. - + diff --git a/document_page/document_page_demo.xml b/document_page/demo/document_page.xml similarity index 99% rename from document_page/document_page_demo.xml rename to document_page/demo/document_page.xml index c94054e7..8e6d2eca 100644 --- a/document_page/document_page_demo.xml +++ b/document_page/demo/document_page.xml @@ -1,5 +1,5 @@ - + - + diff --git a/document_page/images/category_list.png b/document_page/images/category_list.png new file mode 100644 index 00000000..01be2584 Binary files /dev/null and b/document_page/images/category_list.png differ diff --git a/document_page/images/create_category.png b/document_page/images/create_category.png new file mode 100644 index 00000000..a845123d Binary files /dev/null and b/document_page/images/create_category.png differ diff --git a/document_page/images/create_page.png b/document_page/images/create_page.png new file mode 100644 index 00000000..ab8c980f Binary files /dev/null and b/document_page/images/create_page.png differ diff --git a/document_page/images/page_history.png b/document_page/images/page_history.png new file mode 100644 index 00000000..9520ab05 Binary files /dev/null and b/document_page/images/page_history.png differ diff --git a/document_page/images/page_list.png b/document_page/images/page_list.png new file mode 100644 index 00000000..731f3422 Binary files /dev/null and b/document_page/images/page_list.png differ diff --git a/document_page/models/__init__.py b/document_page/models/__init__.py new file mode 100644 index 00000000..2d33cac6 --- /dev/null +++ b/document_page/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## +from . import document_page +from . import document_page_history diff --git a/document_page/document_page.py b/document_page/models/document_page.py similarity index 71% rename from document_page/document_page.py rename to document_page/models/document_page.py index 21da2770..65e68600 100644 --- a/document_page/document_page.py +++ b/document_page/models/document_page.py @@ -19,13 +19,14 @@ # ############################################################################## import logging -import difflib -from openerp import models, fields, api, _ +from openerp import models, fields, api _logger = logging.getLogger(__name__) -class document_page(models.Model): +class DocumentPage(models.Model): + """This class is use to manage Document.""" + _name = "document.page" _inherit = ['mail.thread'] _description = "Document Page" @@ -99,6 +100,7 @@ class document_page(models.Model): ) def _get_page_index(self, page, link=True): + """Return the index of a document.""" index = [] for subpage in page.child_ids: index += ["
  • " + self._get_page_index(subpage) + @@ -112,6 +114,7 @@ class document_page(models.Model): return r def _get_display_content(self): + """Return the content of a document.""" for page in self: if page.type == "category": display_content = self._get_page_index(page, link=False) @@ -121,11 +124,13 @@ class document_page(models.Model): @api.onchange("parent_id") def do_set_content(self): + """We Set it the right content to the new parent.""" if self.parent_id and not self.content: if self.parent_id.type == "category": self.content = self.parent_id.content def create_history(self, page_id, content): + """Create the first history of a newly created document.""" history = self.env['document.page.history'] return history.create({ "content": content, @@ -134,7 +139,8 @@ class document_page(models.Model): @api.multi def write(self, vals): - result = super(document_page, self).write(vals) + """Write the content and set the history.""" + result = super(DocumentPage, self).write(vals) content = vals.get('content') if content: for page in self: @@ -144,51 +150,9 @@ class document_page(models.Model): @api.model @api.returns('self', lambda value: value.id) def create(self, vals): - page_id = super(document_page, self).create(vals) + """Create the first history of a document.""" + page_id = super(DocumentPage, self).create(vals) content = vals.get('content') if content: self.create_history(page_id.id, content) return page_id - - -class document_page_history(models.Model): - _name = "document.page.history" - _description = "Document Page History" - _order = 'id DESC' - _rec_name = "create_date" - - 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, v1, v2): - text1 = self.browse(v1).content - text2 = self.browse(v2).content - line1 = line2 = '' - if text1: - line1 = text1.splitlines(1) - if text2: - line2 = text2.splitlines(1) - if (not line1 and not line2) or (line1 == line2): - return _('There are no changes in revisions.') - else: - diff = difflib.HtmlDiff() - return diff.make_table( - line1, line2, - "Revision-{}".format(v1), - "Revision-{}".format(v2), - context=True - ) - - def __getattr__(self, attr): - """Return a dummy callabale""" - if attr in ['_sql', 'init', '_ids']: - raise AttributeError - - _logger.warning( - "Trying to access attribute %s on document_page_history", - attr - ) - return (lambda *a, **b: None) diff --git a/document_page/models/document_page_history.py b/document_page/models/document_page_history.py new file mode 100644 index 00000000..9bbf61a8 --- /dev/null +++ b/document_page/models/document_page_history.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## +import logging +import difflib +from openerp import models, fields, _ + +_logger = logging.getLogger(__name__) + + +class DocumentPageHistory(models.Model): + """This model is necessary to manage a document history.""" + + _name = "document.page.history" + _description = "Document Page History" + _order = 'id DESC' + _rec_name = "create_date" + + page_id = fields.Many2one('document.page', 'Page') + summary = fields.Char('Summary', select=True) + content = fields.Text("Content") + create_date = fields.Datetime("Date") + create_uid = fields.Many2one('res.users', "Modified By") + + def getDiff(self, v1, v2): + """Return the difference between two version of document version.""" + text1 = self.browse(v1).content + text2 = self.browse(v2).content + line1 = line2 = '' + if text1: + line1 = text1.splitlines(1) + if text2: + line2 = text2.splitlines(1) + if (not line1 and not line2) or (line1 == line2): + return _('There are no changes in revisions.') + else: + diff = difflib.HtmlDiff() + return diff.make_table( + line1, line2, + "Revision-{}".format(v1), + "Revision-{}".format(v2), + context=True + ) diff --git a/document_page/security/document_page_security.xml b/document_page/security/document_page_security.xml index 6d85d054..6834b69b 100644 --- a/document_page/security/document_page_security.xml +++ b/document_page/security/document_page_security.xml @@ -1,8 +1,8 @@ - + - + diff --git a/document_page/test/document_page_test00.yml b/document_page/test/document_page_test00.yml deleted file mode 100644 index bc75c64e..00000000 --- a/document_page/test/document_page_test00.yml +++ /dev/null @@ -1,55 +0,0 @@ -- - In order to test the document_page in OpenERP, I create a new page to category demo_category1 -- - !record {model: document.page, id: test_page0}: - name: Test Page0 - parent_id: demo_category1 - content: 'Test content - - The Open ERP wiki allows you to manage your enterprise contents using wiki - - restructured texts. This module provides a collaborative way to manage internal - - FAQs, quality manuals, technical references, etc.' - -- - I check the category index contains my page. -- - !python {model: document.page}: | - res = self.read(cr, uid, [ref('demo_category1')], ['display_content']) - assert res[0]['display_content'].find('Test Page') > 1 -- - !record {model: document.page, id: test_page0}: - content: 'Test updated content - - The Open ERP wiki allows you to manage your enterprise contents using wiki - - restructured texts. This module provides a collaborative way to manage internal - - FAQs, quality manuals, technical references, etc. - - Wiki text can easily be edited - ' - -- - I check the page history for the current page by clicking on "Page History".After that find difference between history. -- - !python {model: wizard.document.page.history.show_diff, id: False}: | - hist_obj = self.env['document.page.history'] - ids = hist_obj.search([('page_id', '=', ref("test_page0"))]) - self.with_context(active_ids=[i.id for i in ids]).get_diff() - - -- - I click the "create menu" link and i fill the form. -- - !record {model: document.page.create.menu, id: test_create_menu0}: - menu_name: Wiki Test menu - menu_parent_id: base.menu_base_partner -- - I create a Menu by clicking on "create menu" -- - !python {model: document.page.create.menu, id: False}: | - menu = self.search([('id', '=', ref("test_create_menu0"))]) - menu.with_context(active_id=[ref('test_page0')]).document_page_menu_create() - diff --git a/document_page/tests/__init__.py b/document_page/tests/__init__.py new file mode 100644 index 00000000..4c507a03 --- /dev/null +++ b/document_page/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from . import test_document_page, test_document_page_history +from . import test_document_page_create_menu +from . import test_document_page_show_diff diff --git a/document_page/tests/test_document_page.py b/document_page/tests/test_document_page.py new file mode 100644 index 00000000..9c3b4d72 --- /dev/null +++ b/document_page/tests/test_document_page.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +from openerp.tests import common + + +class TestDocumentPage(common.TransactionCase): + """document_page test class.""" + + def test_page_creation(self): + """Test page creation.""" + parent_page = self.env.ref('document_page.demo_category1') + + self.assertEqual(parent_page.name, 'OpenERP Features') + + record = self.env['document.page'].create({ + 'name': 'Test Page1', + 'parent_id': parent_page.id, + 'content': 'Test content' + }) + self.assertEqual(record.name, 'Test Page1') + + def test_category_display_content(self): + """Test category display content.""" + page = self.env.ref('document_page.demo_category1') + self.assertTrue(page.display_content.find('Demo') > 1) + + def test_page_display_content(self): + """Test page display content.""" + page = self.env.ref('document_page.demo_page1') + self.assertTrue(page.display_content.find('Demo') > 1) + + def test_page_do_set_content(self): + """Test page set content.""" + page = self.env.ref('document_page.demo_page1') + page.content = None + page.do_set_content() + self.assertTrue(page.display_content.find('Summary') == 1) diff --git a/document_page/tests/test_document_page_create_menu.py b/document_page/tests/test_document_page_create_menu.py new file mode 100644 index 00000000..567b9d9b --- /dev/null +++ b/document_page/tests/test_document_page_create_menu.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from openerp.tests import common + + +class TestDocumentPageCreateMenu(common.TransactionCase): + """document_page_create_menu test class.""" + + def test_page_menu_creation(self): + """Test page menu creation.""" + menu_parent = self.env.ref('base.menu_base_partner') + + menu_created = self.env['document.page.create.menu'].create( + {'menu_name': 'Wiki Test menu', 'menu_parent_id': menu_parent.id} + ) + + menu = self.env['document.page.create.menu'].search( + [('id', '=', menu_created.id)] + ) + menu.with_context( + active_id=[self.ref('document_page.demo_page1')] + ).document_page_menu_create() + + fields_list = ["menu_name", "menu_name"] + + res = menu.with_context( + active_id=[self.ref('document_page.demo_page1')] + ).default_get(fields_list) + + self.assertEqual(res['menu_name'], 'OpenERP 6.1. Functional Demo') diff --git a/document_page/tests/test_document_page_history.py b/document_page/tests/test_document_page_history.py new file mode 100644 index 00000000..ced210c1 --- /dev/null +++ b/document_page/tests/test_document_page_history.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from openerp.tests import common + + +class TestDocumentPageHistory(common.TransactionCase): + """document_page_history test class.""" + + def test_page_history_demo_page1(self): + """Test page history demo page1.""" + page = self.env.ref('document_page.demo_page1') + page.content = 'Test content updated' + history_document = self.env['document.page.history'] + history_pages = history_document.search([('page_id', '=', page.id)]) + active_ids = [i.id for i in history_pages] + + result = history_document.getDiff(active_ids[0], active_ids[0]) + self.assertEqual(result, 'There are no changes in revisions.') + + result = history_document.getDiff(active_ids[0], active_ids[1]) + self.assertNotEqual(result, 'There are no changes in revisions.') diff --git a/document_page/tests/test_document_page_show_diff.py b/document_page/tests/test_document_page_show_diff.py new file mode 100644 index 00000000..a43f7bc1 --- /dev/null +++ b/document_page/tests/test_document_page_show_diff.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +from openerp.tests import common +from openerp import _ + + +class TestDocumentPageShowDiff(common.TransactionCase): + """document_page_show_diff test class.""" + + def test_show_demo_page1_diff(self): + """Show test page history difference.""" + page = self.env.ref('document_page.demo_page1') + + show_diff_object = self.env['wizard.document.page.history.show_diff'] + + history_document = self.env['document.page.history'] + history_pages = history_document.search([('page_id', '=', page.id)]) + + self.assertTrue( + show_diff_object.with_context( + active_ids=[i.id for i in history_pages] + ).get_diff() + ) + + page.write({'content': 'Text content updated'}) + page.write({'content': 'Text updated'}) + + history_pages = history_document.search([('page_id', '=', page.id)]) + + with self.assertRaises(Exception) as context: + show_diff_object.with_context( + active_ids=[i.id for i in history_pages] + ).get_diff() + + self.assertTrue(_("Select one or maximum two history revisions!") + in context.exception) diff --git a/document_page/document_page_view.xml b/document_page/views/document_page.xml similarity index 99% rename from document_page/document_page_view.xml rename to document_page/views/document_page.xml index 7f7ab50d..06e4f19a 100644 --- a/document_page/document_page_view.xml +++ b/document_page/views/document_page.xml @@ -1,9 +1,6 @@ - + - - - + diff --git a/document_page/wizard/__init__.py b/document_page/wizard/__init__.py index 3348328b..af150490 100644 --- a/document_page/wizard/__init__.py +++ b/document_page/wizard/__init__.py @@ -20,5 +20,3 @@ ############################################################################## from . import document_page_create_menu from . import document_page_show_diff - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_page/wizard/document_page_create_menu.py b/document_page/wizard/document_page_create_menu.py index 91821718..9904ba4d 100644 --- a/document_page/wizard/document_page_create_menu.py +++ b/document_page/wizard/document_page_create_menu.py @@ -21,8 +21,9 @@ from openerp import models, fields, api -class document_page_create_menu(models.TransientModel): - """ Create Menu """ +class DocumentPageCreateMenu(models.TransientModel): + """Create Menu.""" + _name = "document.page.create.menu" _description = "Wizard Create Menu" @@ -39,7 +40,8 @@ class document_page_create_menu(models.TransientModel): @api.model def default_get(self, fields_list): - res = super(document_page_create_menu, self).default_get(fields_list) + """Get Page name of the menu.""" + res = super(DocumentPageCreateMenu, self).default_get(fields_list) page_id = self.env.context.get('active_id') obj_page = self.env['document.page'] page = obj_page.browse(page_id) @@ -48,6 +50,7 @@ class document_page_create_menu(models.TransientModel): @api.multi def document_page_menu_create(self): + """Menu creation.""" obj_page = self.env['document.page'] obj_menu = self.env['ir.ui.menu'] obj_action = self.env['ir.actions.act_window'] @@ -86,6 +89,3 @@ class document_page_create_menu(models.TransientModel): 'type': 'ir.actions.client', 'tag': 'reload', } - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_page/wizard/document_page_create_menu_view.xml b/document_page/wizard/document_page_create_menu.xml similarity index 98% rename from document_page/wizard/document_page_create_menu_view.xml rename to document_page/wizard/document_page_create_menu.xml index 858aa0ed..c18c4729 100644 --- a/document_page/wizard/document_page_create_menu_view.xml +++ b/document_page/wizard/document_page_create_menu.xml @@ -1,5 +1,5 @@ - + @@ -38,4 +38,4 @@ - + diff --git a/document_page/wizard/document_page_show_diff.py b/document_page/wizard/document_page_show_diff.py index 25a93de2..db42214d 100644 --- a/document_page/wizard/document_page_show_diff.py +++ b/document_page/wizard/document_page_show_diff.py @@ -22,12 +22,13 @@ from openerp import models, fields, _ from openerp import exceptions -class showdiff(models.TransientModel): - """ Display Difference for History """ +class DocumentPageShowDiff(models.TransientModel): + """Display Difference for History.""" _name = 'wizard.document.page.history.show_diff' def get_diff(self): + """Return the Difference between two document.""" history = self.env["document.page.history"] ids = self.env.context.get('active_ids', []) @@ -47,8 +48,7 @@ class showdiff(models.TransientModel): diff = history.getDiff(ids[0], nids.id) else: raise exceptions.Warning( - _("You need to select minimum one or maximum " - "two history revisions!") + _("Select one or maximum two history revisions!") ) return diff @@ -57,5 +57,3 @@ class showdiff(models.TransientModel): readonly=True, default=get_diff ) - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/document_page/wizard/document_page_show_diff_view.xml b/document_page/wizard/document_page_show_diff.xml similarity index 98% rename from document_page/wizard/document_page_show_diff_view.xml rename to document_page/wizard/document_page_show_diff.xml index dbe973b3..4499769f 100644 --- a/document_page/wizard/document_page_show_diff_view.xml +++ b/document_page/wizard/document_page_show_diff.xml @@ -1,5 +1,5 @@ - + @@ -44,4 +44,4 @@ view_type="form"/> - +