-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11.0 Improvement for filters and product page description #14
Changes from all commits
e142183
815a1d5
bae02f8
7b2909a
2c4408a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,28 @@ | |
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, fields, models | ||
from odoo import tools | ||
import lxml | ||
|
||
|
||
def urljoin(*args): | ||
""" | ||
Joins given arguments into an url. Trailing but not leading slashes are | ||
stripped for each argument. | ||
""" | ||
|
||
return "/".join(map(lambda x: str(x).rstrip('/'), args)) | ||
|
||
|
||
def hook_github_image_url(rst_desc, github_url): | ||
html_node = lxml.html.fromstring(rst_desc) | ||
github_url = github_url.replace('/tree/', '/blob/') | ||
for node in html_node.xpath('//img'): | ||
if not node.attrib['src'].startswith("/"): | ||
continue | ||
node.attrib['src'] = urljoin( | ||
github_url, '/'.join(node.attrib['src'].split("/")[2:]), | ||
'?raw=true') | ||
return lxml.html.tostring(html_node) | ||
|
||
|
||
class ProductProduct(models.Model): | ||
|
@@ -32,8 +54,8 @@ class ProductProduct(models.Model): | |
) | ||
app_description_rst_html = fields.Html( | ||
'HTML of the RST Description', | ||
compute='_compute_app_description_rst_html', | ||
readonly=True, | ||
related="odoo_module_version_id.description_rst_html", | ||
store=True, | ||
) | ||
app_version = fields.Char( | ||
|
@@ -57,6 +79,17 @@ class ProductProduct(models.Model): | |
store=True, | ||
) | ||
|
||
@api.depends('odoo_module_version_id', | ||
'odoo_module_version_id.description_rst_html') | ||
@api.multi | ||
def _compute_app_description_rst_html(self): | ||
for product in self: | ||
rst_desc = product.odoo_module_version_id.description_rst_html | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elicoidal yes it will. confirmed with https://github.com/OCA/server-tools/blob/11.0/base_fontawesome/ module and it is working |
||
if rst_desc and '<img' in rst_desc: | ||
rst_desc = hook_github_image_url( | ||
rst_desc, product.app_github_url) | ||
product.app_description_rst_html = rst_desc | ||
|
||
@api.model | ||
def create(self, values): | ||
self._manage_product_module(values) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
hook_
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is literally processing the URL and adding GitHub module prefix URL for display purpose.