-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by etobella
- Loading branch information
Showing
19 changed files
with
1,005 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
======================= | ||
Document Page Reference | ||
======================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/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 | ||
:target: https://github.com/OCA/knowledge/tree/15.0/document_page_reference | ||
:alt: OCA/knowledge | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/knowledge-15-0/knowledge-15-0-document_page_reference | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/118/15.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to add a reference name on documents and simplifies the link | ||
between document pages. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
When editing a document page add elements like ${XXX} where XXX is the reference | ||
of another page. Now, when viewing the document, it will link directly to the page. | ||
Also, the name will be parsed as the display name. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20document_page_reference%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Creu Blanca | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Enric Tobella <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px | ||
:target: https://github.com/etobella | ||
:alt: etobella | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-etobella| | ||
|
||
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/15.0/document_page_reference>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2019 Creu Blanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Document Page Reference", | ||
"summary": """ | ||
Include references on document pages""", | ||
"version": "16.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Creu Blanca,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/knowledge", | ||
"depends": ["document_page", "web_editor"], | ||
"data": [ | ||
"views/document_page.xml", | ||
"views/report_document_page.xml", | ||
], | ||
"assets": { | ||
"web.assets_backend": [ | ||
"document_page_reference/static/src/js/**/*", | ||
], | ||
}, | ||
"maintainers": ["etobella"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * document_page_reference | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,field_description:document_page_reference.field_document_page__content_parsed | ||
msgid "Content Parsed" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model,name:document_page_reference.model_document_page | ||
msgid "Document Page" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,field_description:document_page_reference.field_document_page__reference | ||
msgid "Reference" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: code:addons/document_page_reference/models/document_page.py:0 | ||
#, python-format | ||
msgid "Reference is not valid" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: code:addons/document_page_reference/models/document_page.py:0 | ||
#, python-format | ||
msgid "Reference must be unique" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,help:document_page_reference.field_document_page__reference | ||
msgid "Used to find the document, it can contain letters, numbers and _" | ||
msgstr "" | ||
|
||
#. module: document_page_reference | ||
#: model_terms:ir.ui.view,arch_db:document_page_reference.document_page_form_view | ||
msgid "internal_reference (autofilled if not value is provided)" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * document_page_reference | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"PO-Revision-Date: 2023-06-23 10:10+0000\n" | ||
"Last-Translator: mymage <[email protected]>\n" | ||
"Language-Team: none\n" | ||
"Language: it\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
"X-Generator: Weblate 4.17\n" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,field_description:document_page_reference.field_document_page__content_parsed | ||
msgid "Content Parsed" | ||
msgstr "Contenuto analizzato" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model,name:document_page_reference.model_document_page | ||
msgid "Document Page" | ||
msgstr "Pagina documento" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,field_description:document_page_reference.field_document_page__reference | ||
msgid "Reference" | ||
msgstr "Riferimento" | ||
|
||
#. module: document_page_reference | ||
#: code:addons/document_page_reference/models/document_page.py:0 | ||
#, python-format | ||
msgid "Reference is not valid" | ||
msgstr "Il riferimento non è valido" | ||
|
||
#. module: document_page_reference | ||
#: code:addons/document_page_reference/models/document_page.py:0 | ||
#, python-format | ||
msgid "Reference must be unique" | ||
msgstr "Il riferimento deve essere unico" | ||
|
||
#. module: document_page_reference | ||
#: model:ir.model.fields,help:document_page_reference.field_document_page__reference | ||
msgid "Used to find the document, it can contain letters, numbers and _" | ||
msgstr "Utilizzato per trovare il documento, può contenere lettere, numeri e _" | ||
|
||
#. module: document_page_reference | ||
#: model_terms:ir.ui.view,arch_db:document_page_reference.document_page_form_view | ||
msgid "internal_reference (autofilled if not value is provided)" | ||
msgstr "internal_reference (auto compilato se non viene fornito un valore)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import document_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# Copyright 2019 Creu Blanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from odoo import _, api, fields, models, tools | ||
from odoo.exceptions import ValidationError | ||
from odoo.tools.misc import html_escape | ||
|
||
from odoo.addons.http_routing.models.ir_http import slugify | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
try: | ||
import re | ||
|
||
from jinja2 import Undefined | ||
from jinja2.lexer import name_re as old_name_re | ||
from jinja2.sandbox import SandboxedEnvironment | ||
|
||
name_re = re.compile("^%s$" % old_name_re.pattern) | ||
|
||
class Context(SandboxedEnvironment.context_class): | ||
def resolve(self, key): | ||
res = super().resolve(key) | ||
if not isinstance(res, Undefined): | ||
return res | ||
return self.parent["ref"](key) | ||
|
||
class Environment(SandboxedEnvironment): | ||
context_class = Context | ||
|
||
mako_template_env = Environment( | ||
block_start_string="<%", | ||
block_end_string="%>", | ||
variable_start_string="${", | ||
variable_end_string="}", | ||
comment_start_string="<%doc>", | ||
comment_end_string="</%doc>", | ||
line_statement_prefix="%", | ||
line_comment_prefix="##", | ||
trim_blocks=True, # do not output newline after blocks | ||
autoescape=False, | ||
) | ||
except Exception: | ||
_logger.error("Jinja2 is not available") | ||
|
||
|
||
class DocumentPage(models.Model): | ||
|
||
_inherit = "document.page" | ||
|
||
reference = fields.Char( | ||
help="Used to find the document, it can contain letters, numbers and _" | ||
) | ||
content_parsed = fields.Html(compute="_compute_content_parsed") | ||
|
||
def get_formview_action(self, access_uid=None): | ||
res = super().get_formview_action(access_uid) | ||
view_id = self.env.ref("document_page.view_wiki_form").id | ||
res["views"] = [(view_id, "form")] | ||
return res | ||
|
||
@api.depends("history_head") | ||
def _compute_content_parsed(self): | ||
for record in self: | ||
content = record.get_content() | ||
if content == "<p>" and self.content != "<p>": | ||
_logger.error( | ||
"Template from page with id = %s cannot be processed correctly" | ||
% self.id | ||
) | ||
content = self.content | ||
record.content_parsed = content | ||
|
||
@api.constrains("reference") | ||
def _check_reference(self): | ||
for record in self: | ||
if not record.reference: | ||
continue | ||
record._validate_reference(record=record) | ||
|
||
@api.model | ||
def _validate_reference(self, record=None, reference=None): | ||
if not reference: | ||
reference = self.reference | ||
if not name_re.match(reference): | ||
raise ValidationError(_("Reference is not valid")) | ||
uniq_domain = [("reference", "=", reference)] | ||
if record: | ||
uniq_domain += [("id", "!=", record.id)] | ||
if self.search(uniq_domain): | ||
raise ValidationError(_("Reference must be unique")) | ||
|
||
def _get_document(self, code): | ||
# Hook created in order to add check on other models | ||
document = self.search([("reference", "=", code)]) | ||
if document: | ||
return document | ||
else: | ||
return self.env[self._name] | ||
|
||
def get_reference(self, code): | ||
element = self._get_document(code) | ||
if self.env.context.get("raw_reference", False): | ||
return html_escape(element.display_name) | ||
text = """<a href="#" class="oe_direct_line" | ||
data-oe-model="%s" data-oe-id="%s" name="%s">%s</a> | ||
""" | ||
if not element: | ||
text = "<i>%s</i>" % text | ||
res = text % ( | ||
element._name, | ||
element and element.id or "", | ||
code, | ||
html_escape(element.display_name or code), | ||
) | ||
return res | ||
|
||
def _get_template_variables(self): | ||
return {"ref": self.get_reference} | ||
|
||
def get_content(self): | ||
try: | ||
content = self.content | ||
mako_env = mako_template_env | ||
template = mako_env.from_string(tools.ustr(content)) | ||
return template.render(self._get_template_variables()) | ||
except Exception: | ||
_logger.error( | ||
"Template from page with id = %s cannot be processed" % self.id | ||
) | ||
return self.content | ||
|
||
def get_raw_content(self): | ||
return self.with_context(raw_reference=True).get_content() | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
for vals in vals_list: | ||
if not vals.get("reference"): | ||
# Propose a default reference | ||
reference = slugify(vals.get("name")).replace("-", "_") | ||
try: | ||
self._validate_reference(reference=reference) | ||
vals["reference"] = reference | ||
except ValidationError: # pylint: disable=W7938 | ||
# Do not fill reference. | ||
pass | ||
return super(DocumentPage, self).create(vals_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Enric Tobella <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module allows to add a reference name on documents and simplifies the link | ||
between document pages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
When editing a document page add elements like ${XXX} where XXX is the reference | ||
of another page. Now, when viewing the document, it will link directly to the page. | ||
Also, the name will be parsed as the display name. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.