From e92017023ca87ca274cc541ad98dcd23ffe90d58 Mon Sep 17 00:00:00 2001
From: Enric Tobella
Date: Mon, 15 Dec 2025 09:59:54 +0100
Subject: [PATCH] [IMP] document_page: Use html_diff for checking differences
---
document_page/README.rst | 27 ++++++--
document_page/__manifest__.py | 3 +
document_page/models/document_page_history.py | 17 ++++-
document_page/readme/CONTRIBUTORS.md | 7 +-
document_page/readme/USAGE.md | 5 ++
document_page/static/description/index.html | 64 ++++++++++---------
.../static/src/scss/document_page.scss | 54 +++++++++-------
.../src/scss/document_page_variables.scss | 5 ++
.../tests/test_document_page_history.py | 41 ++++++++++--
.../tests/test_document_page_show_diff.py | 7 +-
document_page/views/document_page_history.xml | 1 +
test-requirements.txt | 1 +
12 files changed, 162 insertions(+), 70 deletions(-)
create mode 100644 document_page/static/src/scss/document_page_variables.scss
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
-
-
-
-
-
-
Document Page
-

+

This module allows you to write web pages for internal documentation.
Table of contents
-
+
This module depends on module knowledge. So make sure to have it in your
addons list.
-
+
No configuration required.
-
+
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
+
+
+
If you want to improve how history is shown, you can install html_diff
+python library. A new comparison method will be installed.
+
-
+
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.
-
+
-
+
-
-
Trobz
-
+- Trobz
+
- Sygel:
- Ángel García de la Chica Herrera
+- Dixmit:
+
-
+
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
-