Browse Source

publish muk_session_store - 11.0

pull/6/head
MuK IT GmbH 6 years ago
parent
commit
5da863e3b4
  1. 3
      muk_session_store/__manifest__.py
  2. 174
      muk_session_store/patch/http.py

3
muk_session_store/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Session Store",
"summary": """Session Store Options""",
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"category": "Extra Tools",
"license": "AGPL-3",
"website": "http://www.mukit.at",
@ -44,7 +44,6 @@
"python": [],
"bin": [],
},
"auto_install": True,
"application": False,
"installable": True,
"post_load": "_patch_system",

174
muk_session_store/patch/http.py

@ -1,87 +1,87 @@
###################################################################################
#
# 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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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:
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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()
Loading…
Cancel
Save