Odoo URL解析
openerp.http.Root
Root类是 OpenERP Web客户端的WSGI应用,处理HTTP请求的接口为__call__()
def __call__(self, environ, start_response):
""" Handle a WSGI request
"""
if not self._loaded:
self._loaded = True
self.load_addons()
return self.dispatch(environ, start_response)
可见,dispatch()是处理HTTP请求的核心方法
def dispatch(self, environ, start_response):
"""
Performs the actual WSGI dispatching for the application.
"""
try:
httprequest = werkzeug.wrappers.Request(environ)
httprequest.app = self
explicit_session = self.setup_session(httprequest)
self.setup_db(httprequest)
self.setup_lang(httprequest)
request = self.get_request(httprequest)
def _dispatch_nodb():
try:
func, arguments = self.nodb_routing_map.bind_to_environ(request.httprequest.environ).match()
except werkzeug.exceptions.HTTPException, e:
return request._handle_exception(e)
request.set_handler(func, arguments, "none")
result = request.dispatch()
return result
with request:
db = request.session.db
if db:
openerp.modules.registry.RegistryManager.check_registry_signaling(db)
try:
with openerp.tools.mute_logger('openerp.sql_db'):
ir_http = request.registry['ir.http']
except (AttributeError, psycopg2.OperationalError):
# psycopg2 error or attribute error while constructing
# the registry. That means the database probably does
# not exists anymore or the code doesnt match the db.
# Log the user out and fall back to nodb
request.session.logout()
result = _dispatch_nodb()
else:
result = ir_http._dispatch()
openerp.modules.registry.RegistryManager.signal_caches_change(db)
else:
result = _dispatch_nodb()
response = self.get_response(httprequest, result, explicit_session)
return response(environ, start_response)
except werkzeug.exceptions.HTTPException, e:
return e(environ, s

本文深入探讨了Odoo的URL解析过程,从openerp.http.Root类的dispatch()方法开始,详细介绍了如何恢复或创建session,以及如何处理HTTP请求。接着,文章聚焦于Odoo的模块加载流程,包括request.registry的使用,load_modules函数的作用,以及load_module_graph(), load_openerp_module(), init_module_models()和build_model()等关键步骤在模块加载中的作用。"
105100133,9252322,Python进阶:Matplotlib数据可视化实战,"['Python编程', '数据可视化', 'Matplotlib库', '图表绘制', '数据分析']
最低0.47元/天 解锁文章
1127

被折叠的 条评论
为什么被折叠?



