[FIX] web: regard the view_list has valid if not yet loaded
[odoo/odoo.git] / openerp / pooler.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 """ Functions kept for backward compatibility.
23
24     They are simple wrappers around a global RegistryManager methods.
25
26 """
27
28 from openerp.modules.registry import RegistryManager
29
30
31 def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
32     """Create and return a database connection and a newly initialized registry."""
33     registry = RegistryManager.get(db_name, force_demo, status, update_module)
34     return registry.db, registry
35
36
37 def restart_pool(db_name, force_demo=False, status=None, update_module=False):
38     """Delete an existing registry and return a database connection and a newly initialized registry."""
39     registry = RegistryManager.new(db_name, force_demo, status, update_module)
40     return registry.db, registry
41
42 def get_db(db_name):
43     """Return a database connection. The corresponding registry is initialized."""
44     return get_db_and_pool(db_name)[0]
45
46
47 def get_pool(db_name, force_demo=False, status=None, update_module=False):
48     """Return a model registry."""
49     return get_db_and_pool(db_name, force_demo, status, update_module)[1]
50
51 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: