69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
##############################################################################
|
|
#
|
|
# OpenERP, Open Source Management Solution
|
|
# Copyright (C) 20014-2016 Camadeus GmbH (<http://www.camadeus.at>).
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
##############################################################################
|
|
|
|
import re
|
|
import openerp
|
|
from openerp.tools.translate import _
|
|
from openerp.tools import config
|
|
|
|
from openerp.addons.web import http
|
|
from openerp.addons.web.controllers.main import Home
|
|
from openerp.http import request
|
|
|
|
class Home_Debug(Home):
|
|
|
|
@http.route('/', type='http', auth="none")
|
|
def index(self, s_action=None, db=None, **kw):
|
|
|
|
# Check arguments
|
|
if openerp.tools.config.get('show_debug', False):
|
|
return http.local_redirect('/web?debug=1', query=request.params, keep_hash=True)
|
|
else:
|
|
return http.local_redirect('/web', query=request.params, keep_hash=True)
|
|
|
|
class WebClient(http.Controller):
|
|
_cp_path = "/web/testenv"
|
|
|
|
@http.jsonrequest
|
|
def testmode(self, req, db=False):
|
|
if not db and req and req.session:
|
|
db = req.session._db
|
|
|
|
if db:
|
|
h = req.httprequest.environ['HTTP_HOST'].split(':')[0]
|
|
d = h.split('.')[0]
|
|
r = openerp.tools.config.get('dbfilter_test', 'test.*').replace('%h', h).replace('%d', d)
|
|
try:
|
|
pattern_list = eval(r)
|
|
if not hasattr(pattern_list, '__iter__'):
|
|
pattern_list = [pattern_list]
|
|
except:
|
|
pattern_list = [r]
|
|
|
|
for pattern in pattern_list:
|
|
if isinstance(pattern, str) and re.match(pattern, db):
|
|
return True
|
|
return False
|
|
|
|
|
|
|
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|