您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

132 行
3.7 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. def get_bootinfo():
  13. """build and return boot info"""
  14. bootinfo = webnotes._dict()
  15. doclist = []
  16. # profile
  17. get_profile(bootinfo)
  18. # control panel
  19. cp = webnotes.model.doc.getsingle('Control Panel')
  20. # system info
  21. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  22. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  23. bootinfo['server_date'] = webnotes.utils.nowdate()
  24. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  25. None, "send_print_in_body_and_attachment")
  26. if webnotes.session['user'] != 'Guest':
  27. bootinfo['user_info'] = get_fullnames()
  28. bootinfo['sid'] = webnotes.session['sid'];
  29. # home page
  30. bootinfo.modules = webnotes.get_config().modules
  31. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  32. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  33. tabDocType where ifnull(icon,'')!=''"""))
  34. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  35. tabPage where ifnull(icon,'')!=''""")))
  36. add_home_page(bootinfo, doclist)
  37. add_allowed_pages(bootinfo)
  38. load_translations(bootinfo)
  39. load_country_and_currency(bootinfo, doclist)
  40. # ipinfo
  41. if webnotes.session['data'].get('ipinfo'):
  42. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  43. # add docs
  44. bootinfo['docs'] = doclist
  45. # plugins
  46. try:
  47. import startup.boot
  48. startup.boot.boot_session(bootinfo)
  49. except ImportError:
  50. pass
  51. from webnotes.model.utils import compress
  52. bootinfo['docs'] = compress(bootinfo['docs'])
  53. return bootinfo
  54. def load_country_and_currency(bootinfo, doclist):
  55. if bootinfo.control_panel.country and \
  56. webnotes.conn.exists("Country", bootinfo.control_panel.country):
  57. doclist += [webnotes.doc("Country", bootinfo.control_panel.country)]
  58. doclist += webnotes.conn.sql("""select * from tabCurrency
  59. where ifnull(enabled,0)=1""", as_dict=1, update={"doctype":":Currency"})
  60. def add_allowed_pages(bootinfo):
  61. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  62. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  63. def load_translations(bootinfo):
  64. webnotes.set_user_lang(webnotes.session.user)
  65. if webnotes.lang != 'en':
  66. from webnotes.translate import get_lang_data
  67. # framework
  68. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  69. # doctype and module names
  70. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  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.PermissionError, e:
  99. page_doclist = webnotes.widgets.page.get('Login Page')
  100. bootinfo['home_page_html'] = page_doclist[0].content
  101. bootinfo['home_page'] = page_doclist[0].name
  102. doclist += page_doclist