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.
 
 
 
 
 
 

96 lines
2.9 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. # home page
  47. get_home_page(bootinfo, doclist)
  48. # ipinfo
  49. if webnotes.session['data'].get('ipinfo'):
  50. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  51. # add docs
  52. bootinfo['docs'] = doclist
  53. # plugins
  54. import startup.event_handlers
  55. if getattr(startup.event_handlers, 'boot_session'):
  56. startup.event_handlers.boot_session(bootinfo)
  57. webnotes.conn.commit()
  58. return bootinfo
  59. def get_profile(bootinfo):
  60. """get profile info"""
  61. import webnotes
  62. bootinfo['profile'] = webnotes.user.load_profile()
  63. webnotes.session['data']['profile'] = bootinfo['profile']
  64. def get_home_page(bootinfo, doclist):
  65. """load home page"""
  66. import webnotes
  67. home_page = webnotes.user.get_home_page()
  68. if home_page:
  69. import webnotes.widgets.page
  70. page_doclist = webnotes.widgets.page.get(home_page)
  71. doclist += webnotes.widgets.page.get(home_page)
  72. bootinfo['home_page_html'] = page_doclist[0].content
  73. bootinfo['home_page'] = home_page or ''
  74. def get_dt_labels():
  75. import webnotes
  76. res = webnotes.conn.sql("select name, dt_label from `tabDocType Label`")
  77. return dict(res)