From 864c0a000cf0758d4b3243125386822ab3cfcdf5 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 Odoo HTML Diff comparison method
---
document_page/README.rst | 27 ++++++--
document_page/__manifest__.py | 5 +-
document_page/models/document_page_history.py | 27 ++------
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 | 58 ++++++++++-------
.../src/scss/document_page_variables.scss | 5 ++
document_page/tests/test_document_page.py | 14 ++--
.../tests/test_document_page_history.py | 15 +++--
.../tests/test_document_page_show_diff.py | 11 +++-
document_page/views/document_page_history.xml | 1 +
.../wizard/document_page_show_diff.py | 2 +-
13 files changed, 143 insertions(+), 98 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..ed698709 100644
--- a/document_page/__manifest__.py
+++ b/document_page/__manifest__.py
@@ -17,7 +17,7 @@
],
"website": "https://github.com/OCA/knowledge",
"license": "AGPL-3",
- "depends": ["mail", "document_knowledge"],
+ "depends": ["mail", "document_knowledge", "web_editor"],
"data": [
"security/document_page_security.xml",
"security/ir.model.access.csv",
@@ -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..ef39b3d6 100644
--- a/document_page/models/document_page_history.py
+++ b/document_page/models/document_page_history.py
@@ -1,10 +1,13 @@
# Copyright (C) 2004-2010 Tiny SPRL ().
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-import difflib
from odoo import api, fields, models
+from odoo.addons.web_editor.models.diff_utils import (
+ generate_comparison,
+)
+
class DocumentPageHistory(models.Model):
"""This model is necessary to manage a document history."""
@@ -17,7 +20,7 @@ class DocumentPageHistory(models.Model):
name = fields.Char(index=True)
summary = fields.Char(index=True)
content = fields.Html(sanitize=False)
- diff = fields.Html(compute="_compute_diff")
+ diff = fields.Html(compute="_compute_diff", sanitize_tags=False)
company_id = fields.Many2one(
"res.company",
@@ -43,28 +46,10 @@ 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 ""
- # Include line breaks to make it more readable
- # TODO: consider using a beautify library directly on the content
- text1 = text1.replace("
", "
\r\n")
- text2 = text2.replace("
", "
\r\n")
- line1 = text1.splitlines(True)
- line2 = text2.splitlines(True)
- if line1 == line2:
- return self.env._("There are no changes in revisions.")
- else:
- diff = difflib.HtmlDiff()
- return diff.make_table(
- line1,
- line2,
- f"Revision-{v1}",
- f"Revision-{v2}",
- context=True,
- )
+ return generate_comparison(text1, text2)
@api.depends("page_id")
def _compute_display_name(self):
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
-