From 96d3fa4e01bf8afc35dbf0b7301ce75c6bf3a5c7 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 4 Feb 2020 18:17:45 +0000 Subject: [IMP] base, website: add ir.ui.view action to compare arch (wizard) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds the possibility to compare a view arch to another one. The result will be shown in a diff viewer (github like). This is following what was done at #32009 task-2190072 closes odoo/odoo#44646 Signed-off-by: Jérémy Kersten (jke) --- odoo/tools/misc.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'odoo/tools/misc.py') diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 534493afa95..b19e3b44923 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -29,6 +29,7 @@ import unicodedata import werkzeug.utils import zipfile from collections import defaultdict, Iterable, Mapping, MutableMapping, MutableSet, OrderedDict +from difflib import HtmlDiff from itertools import islice, groupby as itergroupby, repeat from lxml import etree @@ -1470,3 +1471,48 @@ class DotDict(dict): def __getattr__(self, attrib): val = self.get(attrib) return DotDict(val) if type(val) is dict else val + + +def get_diff(data_from, data_to, custom_style=False): + """ + Return, in an HTML table, the diff between two texts. + + :param tuple data_from: tuple(text, name), name will be used as table header + :param tuple data_to: tuple(text, name), name will be used as table header + :param tuple custom_style: string, style css including + ''' + return html_diff + + diff = HtmlDiff(tabsize=2).make_table( + data_from[0].splitlines(), + data_to[0].splitlines(), + data_from[1], + data_to[1], + context=True, # Show only diff lines, not all the code + numlines=3, + ) + return handle_style(diff, custom_style) -- cgit v1.2.3