From 553d572887a9954318225bf652e215a8cc503431 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Wed, 20 May 2020 20:42:22 +0200 Subject: [PATCH] [12.0][PORT] server_environment. port static files controllers from server-tools 8.0 branch --- server_environment/__init__.py | 1 + server_environment/__manifest__.py | 2 +- server_environment/controllers/__init__.py | 1 + server_environment/controllers/main.py | 30 +++++++++++++++++++ server_environment/readme/CONFIGURE.rst | 25 ++++++++++++++++ server_environment/readme/CONTRIBUTORS.rst | 1 + .../__manifest__.py | 8 +++-- .../readme/CONTRIBUTORS.rst | 1 + .../static/preprod/web_login.css | 3 ++ .../static/prod/web_login.css | 0 .../static/test/web_login.css | 3 ++ .../views/templates.xml | 16 ++++++++++ 12 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 server_environment/controllers/__init__.py create mode 100644 server_environment/controllers/main.py create mode 100644 server_environment_files_sample/static/preprod/web_login.css create mode 100644 server_environment_files_sample/static/prod/web_login.css create mode 100644 server_environment_files_sample/static/test/web_login.css create mode 100644 server_environment_files_sample/views/templates.xml diff --git a/server_environment/__init__.py b/server_environment/__init__.py index aab9a42..689a5aa 100644 --- a/server_environment/__init__.py +++ b/server_environment/__init__.py @@ -18,6 +18,7 @@ # ############################################################################## from . import models +from . import controllers # TODO when migrating to 12, fix the import of serv_config by renaming the # file? # Add an alias to access to the 'serv_config' module as it is shadowed diff --git a/server_environment/__manifest__.py b/server_environment/__manifest__.py index 38fbb9d..29f741a 100644 --- a/server_environment/__manifest__.py +++ b/server_environment/__manifest__.py @@ -9,7 +9,7 @@ "base", "base_sparse_field", ], - "author": "Camptocamp,Odoo Community Association (OCA)", + "author": "Camptocamp,GRAP,Odoo Community Association (OCA)", "summary": "move some configurations out of the database", "website": "http://github.com/OCA/server-env", "license": "GPL-3 or any later version", diff --git a/server_environment/controllers/__init__.py b/server_environment/controllers/__init__.py new file mode 100644 index 0000000..12a7e52 --- /dev/null +++ b/server_environment/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/server_environment/controllers/main.py b/server_environment/controllers/main.py new file mode 100644 index 0000000..318ee40 --- /dev/null +++ b/server_environment/controllers/main.py @@ -0,0 +1,30 @@ +# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from werkzeug.utils import redirect +from urllib.parse import urljoin + +from odoo.tools.config import config +from odoo import http +from odoo.http import request, Controller + + +class ServerEnvironmentController(Controller): + + @http.route( + '/server_environment_' + '/static/RUNNING_ENV/', + type='http', auth='public') + def environment_redirect(self, module_extension, local_path, **kw): + # Note: module_extension is present to make working + # the module in normal configuration, with the folder + # server_environment_files and in demo configuration, with the + # module server_environment_files_sample + running_env = config.get('running_env', "default") + IrConfigParameter = request.env['ir.config_parameter'].sudo() + base_url = IrConfigParameter.get_param('web.base.url', '') + new_path = "/server_environment_%s/static/%s/%s" % ( + module_extension, running_env, local_path) + url = urljoin(base_url, new_path) + return redirect(url, 303) diff --git a/server_environment/readme/CONFIGURE.rst b/server_environment/readme/CONFIGURE.rst index 6610f44..0871e14 100644 --- a/server_environment/readme/CONFIGURE.rst +++ b/server_environment/readme/CONFIGURE.rst @@ -89,3 +89,28 @@ Keychain integration Read the documentation of the class `models/server_env_mixin.py `_. + + + +Loading static files +-------------------- + +This module provides also the possibility to load static files depending +on the environment. + +Create a file view/templates.xml, and insert a css file +:: + + + +Then, create css files for each environment you have. exemple: +:: + /server_environment_files/static/dev/css.css + /server_environment_files/static/prod/css.css + ... diff --git a/server_environment/readme/CONTRIBUTORS.rst b/server_environment/readme/CONTRIBUTORS.rst index 4d64e67..3640a46 100644 --- a/server_environment/readme/CONTRIBUTORS.rst +++ b/server_environment/readme/CONTRIBUTORS.rst @@ -9,3 +9,4 @@ * Guewen Baconnier * Thomas Binfeld * Stéphane Bidoul +* Sylvain LE GAL (https://www.twitter.com/legalsylvain) diff --git a/server_environment_files_sample/__manifest__.py b/server_environment_files_sample/__manifest__.py index 6c2b0f6..b2992a7 100644 --- a/server_environment_files_sample/__manifest__.py +++ b/server_environment_files_sample/__manifest__.py @@ -5,11 +5,13 @@ { "name": "Example server configuration environment files repository module", "version": "12.0.1.0.1", - "depends": ["base"], - "author": "Camptocamp,Odoo Community Association (OCA)", + "depends": ["server_environment", "web"], + "author": "Camptocamp,GRAP,Odoo Community Association (OCA)", "summary": "sample config file for server_environment", "website": "http://github.com/OCA/server-env", "license": "GPL-3 or any later version", "category": "Tools", - "data": [], + "data": [ + 'views/templates.xml', + ], } diff --git a/server_environment_files_sample/readme/CONTRIBUTORS.rst b/server_environment_files_sample/readme/CONTRIBUTORS.rst index 838bdbd..c205868 100644 --- a/server_environment_files_sample/readme/CONTRIBUTORS.rst +++ b/server_environment_files_sample/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Florent Xicluna (Wingo) * Nicolas Bessi +* Sylvain LE GAL (https://www.twitter.com/legalsylvain) diff --git a/server_environment_files_sample/static/preprod/web_login.css b/server_environment_files_sample/static/preprod/web_login.css new file mode 100644 index 0000000..67c7c27 --- /dev/null +++ b/server_environment_files_sample/static/preprod/web_login.css @@ -0,0 +1,3 @@ +body .bg-100{ + background-color:#AAFFAA !important; +} diff --git a/server_environment_files_sample/static/prod/web_login.css b/server_environment_files_sample/static/prod/web_login.css new file mode 100644 index 0000000..e69de29 diff --git a/server_environment_files_sample/static/test/web_login.css b/server_environment_files_sample/static/test/web_login.css new file mode 100644 index 0000000..2efe770 --- /dev/null +++ b/server_environment_files_sample/static/test/web_login.css @@ -0,0 +1,3 @@ +body .bg-100{ + background-color:#AAFFFF !important; +} diff --git a/server_environment_files_sample/views/templates.xml b/server_environment_files_sample/views/templates.xml new file mode 100644 index 0000000..b73bce1 --- /dev/null +++ b/server_environment_files_sample/views/templates.xml @@ -0,0 +1,16 @@ + + + + + + + +