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:
4
web_dark_mode/models/__init__.py
Normal file
4
web_dark_mode/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# © 2022 Florian Kantelberg - initOS GmbH
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import ir_http, res_users
|
||||
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)
|
||||
12
web_dark_mode/models/res_users.py
Normal file
12
web_dark_mode/models/res_users.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# © 2022 Florian Kantelberg - initOS GmbH
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
dark_mode = fields.Boolean()
|
||||
dark_mode_device_dependent = fields.Boolean("Device Dependent Dark Mode")
|
||||
Reference in New Issue
Block a user