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

159 行
5.1 KiB

  1. # Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. #
  3. # MIT License (MIT)
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #
  22. from __future__ import unicode_literals
  23. """
  24. bootstrap client session
  25. """
  26. import webnotes
  27. import webnotes.defaults
  28. import webnotes.model.doc
  29. import webnotes.widgets.page
  30. import json
  31. def get_bootinfo():
  32. """build and return boot info"""
  33. bootinfo = webnotes._dict()
  34. doclist = []
  35. # profile
  36. get_profile(bootinfo)
  37. # control panel
  38. cp = webnotes.model.doc.getsingle('Control Panel')
  39. # system info
  40. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  41. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  42. bootinfo['server_date'] = webnotes.utils.nowdate()
  43. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  44. None, "send_print_in_body_and_attachment")
  45. if webnotes.session['user'] != 'Guest':
  46. bootinfo['user_info'] = get_fullnames()
  47. bootinfo['sid'] = webnotes.session['sid'];
  48. # home page
  49. bootinfo.modules = webnotes.get_config().modules
  50. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  51. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  52. tabDocType where ifnull(icon,'')!=''"""))
  53. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  54. tabPage where ifnull(icon,'')!=''""")))
  55. add_home_page(bootinfo, doclist)
  56. add_allowed_pages(bootinfo)
  57. load_translations(bootinfo)
  58. load_country_and_currency(bootinfo, doclist)
  59. # ipinfo
  60. if webnotes.session['data'].get('ipinfo'):
  61. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  62. # add docs
  63. bootinfo['docs'] = doclist
  64. # plugins
  65. try:
  66. import startup.boot
  67. startup.boot.boot_session(bootinfo)
  68. except ImportError:
  69. pass
  70. from webnotes.model.utils import compress
  71. bootinfo['docs'] = compress(bootinfo['docs'])
  72. return bootinfo
  73. def load_country_and_currency(bootinfo, doclist):
  74. if bootinfo.control_panel.country and \
  75. webnotes.conn.exists("Country", bootinfo.control_panel.country):
  76. doclist += [webnotes.doc("Country", bootinfo.control_panel.country)]
  77. doclist += webnotes.conn.sql("""select * from tabCurrency
  78. where ifnull(enabled,0)=1""", as_dict=1, update={"doctype":":Currency"})
  79. def add_allowed_pages(bootinfo):
  80. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  81. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  82. def load_translations(bootinfo):
  83. try:
  84. from startup import lang_list, lang_names
  85. except ImportError:
  86. return
  87. user_lang_pref = webnotes.conn.get_value("Profile", webnotes.session.user, "language")
  88. if user_lang_pref and (user_lang_pref.lower() in lang_names):
  89. webnotes.lang = lang_names[user_lang_pref.lower()]
  90. webnotes.user_lang = True
  91. if webnotes.lang != 'en':
  92. from webnotes.translate import get_lang_data
  93. # framework
  94. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  95. # doctype and module names
  96. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  97. bootinfo["lang"] = webnotes.lang
  98. def get_fullnames():
  99. """map of user fullnames"""
  100. ret = webnotes.conn.sql("""select name,
  101. concat(ifnull(first_name, ''),
  102. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  103. user_image, gender, email
  104. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  105. d = {}
  106. for r in ret:
  107. if not r[2]:
  108. r[2] = 'lib/images/ui/avatar.png'
  109. else:
  110. r[2] = r[2]
  111. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  112. 'email': r[4] or r[0]}
  113. return d
  114. def get_profile(bootinfo):
  115. """get profile info"""
  116. bootinfo['profile'] = webnotes.user.load_profile()
  117. def add_home_page(bootinfo, doclist):
  118. """load home page"""
  119. if webnotes.session.user=="Guest":
  120. return
  121. home_page = webnotes.get_application_home_page(webnotes.session.user)
  122. try:
  123. page_doclist = webnotes.widgets.page.get(home_page)
  124. except webnotes.PermissionError, e:
  125. page_doclist = webnotes.widgets.page.get('Login Page')
  126. bootinfo['home_page_html'] = page_doclist[0].content
  127. bootinfo['home_page'] = page_doclist[0].name
  128. doclist += page_doclist