From 2b91a25359e19605631369855d3a05f8e1656d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 12 Jul 2014 12:19:38 +0200 Subject: [PATCH] port dbfilter_from_header to 8.0 --- .../__init__.py | 21 ++++++++++++------- .../__openerp__.py | 0 .../i18n/dbfilter_from_header.pot | 0 3 files changed, 14 insertions(+), 7 deletions(-) rename {__unported__/dbfilter_from_header => dbfilter_from_header}/__init__.py (65%) rename {__unported__/dbfilter_from_header => dbfilter_from_header}/__openerp__.py (100%) rename {__unported__/dbfilter_from_header => dbfilter_from_header}/i18n/dbfilter_from_header.pot (100%) diff --git a/__unported__/dbfilter_from_header/__init__.py b/dbfilter_from_header/__init__.py similarity index 65% rename from __unported__/dbfilter_from_header/__init__.py rename to dbfilter_from_header/__init__.py index 00ccc56d5..5f8b01ec0 100644 --- a/__unported__/dbfilter_from_header/__init__.py +++ b/dbfilter_from_header/__init__.py @@ -3,6 +3,7 @@ # # OpenERP, Open Source Management Solution # This module copyright (C) 2013 Therp BV (). +# This module copyright (C) 2014 ACSONE SA/NV (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,13 +20,19 @@ # ############################################################################## import re -from openerp.addons.web.controllers import main as web_main +from openerp import http -db_list_org = web_main.db_list +db_filter_org = http.db_filter -def db_list(req, force=False): - db_filter = req.httprequest.environ.get('HTTP_X_OPENERP_DBFILTER', '.*') - dbs = db_list_org(req, force=force) - return [db for db in dbs if re.match(db_filter, db)] -web_main.db_list = db_list +def db_filter(dbs, httprequest=None): + dbs = db_filter_org(dbs, httprequest) + httprequest = httprequest or http.request.httprequest + db_filter_hdr = \ + httprequest.environ.get('HTTP_X_ODOO_DBFILTER') or \ + httprequest.environ.get('HTTP_X_OPENERP_DBFILTER') + if db_filter_hdr: + dbs = [db for db in dbs if re.match(db_filter_hdr, db)] + return dbs + +http.db_filter = db_filter diff --git a/__unported__/dbfilter_from_header/__openerp__.py b/dbfilter_from_header/__openerp__.py similarity index 100% rename from __unported__/dbfilter_from_header/__openerp__.py rename to dbfilter_from_header/__openerp__.py diff --git a/__unported__/dbfilter_from_header/i18n/dbfilter_from_header.pot b/dbfilter_from_header/i18n/dbfilter_from_header.pot similarity index 100% rename from __unported__/dbfilter_from_header/i18n/dbfilter_from_header.pot rename to dbfilter_from_header/i18n/dbfilter_from_header.pot