[FIX] website: generate routing map without request
This fix allows generating the sitemap (via `website.search_pages`) via RPC. The changes are necessary as since #99667 the `request` object is no more available to RPC-executed functions. See also: the `test_search` test case of `website.tests.test_page`. closes odoo/odoo#104567 X-original-commit: 8f4e214417cfb1aed7e595b8d6ab71f33a347b29 Signed-off-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
@@ -64,7 +64,8 @@ class Http(models.AbstractModel):
|
||||
|
||||
@classmethod
|
||||
def routing_map(cls, key=None):
|
||||
key = key or (request and request.website_routing)
|
||||
if not key and request:
|
||||
key = request.website_routing
|
||||
return super(Http, cls).routing_map(key=key)
|
||||
|
||||
@classmethod
|
||||
@@ -82,6 +83,10 @@ class Http(models.AbstractModel):
|
||||
|
||||
@classmethod
|
||||
def _generate_routing_rules(cls, modules, converters):
|
||||
if not request:
|
||||
yield from super()._generate_routing_rules(modules, converters)
|
||||
return
|
||||
|
||||
website_id = request.website_routing
|
||||
logger.debug("_generate_routing_rules for website: %s", website_id)
|
||||
domain = [('redirect_type', 'in', ('308', '404')), '|', ('website_id', '=', False), ('website_id', '=', website_id)]
|
||||
|
||||
@@ -1098,7 +1098,7 @@ class Website(models.Model):
|
||||
of the same.
|
||||
:rtype: list({name: str, url: str})
|
||||
"""
|
||||
router = http.root.get_db_router(request.db)
|
||||
router = self.env['ir.http'].routing_map()
|
||||
url_set = set()
|
||||
|
||||
sitemap_endpoint_done = set()
|
||||
|
||||
@@ -11,6 +11,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
import threading
|
||||
|
||||
import werkzeug
|
||||
import werkzeug.exceptions
|
||||
@@ -21,6 +22,7 @@ import odoo
|
||||
from odoo import api, http, models, tools, SUPERUSER_ID
|
||||
from odoo.exceptions import AccessDenied, AccessError, MissingError
|
||||
from odoo.http import request, Response, ROUTING_KEYS, Stream
|
||||
from odoo.modules.registry import Registry
|
||||
from odoo.service import security
|
||||
from odoo.tools import consteq, submap
|
||||
from odoo.tools.translate import code_translations
|
||||
@@ -172,7 +174,8 @@ class IrHttp(models.AbstractModel):
|
||||
|
||||
if key not in cls._routing_map:
|
||||
_logger.info("Generating routing map for key %s" % str(key))
|
||||
installed = request.env.registry._init_modules.union(odoo.conf.server_wide_modules)
|
||||
registry = Registry(threading.current_thread().dbname)
|
||||
installed = registry._init_modules.union(odoo.conf.server_wide_modules)
|
||||
if tools.config['test_enable'] and odoo.modules.module.current_test:
|
||||
installed.add(odoo.modules.module.current_test)
|
||||
mods = sorted(installed)
|
||||
|
||||
@@ -85,12 +85,14 @@ class TestHttpMisc(TestHttpBase):
|
||||
]
|
||||
}})
|
||||
|
||||
res = self.nodb_url_open('/jsonrpc', data=payload, headers=CT_JSON)
|
||||
res.raise_for_status()
|
||||
for method in (self.db_url_open, self.nodb_url_open):
|
||||
with self.subTest(method=method.__name__):
|
||||
res = method('/jsonrpc', data=payload, headers=CT_JSON)
|
||||
res.raise_for_status()
|
||||
|
||||
res_rpc = res.json()
|
||||
self.assertNotIn('error', res_rpc.keys(), res_rpc.get('error', {}).get('data', {}).get('message'))
|
||||
self.assertIn(milky_way.name, res_rpc['result'], "QWeb template was correctly rendered")
|
||||
res_rpc = res.json()
|
||||
self.assertNotIn('error', res_rpc.keys(), res_rpc.get('error', {}).get('data', {}).get('message'))
|
||||
self.assertIn(milky_way.name, res_rpc['result'], "QWeb template was correctly rendered")
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
|
||||
Reference in New Issue
Block a user