Skip to content
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

Merged
merged 5 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion apps_product_creator/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hook_?

Copy link
Author

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.

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):
Expand Down Expand Up @@ -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(
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that description_rst_html will already contain either html if exist or rst as fallback.
Do you confirm?

Copy link
Author

Choose a reason for hiding this comment

The 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)
Expand Down
17 changes: 0 additions & 17 deletions website_apps_store/static/src/js/website_apps_store_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,6 @@ var base = require("web_editor.base");
]
);

Tour.register('select_author_search', {
name: "Select Author",
url: '/shop',
test: true,
wait_for: base.ready()
},[
{
content: "Shop",
trigger: ".dropdown_author_by a.dropdown-toggle"
},
{
content: "Select Author",
trigger: ".dropdown_author_by .dropdown-menu a:first",
},
]
);

Tour.register('select_category_search', {
name: "Select Category",
url: '/shop',
Expand Down
8 changes: 0 additions & 8 deletions website_apps_store/tests/test_tour_website_apps_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ def test_select_version_search_tour(self):
login="admin"
)

def test_select_author_search_tour(self):
self.phantom_js(
"/shop",
self.tour + ".run('select_author_search')",
self.tour + ".tours.select_author_search.ready",
login="admin"
)

def test_select_category_search_tour(self):
self.phantom_js(
"/shop",
Expand Down
21 changes: 3 additions & 18 deletions website_apps_store/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li t-att-class="'active' if not version else None">
<a t-att-href="keep('/shop', version='')">All</a>
</li>
<t t-foreach="versions" t-as="v">
<li t-att-class="'active' if v.id == int(version or 0) else None">
<a t-att-href="keep('/shop', version=v.id)">
Expand All @@ -38,29 +41,11 @@
</ul>
</div>
</template>
<template id="author_display" name="Show Author by">
<div class="dropdown btn-group dropdown_author_by">
<a href="#" class="dropdown-toggle btn btn-default" data-toggle="dropdown">
<span>Author</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<t t-foreach="authors" t-as="auth_id">
<li t-att-class="'active' if auth_id.id == int(author or 0) else None">
<a t-att-href="keep('/shop', author=auth_id.id)">
<span t-esc="auth_id.name"/>
</a>
</li>
</t>
</ul>
</div>
</template>

<template id="sort_customize" inherit_id="website_sale.sort">
<xpath expr='//div[hasclass("dropdown_sorty_by")]' position="after">
<t t-call="website_apps_store.category_display"/>
<t t-call="website_apps_store.version_display"/>
<t t-call="website_apps_store.author_display"/>
</xpath>
</template>

Expand Down