[FIX] website: fix sitemap for multi website
This commit is contained in:
@@ -98,6 +98,7 @@ class Website(openerp.addons.web.controllers.main.Home):
|
||||
|
||||
@http.route('/sitemap.xml', type='http', auth="public", website=True)
|
||||
def sitemap_xml_index(self):
|
||||
current_website = request.website
|
||||
cr, uid, context = request.cr, openerp.SUPERUSER_ID, request.context
|
||||
ira = request.registry['ir.attachment']
|
||||
iuv = request.registry['ir.ui.view']
|
||||
@@ -112,8 +113,8 @@ class Website(openerp.addons.web.controllers.main.Home):
|
||||
name=url,
|
||||
url=url,
|
||||
), context=context)
|
||||
|
||||
sitemap = ira.search_read(cr, uid, [('url', '=' , '/sitemap.xml'), ('type', '=', 'binary')], ('datas', 'create_date'), context=context)
|
||||
dom = [('url', '=' , '/sitemap-%d.xml' % current_website.id), ('type', '=', 'binary')]
|
||||
sitemap = ira.search_read(cr, uid, dom, ('datas', 'create_date'), context=context)
|
||||
if sitemap:
|
||||
# Check if stored version is still valid
|
||||
server_format = openerp.tools.misc.DEFAULT_SERVER_DATETIME_FORMAT
|
||||
@@ -124,7 +125,9 @@ class Website(openerp.addons.web.controllers.main.Home):
|
||||
|
||||
if not content:
|
||||
# Remove all sitemaps in ir.attachments as we're going to regenerated them
|
||||
sitemap_ids = ira.search(cr, uid, [('url', '=like' , '/sitemap%.xml'), ('type', '=', 'binary')], context=context)
|
||||
dom = [('type', '=', 'binary'), '|', ('url', '=like' , '/sitemap-%d-%%.xml' % current_website.id),
|
||||
('url', '=' , '/sitemap-%d.xml' % current_website.id)]
|
||||
sitemap_ids = ira.search(cr, uid, dom, context=context)
|
||||
if sitemap_ids:
|
||||
ira.unlink(cr, uid, sitemap_ids, context=context)
|
||||
|
||||
@@ -139,20 +142,21 @@ class Website(openerp.addons.web.controllers.main.Home):
|
||||
if urls.strip():
|
||||
content = iuv.render(cr, uid, 'website.sitemap_xml', dict(content=urls), context=context)
|
||||
pages += 1
|
||||
last = create_sitemap('/sitemap-%d.xml' % pages, content)
|
||||
last = create_sitemap('/sitemap-%d-%d.xml' % (current_website.id, pages), content)
|
||||
else:
|
||||
break
|
||||
if not pages:
|
||||
return request.not_found()
|
||||
elif pages == 1:
|
||||
ira.write(cr, uid, last, dict(url="/sitemap.xml", name="/sitemap.xml"), context=context)
|
||||
# rename the -id-page.xml => -id.xml
|
||||
ira.write(cr, uid, last, dict(url="/sitemap-%d.xml" % current_website.id, name="/sitemap-%d.xml" % current_website.id), context=context)
|
||||
else:
|
||||
# Sitemaps must be split in several smaller files with a sitemap index
|
||||
content = iuv.render(cr, uid, 'website.sitemap_index_xml', dict(
|
||||
pages=range(1, pages + 1),
|
||||
url_root=request.httprequest.url_root,
|
||||
), context=context)
|
||||
create_sitemap('/sitemap.xml', content)
|
||||
create_sitemap('/sitemap-%d.xml' % current_website.id, content)
|
||||
|
||||
return request.make_response(content, [('Content-Type', mimetype)])
|
||||
|
||||
|
||||
@@ -345,6 +345,7 @@ class PageConverter(werkzeug.routing.PathConverter):
|
||||
query = query and query.startswith('website.') and query[8:] or query
|
||||
if query:
|
||||
domain += [('key', 'like', query)]
|
||||
domain += ['|', ('website_id', '=', request.website.id), ('website_id', '=', False)]
|
||||
|
||||
views = View.search_read(cr, uid, domain, fields=['key', 'priority', 'write_date'], order='name', context=context)
|
||||
for view in views:
|
||||
@@ -353,7 +354,7 @@ class PageConverter(werkzeug.routing.PathConverter):
|
||||
# when we will have an url mapping mechanism, replace this by a rule: page/homepage --> /
|
||||
if xid=='homepage': continue
|
||||
record = {'loc': xid}
|
||||
if view['priority'] <> 16:
|
||||
if view['priority'] != 16:
|
||||
record['__priority'] = min(round(view['priority'] / 32.0,1), 1)
|
||||
if view['write_date']:
|
||||
record['__lastmod'] = view['write_date'][:10]
|
||||
|
||||
Reference in New Issue
Block a user