I want to share local directory on my apps. Found load_addons definition in http.Root class, append in statics['/shared_folder'] = '/home/shared_folder' that is work but, override load_addons function with monkey_patch like this
# -- coding: utf-8 --
import ast
import logging
import odoo
import os
import werkzeug
from odoo import http, tools
from odoo.modules.module import module_manifest
from odoo.tools import ustr, consteq, frozendict, pycompat, unique, date_utils
from os.path import join as opj
import mock
logger = logging.getLogger(name_)
STATIC_CACHE = 60 * 60 * 24 * 7
addons_manifest = {}
def load_addons():
""" Load all addons from addons path containing static files and
controllers and configure them. """
# TODO should we move this to ir.http so that only configured modules are served ?
statics = {}
for addons_path in odoo.modules.module.ad_paths:
for module in sorted(os.listdir(str(addons_path))):
if module not in addons_manifest:
mod_path = opj(addons_path, module)
manifest_path = module_manifest(mod_path)
path_static = opj(addons_path, module, 'static')
if manifest_path and os.path.isdir(path_static):
manifest_data = open(manifest_path, 'rb').read()
manifest = ast.literal_eval(pycompat.to_native(manifest_data))
if not manifest.get('installable', True):
continue
manifest['addons_path'] = addons_path
_logger.debug("Loading %s", module)
addons_manifest[module] = manifest
statics['/%s/static' % module] = path_static
statics['/shared_files'] = opj(odoo.tools.config.options['data_dir'], 'shared_files')
if statics:
_logger.info("HTTP Configuring static files")
app = werkzeug.wsgi.SharedDataMiddleware(http.Root.dispatch, statics, cache_timeout=STATIC_CACHE)
http.Root.dispatch = http.DisableCacheMiddleware(app)
with mock.patch.object(http.Root, 'load_addons', load_addons):
http.root
but doesnt work. How to override this function in my apps.