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.
 
 
 
 
 
 

142 rivejä
4.0 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. """
  5. bootstrap client session
  6. """
  7. import webnotes
  8. import webnotes.defaults
  9. import webnotes.model.doc
  10. import webnotes.widgets.page
  11. import json
  12. import webnotes.webutils
  13. def get_bootinfo():
  14. """build and return boot info"""
  15. bootinfo = webnotes._dict()
  16. hooks = webnotes.get_hooks()
  17. doclist = []
  18. # profile
  19. get_profile(bootinfo)
  20. # control panel
  21. cp = webnotes.model.doc.getsingle('Control Panel')
  22. # system info
  23. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  24. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  25. bootinfo['server_date'] = webnotes.utils.nowdate()
  26. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  27. None, "send_print_in_body_and_attachment")
  28. if webnotes.session['user'] != 'Guest':
  29. bootinfo['user_info'] = get_fullnames()
  30. bootinfo['sid'] = webnotes.session['sid'];
  31. # home page
  32. bootinfo.modules = {}
  33. for app in webnotes.get_installed_apps():
  34. try:
  35. bootinfo.modules.update(webnotes.get_attr(app + ".config.desktop.data") or {})
  36. except ImportError, e:
  37. pass
  38. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  39. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  40. tabDocType where ifnull(icon,'')!=''"""))
  41. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  42. tabPage where ifnull(icon,'')!=''""")))
  43. add_home_page(bootinfo, doclist)
  44. add_allowed_pages(bootinfo)
  45. load_translations(bootinfo)
  46. load_conf_settings(bootinfo)
  47. load_startup_js(bootinfo)
  48. # ipinfo
  49. if webnotes.session['data'].get('ipinfo'):
  50. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  51. # add docs
  52. bootinfo['docs'] = doclist
  53. for method in hooks.boot_session or []:
  54. webnotes.get_attr(method)(bootinfo)
  55. from webnotes.model.utils import compress
  56. bootinfo['docs'] = compress(bootinfo['docs'])
  57. # deal with __slots__ in lang
  58. if bootinfo.lang:
  59. bootinfo.lang = unicode(bootinfo.lang)
  60. bootinfo.metadata_version = webnotes.cache().get_value("metadata_version")
  61. if not bootinfo.metadata_version:
  62. bootinfo.metadata_version = webnotes.reset_metadata_version()
  63. return bootinfo
  64. def load_conf_settings(bootinfo):
  65. from webnotes import conf
  66. for key in ['developer_mode']:
  67. if key in conf: bootinfo[key] = conf.get(key)
  68. def add_allowed_pages(bootinfo):
  69. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  70. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  71. def load_translations(bootinfo):
  72. webnotes.set_user_lang(webnotes.session.user)
  73. if webnotes.lang != 'en':
  74. bootinfo["__messages"] = webnotes.get_lang_dict("include")
  75. bootinfo["lang"] = webnotes.lang
  76. def get_fullnames():
  77. """map of user fullnames"""
  78. ret = webnotes.conn.sql("""select name,
  79. concat(ifnull(first_name, ''),
  80. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  81. user_image, gender, email
  82. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  83. d = {}
  84. for r in ret:
  85. if not r[2]:
  86. r[2] = '/assets/webnotes/images/ui/avatar.png'
  87. else:
  88. r[2] = r[2]
  89. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  90. 'email': r[4] or r[0]}
  91. return d
  92. def load_startup_js(bootinfo):
  93. bootinfo.startup_js = ""
  94. for method in webnotes.get_hooks().startup_js or []:
  95. bootinfo.startup_js += webnotes.get_attr(method)()
  96. def get_profile(bootinfo):
  97. """get profile info"""
  98. bootinfo['profile'] = webnotes.user.load_profile()
  99. def add_home_page(bootinfo, doclist):
  100. """load home page"""
  101. if webnotes.session.user=="Guest":
  102. return
  103. home_page = webnotes.get_application_home_page(webnotes.session.user)
  104. try:
  105. page_doclist = webnotes.widgets.page.get(home_page)
  106. except (webnotes.DoesNotExistError, webnotes.PermissionError), e:
  107. page_doclist = webnotes.widgets.page.get('desktop')
  108. bootinfo['home_page_html'] = page_doclist[0].content
  109. bootinfo['home_page'] = page_doclist[0].name
  110. doclist += page_doclist