From 80d7cc6c4d40c00f8773faf4ec1ecc0feb634a82 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Tue, 22 Jan 2019 14:04:37 +0000 Subject: [PATCH] publish muk_session_store - 12.0 --- muk_session_store/__manifest__.py | 2 +- muk_session_store/patch/http.py | 175 +++++++++++++++--------------- 2 files changed, 89 insertions(+), 88 deletions(-) diff --git a/muk_session_store/__manifest__.py b/muk_session_store/__manifest__.py index ce8f8a8..3faa16e 100644 --- a/muk_session_store/__manifest__.py +++ b/muk_session_store/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Session Store", "summary": """Session Store Options""", - "version": "12.0.1.0.2", + "version": "12.0.1.0.3", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_session_store/patch/http.py b/muk_session_store/patch/http.py index 56e732a..7518367 100644 --- a/muk_session_store/patch/http.py +++ b/muk_session_store/patch/http.py @@ -1,87 +1,88 @@ -################################################################################### -# -# Copyright (C) 2018 MuK IT GmbH -# -# 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 . -# -################################################################################### - -import random -import logging - -from odoo import http, tools -from odoo.tools.func import lazy_property - -from odoo.addons.muk_utils.tools.patch import monkey_patch -from odoo.addons.muk_session_store.store import postgres -from odoo.addons.muk_session_store.store import redis - -_logger = logging.getLogger(__name__) - -try: - import redis -except ImportError: - if tools.config.get('session_store_redis'): - _logger.warning("The Python library redis is not installed.") - redis = False - -def get_session_store_database(): - return tools.config.get('session_store_dbname', 'session_store') - -@monkey_patch(http) -def db_monodb(httprequest=None): - if tools.config.get('session_store_database'): - httprequest = httprequest or request.httprequest - dbs = http.db_list(True, httprequest) - store = get_session_store_database() - db_session = httprequest.session.db - if db_session in dbs: - return db_session - if store in dbs: - dbs.remove(store) - if len(dbs) == 1: - return dbs[0] - return None - else: - return db_monodb.super(httprequest) - -@monkey_patch(http) -def db_filter(dbs, httprequest=None): - dbs = db_filter.super(dbs, httprequest=httprequest) - store = get_session_store_database() - if store in dbs: - dbs.remove(store) - return dbs - -@monkey_patch(http) -def session_gc(session_store): - if tools.config.get('session_store_database'): - if random.random() < 0.001: - session_store.clean() - elif tools.config.get('session_store_redis'): - pass - else: - session_gc.super(session_store) - -class Root(http.Root): - @lazy_property - def session_store(self): - if tools.config.get('session_store_database'): - return postgres.PostgresSessionStore(session_class=http.OpenERPSession) - elif tools.config.get('session_store_redis') and redis: - return redis.RedisSessionStore(session_class=http.OpenERPSession) - return super(Root, self).session_store - -http.root = Root() - +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# 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 . +# +################################################################################### + +import random +import logging + +from odoo import http, tools +from odoo.http import request +from odoo.tools.func import lazy_property + +from odoo.addons.muk_utils.tools.patch import monkey_patch +from odoo.addons.muk_session_store.store import postgres +from odoo.addons.muk_session_store.store import redis + +_logger = logging.getLogger(__name__) + +try: + import redis +except ImportError: + if tools.config.get('session_store_redis'): + _logger.warning("The Python library redis is not installed.") + redis = False + +def get_session_store_database(): + return tools.config.get('session_store_dbname', 'session_store') + +@monkey_patch(http) +def db_monodb(httprequest=None): + if tools.config.get('session_store_database'): + httprequest = httprequest or request.httprequest + dbs = http.db_list(True, httprequest) + store = get_session_store_database() + db_session = httprequest.session.db + if db_session in dbs: + return db_session + if store in dbs: + dbs.remove(store) + if len(dbs) == 1: + return dbs[0] + return None + else: + return db_monodb.super(httprequest) + +@monkey_patch(http) +def db_filter(dbs, httprequest=None): + dbs = db_filter.super(dbs, httprequest=httprequest) + store = get_session_store_database() + if store in dbs: + dbs.remove(store) + return dbs + +@monkey_patch(http) +def session_gc(session_store): + if tools.config.get('session_store_database'): + if random.random() < 0.001: + session_store.clean() + elif tools.config.get('session_store_redis'): + pass + else: + session_gc.super(session_store) + +class Root(http.Root): + @lazy_property + def session_store(self): + if tools.config.get('session_store_database'): + return postgres.PostgresSessionStore(session_class=http.OpenERPSession) + elif tools.config.get('session_store_redis') and redis: + return redis.RedisSessionStore(session_class=http.OpenERPSession) + return super(Root, self).session_store + +http.root = Root() +