[IMP] document_page: black, isort

This commit is contained in:
ernesto
2019-11-06 17:58:38 -05:00
committed by FernandoRomera
parent dda7a9b99a
commit 713f34f9f1
10 changed files with 189 additions and 217 deletions

View File

@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import difflib
from odoo import api, fields, models
from odoo.tools.translate import _
@@ -11,19 +12,19 @@ class DocumentPageHistory(models.Model):
_name = "document.page.history"
_description = "Document Page History"
_order = 'id DESC'
_order = "id DESC"
page_id = fields.Many2one('document.page', 'Page', ondelete='cascade')
page_id = fields.Many2one("document.page", "Page", ondelete="cascade")
name = fields.Char(index=True)
summary = fields.Char(index=True)
content = fields.Text()
diff = fields.Text(compute='_compute_diff')
diff = fields.Text(compute="_compute_diff")
company_id = fields.Many2one(
'res.company',
'Company',
help='If set, page is accessible only from this company',
related='page_id.company_id',
"res.company",
"Company",
help="If set, page is accessible only from this company",
related="page_id.company_id",
store=True,
index=True,
readonly=True,
@@ -32,13 +33,16 @@ class DocumentPageHistory(models.Model):
@api.multi
def _compute_diff(self):
"""Shows a diff between this version and the previous version"""
history = self.env['document.page.history']
history = self.env["document.page.history"]
for rec in self:
prev = history.search([
('page_id', '=', rec.page_id.id),
('create_date', '<', rec.create_date)],
prev = history.search(
[
("page_id", "=", rec.page_id.id),
("create_date", "<", rec.create_date),
],
limit=1,
order='create_date DESC')
order="create_date DESC",
)
if prev:
rec.diff = self._get_diff(prev.id, rec.id)
else:
@@ -47,23 +51,24 @@ class DocumentPageHistory(models.Model):
@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 ''
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('</p><p>', '</p>\r\n<p>')
text2 = text2.replace('</p><p>', '</p>\r\n<p>')
text1 = text1.replace("</p><p>", "</p>\r\n<p>")
text2 = text2.replace("</p><p>", "</p>\r\n<p>")
line1 = text1.splitlines(True)
line2 = text2.splitlines(True)
if line1 == line2:
return _('There are no changes in revisions.')
return _("There are no changes in revisions.")
else:
diff = difflib.HtmlDiff()
return diff.make_table(
line1, line2,
line1,
line2,
"Revision-{}".format(v1),
"Revision-{}".format(v2),
context=True
context=True,
)
@api.multi