mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[ADD][16.0] Module web_dark_mode
This commit is contained in:
22
web_dark_mode/models/ir_http.py
Normal file
22
web_dark_mode/models/ir_http.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# © 2022 Florian Kantelberg - initOS GmbH
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class IrHttp(models.AbstractModel):
|
||||
_inherit = "ir.http"
|
||||
|
||||
@classmethod
|
||||
def _set_color_scheme(cls, response):
|
||||
scheme = request.httprequest.cookies.get("color_scheme")
|
||||
user = request.env.user
|
||||
user_scheme = "dark" if user.dark_mode else "light"
|
||||
if (not user.dark_mode_device_dependent) and scheme != user_scheme:
|
||||
response.set_cookie("color_scheme", user_scheme)
|
||||
|
||||
@classmethod
|
||||
def _post_dispatch(cls, response):
|
||||
cls._set_color_scheme(response)
|
||||
return super()._post_dispatch(response)
|
||||
Reference in New Issue
Block a user