diff --git a/document_page/README.rst b/document_page/README.rst index 8c233970..a9a9cbce 100644 --- a/document_page/README.rst +++ b/document_page/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ============= Document Page ============= @@ -17,7 +13,7 @@ Document Page .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github @@ -61,6 +57,12 @@ To use this module, you need to: - Click on Pages to create pages and select the previous category to use the template +Improve diff of history +----------------------- + +If you want to improve how history is shown, you can install html_diff +python library. A new comparison method will be installed. + Bug Tracker =========== @@ -83,23 +85,34 @@ Contributors ------------ - Gervais Naoussi + - Maxime Chambreuil + - Iván Todorovich + - Jose Maria Alzaga + - Lois Rilo + - Simone Orsi + - `Tecnativa `__: - Ernesto Tejeda - Víctor Martínez -Trobz +- Trobz + + - Dung Tran -- Dung Tran - `Sygel `__: - Ángel García de la Chica Herrera +- `Dixmit `__: + + - Enric Tobella + Other credits ------------- diff --git a/document_page/__manifest__.py b/document_page/__manifest__.py index ccd409b1..ecf546f1 100644 --- a/document_page/__manifest__.py +++ b/document_page/__manifest__.py @@ -30,6 +30,9 @@ ], "demo": ["demo/document_page.xml"], "assets": { + "web._assets_primary_variables": [ + "document_page/static/src/**/document_page_variables.scss", + ], "web.assets_backend": [ "document_page/static/src/scss/document_page.scss", "document_page/static/src/js/document_page_kanban_controller.esm.js", diff --git a/document_page/models/document_page_history.py b/document_page/models/document_page_history.py index b2bf80a6..24ae10e4 100644 --- a/document_page/models/document_page_history.py +++ b/document_page/models/document_page_history.py @@ -3,8 +3,16 @@ import difflib +try: + import html_diff +except ImportError: + html_diff = None +import logging + from odoo import api, fields, models +_logger = logging.getLogger(__name__) + class DocumentPageHistory(models.Model): """This model is necessary to manage a document history.""" @@ -43,11 +51,16 @@ class DocumentPageHistory(models.Model): ) rec.diff = self._get_diff(prev.id, rec.id) - @api.model def _get_diff(self, v1, v2): - """Return the difference between two version of document version.""" text1 = v1 and self.browse(v1).content or "" text2 = v2 and self.browse(v2).content or "" + if html_diff: + return html_diff.diff(text1, text2) + # Keeping old logic. to be removed in 19 or 18.abs + _logger.warning( + "_get_diff: using fallback logic, please install 'html_diff' library " + "for better diff rendering" + ) # Include line breaks to make it more readable # TODO: consider using a beautify library directly on the content text1 = text1.replace("

", "

\r\n

") diff --git a/document_page/readme/CONTRIBUTORS.md b/document_page/readme/CONTRIBUTORS.md index 8e410db7..2c661472 100644 --- a/document_page/readme/CONTRIBUTORS.md +++ b/document_page/readme/CONTRIBUTORS.md @@ -8,8 +8,11 @@ - Ernesto Tejeda - Víctor Martínez -Trobz +- Trobz + - Dung Tran \<\> -- Dung Tran \<\> - [Sygel](https://www.sygel.es): - Ángel García de la Chica Herrera + +- [Dixmit](https://www.dixmit.com): + - Enric Tobella diff --git a/document_page/readme/USAGE.md b/document_page/readme/USAGE.md index 8ba0011a..d272c8d7 100644 --- a/document_page/readme/USAGE.md +++ b/document_page/readme/USAGE.md @@ -5,3 +5,8 @@ To use this module, you need to: the template - Click on Pages to create pages and select the previous category to use the template + +## Improve diff of history + +If you want to improve how history is shown, you can install html_diff python library. +A new comparison method will be installed. diff --git a/document_page/static/description/index.html b/document_page/static/description/index.html index 18eafce8..1f06b405 100644 --- a/document_page/static/description/index.html +++ b/document_page/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Document Page -

+
+

Document Page

- - -Odoo Community Association - -
-

Document Page

-

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runboat

This module allows you to write web pages for internal documentation.

Table of contents

-

Installation

+

Installation

This module depends on module knowledge. So make sure to have it in your addons list.

-

Configuration

+

Configuration

No configuration required.

-

Usage

+

Usage

To use this module, you need to:

  • Go to Knowledge menu
  • @@ -411,9 +409,14 @@ the template
  • Click on Pages to create pages and select the previous category to use the template
+
+

Improve diff of history

+

If you want to improve how history is shown, you can install html_diff +python library. A new comparison method will be installed.

+
-

Bug Tracker

+

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 to smash it by providing a detailed and welcomed @@ -421,15 +424,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • OpenERP SA
-

Contributors

+

Contributors

- -

Trobz

-
-

Other credits

+

Other credits

The development of this module has been financially supported by:

  • Odoo SA <http://www.odoo.com>
  • @@ -462,7 +469,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
-
diff --git a/document_page/static/src/scss/document_page.scss b/document_page/static/src/scss/document_page.scss index 82cfbaac..eb6200f8 100644 --- a/document_page/static/src/scss/document_page.scss +++ b/document_page/static/src/scss/document_page.scss @@ -1,28 +1,36 @@ -table.diff { - font-family: Courier; - border: medium; +.o_document_page_diff { + table.diff { + font-family: Courier; + border: medium; - .diff_header { - background-color: #e0e0e0; + .diff_header { + background-color: $o_document_page_diff_header_background; + } + + td.diff_header { + text-align: right; + } + + .diff_next { + background-color: $o_document_page_diff_next_background; + } + + .diff_add { + background-color: $o_document_page_diff_add_background; + } + + .diff_chg { + background-color: $o_document_page_diff_change_background; + } + + .diff_sub { + background-color: $o_document_page_diff_subtract_background; + } } - - td.diff_header { - text-align: right; + del { + background-color: $o_document_page_diff_subtract_background; } - - .diff_next { - background-color: #c0c0c0; - } - - .diff_add { - background-color: #aaffaa; - } - - .diff_chg { - background-color: #ffff77; - } - - .diff_sub { - background-color: #ffaaaa; + ins { + background-color: $o_document_page_diff_add_background; } } diff --git a/document_page/static/src/scss/document_page_variables.scss b/document_page/static/src/scss/document_page_variables.scss new file mode 100644 index 00000000..0c4d02fe --- /dev/null +++ b/document_page/static/src/scss/document_page_variables.scss @@ -0,0 +1,5 @@ +$o_document_page_diff_header_background: #e0e0e0; +$o_document_page_diff_next_background: #c0c0c0; +$o_document_page_diff_add_background: #aaffaa; +$o_document_page_diff_change_background: #ffff77; +$o_document_page_diff_subtract_background: #ffaaaa; diff --git a/document_page/tests/test_document_page_history.py b/document_page/tests/test_document_page_history.py index 856be77f..fd2d0390 100644 --- a/document_page/tests/test_document_page_history.py +++ b/document_page/tests/test_document_page_history.py @@ -1,19 +1,48 @@ +from unittest.mock import patch + from odoo.tests import common +from odoo.tools import mute_logger class TestDocumentPageHistory(common.TransactionCase): """document_page_history test class.""" - def test_page_history_demo_page1(self): + def test_old_page_history_demo_page1(self): """Test page history demo page1.""" - page = self.env.ref("document_page.demo_page1") + page = self.env["document.page"].create( + { + "name": "Test Page", + "content": "Initial content", + } + ) 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._get_diff(active_ids[0], active_ids[0]) - self.assertEqual(result, "There are no changes in revisions.") + with ( + patch( + "odoo.addons.document_page.models.document_page_history.html_diff", None + ), + mute_logger("odoo.addons.document_page.models.document_page_history"), + ): + result = history_document._get_diff(active_ids[0], active_ids[0]) + self.assertEqual(result, "There are no changes in revisions.") - result = history_document._get_diff(active_ids[0], active_ids[1]) - self.assertNotEqual(result, "There are no changes in revisions.") + result = history_document._get_diff(active_ids[0], active_ids[1]) + self.assertNotEqual(result, "There are no changes in revisions.") + + def test_new_page_history_demo_page1(self): + """Test page history demo page1.""" + page = self.env["document.page"].create( + { + "name": "Test Page", + "content": "Initial content", + } + ) + 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._get_diff(active_ids[0], active_ids[0]) + self.assertEqual(result, page.content) diff --git a/document_page/tests/test_document_page_show_diff.py b/document_page/tests/test_document_page_show_diff.py index 811c35e7..f3ca0b4a 100644 --- a/document_page/tests/test_document_page_show_diff.py +++ b/document_page/tests/test_document_page_show_diff.py @@ -8,7 +8,12 @@ class TestDocumentPageShowDiff(common.TransactionCase): def test_show_demo_page1_diff(self): """Show test page history difference.""" - page = self.env.ref("document_page.demo_page1") + page = self.env["document.page"].create( + { + "name": "Test Page", + "content": "Initial content", + } + ) show_diff_object = self.env["wizard.document.page.history.show_diff"] diff --git a/document_page/views/document_page_history.xml b/document_page/views/document_page_history.xml index c8353acf..a8bf7cf4 100644 --- a/document_page/views/document_page_history.xml +++ b/document_page/views/document_page_history.xml @@ -69,6 +69,7 @@ diff --git a/test-requirements.txt b/test-requirements.txt index 66bc2cba..e6b7fa24 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ odoo_test_helper +html_diff