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.
 
 
 
 
 
 

130 line
3.6 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  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. doclist = []
  17. # profile
  18. get_profile(bootinfo)
  19. # control panel
  20. cp = webnotes.model.doc.getsingle('Control Panel')
  21. # system info
  22. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  23. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  24. bootinfo['server_date'] = webnotes.utils.nowdate()
  25. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  26. None, "send_print_in_body_and_attachment")
  27. if webnotes.session['user'] != 'Guest':
  28. bootinfo['user_info'] = get_fullnames()
  29. bootinfo['sid'] = webnotes.session['sid'];
  30. # home page
  31. bootinfo.modules = webnotes.get_config().modules
  32. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  33. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  34. tabDocType where ifnull(icon,'')!=''"""))
  35. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  36. tabPage where ifnull(icon,'')!=''""")))
  37. add_home_page(bootinfo, doclist)
  38. add_allowed_pages(bootinfo)
  39. load_translations(bootinfo)
  40. load_conf_settings(bootinfo)
  41. # ipinfo
  42. if webnotes.session['data'].get('ipinfo'):
  43. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  44. # add docs
  45. bootinfo['docs'] = doclist
  46. # plugins
  47. try:
  48. import startup.boot
  49. startup.boot.boot_session(bootinfo)
  50. except ImportError:
  51. pass
  52. from webnotes.model.utils import compress
  53. bootinfo['docs'] = compress(bootinfo['docs'])
  54. return bootinfo
  55. def load_conf_settings(bootinfo):
  56. import conf
  57. for key in ['developer_mode']:
  58. if hasattr(conf, key): bootinfo[key] = getattr(conf, key)
  59. def add_allowed_pages(bootinfo):
  60. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  61. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  62. def load_translations(bootinfo):
  63. webnotes.set_user_lang(webnotes.session.user)
  64. if webnotes.lang != 'en':
  65. from webnotes.translate import get_lang_data
  66. # framework
  67. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  68. # doctype and module names
  69. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  70. bootinfo["lang"] = webnotes.lang
  71. def get_fullnames():
  72. """map of user fullnames"""
  73. ret = webnotes.conn.sql("""select name,
  74. concat(ifnull(first_name, ''),
  75. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  76. user_image, gender, email
  77. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  78. d = {}
  79. for r in ret:
  80. if not r[2]:
  81. r[2] = 'lib/images/ui/avatar.png'
  82. else:
  83. r[2] = r[2]
  84. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  85. 'email': r[4] or r[0]}
  86. return d
  87. def get_profile(bootinfo):
  88. """get profile info"""
  89. bootinfo['profile'] = webnotes.user.load_profile()
  90. def add_home_page(bootinfo, doclist):
  91. """load home page"""
  92. if webnotes.session.user=="Guest":
  93. return
  94. home_page = webnotes.get_application_home_page(webnotes.session.user)
  95. try:
  96. page_doclist = webnotes.widgets.page.get(home_page)
  97. except (webnotes.DoesNotExistError, webnotes.PermissionError), e:
  98. page_doclist = webnotes.widgets.page.get('desktop')
  99. bootinfo['home_page_html'] = page_doclist[0].content
  100. bootinfo['home_page'] = page_doclist[0].name
  101. doclist += page_doclist