diff options
| author | Jeremy Kersten <jke@odoo.com> | 2017-09-27 19:23:05 +0200 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2017-09-27 21:33:49 +0200 |
| commit | 1b52b00d2aa96b9360d50a0f0960f1febb5e607e (patch) | |
| tree | 2e098cf6268b0c2fe6d2844e94b45cc801ce4093 /addons/website_customer/controllers | |
| parent | 3d0d8b89d1e7a32a5ef8aa0f40d41a4fb5260c1c (diff) | |
[IMP] website*: clean sitemap + add method to declare sitemap function.
Don't add useless routes or route that will return 404.
Improve generate function from ModelConverter to have a better management of
query_string.
Now we have an helper sitemap_qs2dom that will analyse the current route and
check if query string is plausible and if yes, generate a domain, when the
query_string don't seems to match the route, we return a Falsy domain.
Before this commit, if qs was /product/ipad, enumerate_page check for each
modelconverter of the route a name ilike '/product/ipad'.
Now we check all routes that contains product and one converter that match ipad
or routes that contains ipad and one converter that match product.
This commit a new way to declare the sitemap for a route.
def sitemap_xx(env, rule, query_string):
yield {'loc': '/my_url'}
@http.route(..., sitemap=sitemap_xx)
In this case, only the loc returned by this function will be in the sitemap
for all rules.
You can pass sitempa=False, if you don't want that route are into the sitemap
Diffstat (limited to 'addons/website_customer/controllers')
| -rw-r--r-- | addons/website_customer/controllers/main.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/addons/website_customer/controllers/main.py b/addons/website_customer/controllers/main.py index 480bb62c4d4..421a809b36d 100644 --- a/addons/website_customer/controllers/main.py +++ b/addons/website_customer/controllers/main.py @@ -4,7 +4,8 @@ import werkzeug.urls from odoo import http -from odoo.addons.http_routing.models.ir_http import unslug +from odoo.addons.http_routing.models.ir_http import unslug, slug +from odoo.addons.website.models.ir_http import sitemap_qs2dom from odoo.tools.translate import _ from odoo.http import request @@ -12,6 +13,25 @@ from odoo.http import request class WebsiteCustomer(http.Controller): _references_per_page = 20 + def sitemap_industry(env, rule, qs): + if not qs or qs.lower() in '/customers': + yield {'loc': '/customers'} + + Industry = env['res.partner.industry'] + dom = sitemap_qs2dom(qs, '/customers/industry', Industry._rec_name) + for industry in Industry.search(dom): + loc = '/customers/industry/%s' % slug(industry) + if not qs or qs.lower() in loc: + yield {'loc': loc} + + dom = [('website_published', '=', True), ('assigned_partner_id', '!=', False)] + dom += sitemap_qs2dom(qs, '/customers/country') + countries = env['res.partner'].sudo().read_group(dom, ['id', 'country_id'], groupby='country_id') + for country in countries: + loc = '/customers/country/%s' % slug(country['country_id']) + if not qs or qs.lower() in loc: + yield {'loc': loc} + @http.route([ '/customers', '/customers/page/<int:page>', @@ -21,7 +41,7 @@ class WebsiteCustomer(http.Controller): '/customers/industry/<model("res.partner.industry"):industry>/page/<int:page>', '/customers/industry/<model("res.partner.industry"):industry>/country/<model("res.country"):country>', '/customers/industry/<model("res.partner.industry"):industry>/country/<model("res.country"):country>/page/<int:page>', - ], type='http', auth="public", website=True) + ], type='http', auth="public", website=True, sitemap=sitemap_industry) def customers(self, country=None, industry=None, page=0, **post): Tag = request.env['res.partner.tag'] Partner = request.env['res.partner'] |
