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.
 
 
 
 
 
 

116 line
3.4 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. # remove email settings from control panel dict
  37. for field in ['mail_login', 'mail_password', 'mail_port', 'outgoing_mail_server', 'use_ssl']:
  38. del cp[field]
  39. # system info
  40. bootinfo['control_panel'] = cp.copy()
  41. bootinfo['account_name'] = cp.get('account_id')
  42. bootinfo['sysdefaults'] = webnotes.utils.get_defaults()
  43. if webnotes.session['user'] != 'Guest':
  44. import webnotes.widgets.menus
  45. bootinfo['dt_labels'] = get_dt_labels()
  46. bootinfo['user_info'] = get_fullnames()
  47. # home page
  48. get_home_page(bootinfo, doclist)
  49. # ipinfo
  50. if webnotes.session['data'].get('ipinfo'):
  51. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  52. # add docs
  53. bootinfo['docs'] = doclist
  54. # plugins
  55. import startup.event_handlers
  56. if getattr(startup.event_handlers, 'boot_session'):
  57. startup.event_handlers.boot_session(bootinfo)
  58. webnotes.conn.commit()
  59. return bootinfo
  60. def get_fullnames():
  61. """map of user fullnames"""
  62. import webnotes
  63. ret = webnotes.conn.sql("""select name,
  64. concat(ifnull(first_name, ''),
  65. if(ifnull(first_name, '')!='', ' ', ''), ifnull(last_name, '')),
  66. user_image, gender
  67. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  68. d = {}
  69. for r in ret:
  70. if not r[2]:
  71. r[2] = 'lib/images/ui/no_img_m.gif'
  72. else:
  73. r[2] = 'files/' + r[2]
  74. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3]}
  75. return d
  76. def get_profile(bootinfo):
  77. """get profile info"""
  78. import webnotes
  79. bootinfo['profile'] = webnotes.user.load_profile()
  80. webnotes.session['data']['profile'] = bootinfo['profile']
  81. def get_home_page(bootinfo, doclist):
  82. """load home page"""
  83. import webnotes
  84. home_page = webnotes.user.get_home_page()
  85. if home_page:
  86. import webnotes.widgets.page
  87. page_doclist = webnotes.widgets.page.get(home_page)
  88. doclist += webnotes.widgets.page.get(home_page)
  89. bootinfo['home_page_html'] = page_doclist[0].content
  90. bootinfo['home_page'] = home_page or ''
  91. def get_dt_labels():
  92. import webnotes
  93. res = webnotes.conn.sql("select name, dt_label from `tabDocType Label`")
  94. return dict(res)