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

113 行
3.2 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. """
  23. bootstrap client session
  24. """
  25. def get_bootinfo():
  26. """build and return boot info"""
  27. import webnotes
  28. bootinfo = {}
  29. doclist = []
  30. webnotes.conn.begin()
  31. # profile
  32. get_profile(bootinfo)
  33. # control panel
  34. import webnotes.model.doc
  35. cp = webnotes.model.doc.getsingle('Control Panel')
  36. from webnotes.utils import cint
  37. # system info
  38. bootinfo['control_panel'] = cp.copy()
  39. bootinfo['account_name'] = cp.get('account_id')
  40. bootinfo['sysdefaults'] = webnotes.utils.get_defaults()
  41. if webnotes.session['user'] != 'Guest':
  42. import webnotes.widgets.menus
  43. bootinfo['user_info'] = get_fullnames()
  44. bootinfo['sid'] = webnotes.session['sid'];
  45. # home page
  46. get_home_page(bootinfo, doclist)
  47. # ipinfo
  48. if webnotes.session['data'].get('ipinfo'):
  49. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  50. # add docs
  51. bootinfo['docs'] = doclist
  52. # plugins
  53. try:
  54. import startup.event_handlers
  55. if getattr(startup.event_handlers, 'boot_session'):
  56. startup.event_handlers.boot_session(bootinfo)
  57. except ImportError:
  58. pass
  59. webnotes.conn.commit()
  60. return bootinfo
  61. def get_fullnames():
  62. """map of user fullnames"""
  63. import webnotes
  64. ret = webnotes.conn.sql("""select name,
  65. concat(ifnull(first_name, ''),
  66. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  67. user_image, gender
  68. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  69. d = {}
  70. for r in ret:
  71. if not r[2]:
  72. r[2] = 'lib/images/ui/no_img_m.gif'
  73. else:
  74. r[2] = 'files/' + r[2]
  75. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3]}
  76. return d
  77. def get_profile(bootinfo):
  78. """get profile info"""
  79. import webnotes
  80. bootinfo['profile'] = webnotes.user.load_profile()
  81. webnotes.session['data']['profile'] = bootinfo['profile']
  82. def get_home_page(bootinfo, doclist):
  83. """load home page"""
  84. import webnotes
  85. home_page = webnotes.user.get_home_page()
  86. if home_page:
  87. import webnotes.widgets.page
  88. page_doclist = webnotes.widgets.page.get(home_page)
  89. doclist += webnotes.widgets.page.get(home_page)
  90. bootinfo['home_page_html'] = page_doclist[0].content
  91. bootinfo['home_page'] = home_page or ''