|
3 | 3 |
|
4 | 4 | import logging |
5 | 5 |
|
| 6 | +from markupsafe import Markup |
| 7 | + |
6 | 8 | from odoo import _, api, fields, models, tools |
7 | 9 | from odoo.exceptions import ValidationError |
8 | 10 | from odoo.tools.misc import html_escape |
@@ -52,25 +54,53 @@ class DocumentPage(models.Model): |
52 | 54 | reference = fields.Char( |
53 | 55 | help="Used to find the document, it can contain letters, numbers and _" |
54 | 56 | ) |
55 | | - content_parsed = fields.Html(compute="_compute_content_parsed") |
| 57 | + content_parsed = fields.Html(compute="_compute_content_parsed", sanitize=False) |
| 58 | + |
| 59 | + def _get_page_index(self, link=True): |
| 60 | + """Override to use oe_direct_line links compatible with the widget.""" |
| 61 | + self.ensure_one() |
| 62 | + index = [ |
| 63 | + Markup("<li>") + subpage._get_page_index() + Markup("</li>") |
| 64 | + for subpage in self.child_ids |
| 65 | + ] |
| 66 | + r = Markup("") |
| 67 | + if link: |
| 68 | + r = ( |
| 69 | + Markup( |
| 70 | + '<a href="#" class="oe_direct_line"' |
| 71 | + ' data-oe-model="%s" data-oe-id="%s">' |
| 72 | + ) |
| 73 | + % ( |
| 74 | + self._name, |
| 75 | + self.id, |
| 76 | + ) |
| 77 | + + html_escape(self.name) |
| 78 | + + Markup("</a>") |
| 79 | + ) |
| 80 | + if index: |
| 81 | + r += Markup("<ul>") + Markup("").join(index) + Markup("</ul>") |
| 82 | + return r |
56 | 83 |
|
57 | 84 | def get_formview_action(self, access_uid=None): |
58 | 85 | res = super().get_formview_action(access_uid) |
59 | 86 | view_id = self.env.ref("document_page.view_wiki_form").id |
60 | 87 | res["views"] = [(view_id, "form")] |
61 | 88 | return res |
62 | 89 |
|
63 | | - @api.depends("history_head") |
| 90 | + @api.depends("history_head", "type") |
64 | 91 | def _compute_content_parsed(self): |
65 | 92 | for record in self: |
66 | | - content = record.get_content() |
67 | | - if content == "<p>" and self.content != "<p>": |
68 | | - _logger.error( |
69 | | - "Template from page with id = %s cannot be processed correctly" |
70 | | - % self.id |
71 | | - ) |
72 | | - content = self.content |
73 | | - record.content_parsed = content |
| 93 | + if record.type == "category": |
| 94 | + record.content_parsed = record.content |
| 95 | + else: |
| 96 | + content = record.get_content() |
| 97 | + if content == "<p>" and record.content != "<p>": |
| 98 | + _logger.error( |
| 99 | + "Template from page with id = %s cannot be " |
| 100 | + "processed correctly" % record.id |
| 101 | + ) |
| 102 | + content = record.content |
| 103 | + record.content_parsed = content |
74 | 104 |
|
75 | 105 | @api.constrains("reference") |
76 | 106 | def _check_reference(self): |
|
0 commit comments