Odoo运行机制(三)----模块加载

本文深入探讨了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库', '图表绘制', '数据分析']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值