中国本土应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.8KB

  1. # -*- coding: utf-8 -*-
  2. import json
  3. from odoo import api, models
  4. from odoo.http import request
  5. from odoo.tools import ustr
  6. class Http(models.AbstractModel):
  7. _inherit = "ir.http"
  8. def webclient_rendering_context(self):
  9. """
  10. 覆盖社区版,以防止不必要的加载请求
  11. """
  12. return {
  13. "session_info": self.session_info(),
  14. }
  15. def session_info(self):
  16. """
  17. 设置用户的主题信息 和锁屏信息
  18. """
  19. session_info = super(Http, self).session_info()
  20. # 语言
  21. langs = self.env["res.lang"].search_read([], ["name", "code", "flag_image_url"])
  22. for lang in langs:
  23. if lang["code"] == request.env.lang:
  24. session_info["current_lang"] = lang
  25. break
  26. session_info["langs"] = langs
  27. current_user = self.env.user
  28. current_user_company = current_user.company_id
  29. # 主题
  30. disable_theme_customizer = (
  31. current_user_company.theme_id.disable_theme_customizer
  32. )
  33. theme = {}
  34. theme_id = current_user.theme_id
  35. if disable_theme_customizer:
  36. # 如果关闭用户定制主题功能,则使用公司绑定的主题
  37. theme_id = current_user_company.theme_id
  38. theme = {
  39. "disable_customization": disable_theme_customizer,
  40. "main_menu_mode": theme_id.main_menu_mode,
  41. "main_submenu_position": theme_id.main_submenu_position,
  42. "sidebar_display_number_of_submenus": theme_id.sidebar_display_number_of_submenus,
  43. "sidebar_fixed": theme_id.sidebar_fixed,
  44. "sidebar_show_minimize_button": theme_id.sidebar_show_minimize_button,
  45. "sidebar_default_minimized": theme_id.sidebar_default_minimized,
  46. "sidebar_hover_maximize": theme_id.sidebar_hover_maximize,
  47. }
  48. session_info.update({"theme": json.loads(json.dumps(theme))})
  49. # 锁屏方式
  50. session_info.update(
  51. {
  52. "lock_screen_state_storage_mode": int(current_user_company.lock_screen_state_storage_mode),
  53. # "lock_screen_state":False,
  54. }
  55. )
  56. # print(session_info)
  57. return session_info
  58. def get_frontend_session_info(self):
  59. session_info = super(Http, self).get_frontend_session_info()
  60. # 锁屏方式
  61. session_info.update(
  62. {
  63. "lock_screen_state_storage_mode": int(self.env.user.company_id.lock_screen_state_storage_mode),
  64. # "lock_screen_state":False,
  65. }
  66. )
  67. return session_info
  68. # @api.model
  69. # def set_lock_session_info(self, uid, lock_info):
  70. # """
  71. # 设置锁屏的session信息
  72. # """
  73. # session_info = self.env['ir.http'].session_info()
  74. # frontend_session_info = self.env['ir.http'].get_frontend_session_info()
  75. # storage_mode = session_info["lock_screen_state_storage_mode"]
  76. # lock = {
  77. # "uid": uid,
  78. # "href": lock_info["href"],
  79. # "host": lock_info["host"],
  80. # "pathname": lock_info["pathname"],
  81. # "search": lock_info["search"],
  82. # "hash": lock_info["hash"],
  83. # }
  84. # if "lock" in lock_info:
  85. # lock["lock"] = lock_info["lock"]
  86. # if storage_mode ==1:
  87. # session_info.update({"lock_screen_state": True})
  88. # frontend_session_info.update({"lock_screen_state": True})
  89. # if storage_mode ==2:
  90. # user = self.env["res.users"].sudo().search([('id', '=', uid)], limit=1)
  91. # user.write({"lock_screen": True})
  92. # request.session["lock_screen_info"] = json.loads(json.dumps(lock))
  93. # request.session.modified = True # 标记session已修改
  94. # return request.session["lock_screen_info"]
上海开阖软件有限公司 沪ICP备12045867号-1