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.
 
 
 
 
 
 

133 lines
3.7 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 get_desktop_icons in hooks.get_desktop_icons:
  34. bootinfo.modules.update(webnotes.get_attr(get_desktop_icons)())
  35. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  36. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  37. tabDocType where ifnull(icon,'')!=''"""))
  38. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  39. tabPage where ifnull(icon,'')!=''""")))
  40. add_home_page(bootinfo, doclist)
  41. add_allowed_pages(bootinfo)
  42. load_translations(bootinfo)
  43. load_conf_settings(bootinfo)
  44. # ipinfo
  45. if webnotes.session['data'].get('ipinfo'):
  46. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  47. # add docs
  48. bootinfo['docs'] = doclist
  49. for method in hooks.boot_session:
  50. webnotes.get_attr(method)(bootinfo)
  51. from webnotes.model.utils import compress
  52. bootinfo['docs'] = compress(bootinfo['docs'])
  53. # deal with __slots__ in lang
  54. if bootinfo.lang:
  55. bootinfo.lang = unicode(bootinfo.lang)
  56. bootinfo.metadata_version = webnotes.cache().get_value("metadata_version")
  57. if not bootinfo.metadata_version:
  58. bootinfo.metadata_version = webnotes.reset_metadata_version()
  59. return bootinfo
  60. def load_conf_settings(bootinfo):
  61. from webnotes import conf
  62. for key in ['developer_mode']:
  63. if key in conf: bootinfo[key] = conf.get(key)
  64. def add_allowed_pages(bootinfo):
  65. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  66. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  67. def load_translations(bootinfo):
  68. webnotes.set_user_lang(webnotes.session.user)
  69. if webnotes.lang != 'en':
  70. bootinfo["__messages"] = webnotes.get_lang_dict("include")
  71. bootinfo["lang"] = webnotes.lang
  72. def get_fullnames():
  73. """map of user fullnames"""
  74. ret = webnotes.conn.sql("""select name,
  75. concat(ifnull(first_name, ''),
  76. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  77. user_image, gender, email
  78. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  79. d = {}
  80. for r in ret:
  81. if not r[2]:
  82. r[2] = 'lib/images/ui/avatar.png'
  83. else:
  84. r[2] = r[2]
  85. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  86. 'email': r[4] or r[0]}
  87. return d
  88. def get_profile(bootinfo):
  89. """get profile info"""
  90. bootinfo['profile'] = webnotes.user.load_profile()
  91. def add_home_page(bootinfo, doclist):
  92. """load home page"""
  93. if webnotes.session.user=="Guest":
  94. return
  95. home_page = webnotes.get_application_home_page(webnotes.session.user)
  96. try:
  97. page_doclist = webnotes.widgets.page.get(home_page)
  98. except (webnotes.DoesNotExistError, webnotes.PermissionError), e:
  99. page_doclist = webnotes.widgets.page.get('desktop')
  100. bootinfo['home_page_html'] = page_doclist[0].content
  101. bootinfo['home_page'] = page_doclist[0].name
  102. doclist += page_doclist