[12.0][PORT] server_environment. port static files controllers from server-tools 8.0 branch

This commit is contained in:
Sylvain LE GAL 2020-05-20 20:42:22 +02:00
parent 11d6745d41
commit 553d572887
12 changed files with 87 additions and 4 deletions

View File

@ -18,6 +18,7 @@
# #
############################################################################## ##############################################################################
from . import models from . import models
from . import controllers
# TODO when migrating to 12, fix the import of serv_config by renaming the # TODO when migrating to 12, fix the import of serv_config by renaming the
# file? # file?
# Add an alias to access to the 'serv_config' module as it is shadowed # Add an alias to access to the 'serv_config' module as it is shadowed

View File

@ -9,7 +9,7 @@
"base", "base",
"base_sparse_field", "base_sparse_field",
], ],
"author": "Camptocamp,Odoo Community Association (OCA)", "author": "Camptocamp,GRAP,Odoo Community Association (OCA)",
"summary": "move some configurations out of the database", "summary": "move some configurations out of the database",
"website": "http://github.com/OCA/server-env", "website": "http://github.com/OCA/server-env",
"license": "GPL-3 or any later version", "license": "GPL-3 or any later version",

View File

@ -0,0 +1 @@
from . import main

View File

@ -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_<module_extension>'
'/static/RUNNING_ENV/<local_path>',
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)

View File

@ -89,3 +89,28 @@ Keychain integration
Read the documentation of the class `models/server_env_mixin.py Read the documentation of the class `models/server_env_mixin.py
<models/server_env_mixin.py>`_. <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
::
<odoo>
<template id="login_layout_no_db" name="Login Layout"
inherit_id="web.login_layout" >
<xpath expr="." position="inside">
<link rel="stylesheet"
href="/server_environment_files/static/RUNNING_ENV/css.css"/>
</xpath>
</template>
</odoo>
Then, create css files for each environment you have. exemple:
::
/server_environment_files/static/dev/css.css
/server_environment_files/static/prod/css.css
...

View File

@ -9,3 +9,4 @@
* Guewen Baconnier <guewen.baconnier@camptocamp.com> * Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Thomas Binfeld <thomas.binsfeld@acsone.eu> * Thomas Binfeld <thomas.binsfeld@acsone.eu>
* Stéphane Bidoul <stefane.bidoul@acsone.com> * Stéphane Bidoul <stefane.bidoul@acsone.com>
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

View File

@ -5,11 +5,13 @@
{ {
"name": "Example server configuration environment files repository module", "name": "Example server configuration environment files repository module",
"version": "12.0.1.0.1", "version": "12.0.1.0.1",
"depends": ["base"], "depends": ["server_environment", "web"],
"author": "Camptocamp,Odoo Community Association (OCA)", "author": "Camptocamp,GRAP,Odoo Community Association (OCA)",
"summary": "sample config file for server_environment", "summary": "sample config file for server_environment",
"website": "http://github.com/OCA/server-env", "website": "http://github.com/OCA/server-env",
"license": "GPL-3 or any later version", "license": "GPL-3 or any later version",
"category": "Tools", "category": "Tools",
"data": [], "data": [
'views/templates.xml',
],
} }

View File

@ -1,2 +1,3 @@
* Florent Xicluna (Wingo) <florent.xicluna@gmail.com> * Florent Xicluna (Wingo) <florent.xicluna@gmail.com>
* Nicolas Bessi <nicolas.bessi@camptocamp.com> * Nicolas Bessi <nicolas.bessi@camptocamp.com>
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

View File

@ -0,0 +1,3 @@
body .bg-100{
background-color:#AAFFAA !important;
}

View File

@ -0,0 +1,3 @@
body .bg-100{
background-color:#AAFFFF !important;
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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).
-->
<odoo>
<template id="login_layout_no_db" name="Login Layout" inherit_id="web.login_layout" >
<xpath expr="." position="inside">
<link rel="stylesheet" href="/server_environment_files_sample/static/RUNNING_ENV/web_login.css"/>
</xpath>
</template>
</odoo>