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.
 
 
 
 
 
 

151 line
4.7 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. def get_bootinfo():
  31. """build and return boot info"""
  32. bootinfo = webnotes._dict()
  33. doclist = []
  34. # profile
  35. get_profile(bootinfo)
  36. # control panel
  37. cp = webnotes.model.doc.getsingle('Control Panel')
  38. # system info
  39. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  40. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  41. bootinfo['server_date'] = webnotes.utils.nowdate()
  42. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  43. None, "send_print_in_body_and_attachment")
  44. if webnotes.session['user'] != 'Guest':
  45. bootinfo['user_info'] = get_fullnames()
  46. bootinfo['sid'] = webnotes.session['sid'];
  47. # home page
  48. add_home_page(bootinfo, doclist)
  49. add_allowed_pages(bootinfo)
  50. load_translations(bootinfo)
  51. load_country_and_currency(bootinfo, doclist)
  52. # ipinfo
  53. if webnotes.session['data'].get('ipinfo'):
  54. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  55. # add docs
  56. bootinfo['docs'] = doclist
  57. # plugins
  58. try:
  59. import startup.boot
  60. startup.boot.boot_session(bootinfo)
  61. except ImportError:
  62. pass
  63. from webnotes.model.utils import compress
  64. bootinfo['docs'] = compress(bootinfo['docs'])
  65. return bootinfo
  66. def load_country_and_currency(bootinfo, doclist):
  67. if bootinfo.control_panel.country and \
  68. webnotes.conn.exists("Country", bootinfo.control_panel.country):
  69. doclist += [webnotes.doc("Country", bootinfo.control_panel.country)]
  70. doclist += webnotes.conn.sql("""select * from tabCurrency
  71. where ifnull(enabled,0)=1""", as_dict=1, update={"doctype":":Currency"})
  72. def add_allowed_pages(bootinfo):
  73. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  74. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  75. def load_translations(bootinfo):
  76. try:
  77. from startup import lang_list, lang_names
  78. except ImportError:
  79. return
  80. user_lang_pref = webnotes.conn.get_value("Profile", webnotes.session.user, "language")
  81. if user_lang_pref and (user_lang_pref in lang_names):
  82. webnotes.lang = lang_names[user_lang_pref]
  83. webnotes.user_lang = True
  84. if webnotes.lang != 'en':
  85. from webnotes.translate import get_lang_data
  86. # framework
  87. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  88. # doctype and module names
  89. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  90. bootinfo["lang"] = webnotes.lang
  91. def get_fullnames():
  92. """map of user fullnames"""
  93. ret = webnotes.conn.sql("""select name,
  94. concat(ifnull(first_name, ''),
  95. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  96. user_image, gender, email
  97. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  98. d = {}
  99. for r in ret:
  100. if not r[2]:
  101. r[2] = 'lib/images/ui/avatar.png'
  102. else:
  103. r[2] = r[2]
  104. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  105. 'email': r[4] or r[0]}
  106. return d
  107. def get_profile(bootinfo):
  108. """get profile info"""
  109. bootinfo['profile'] = webnotes.user.load_profile()
  110. def add_home_page(bootinfo, doclist):
  111. """load home page"""
  112. if webnotes.session.user=="Guest":
  113. return
  114. home_page = webnotes.get_application_home_page(webnotes.session.user)
  115. try:
  116. page_doclist = webnotes.widgets.page.get(home_page)
  117. except webnotes.PermissionError, e:
  118. page_doclist = webnotes.widgets.page.get('Login Page')
  119. bootinfo['home_page_html'] = page_doclist[0].content
  120. bootinfo['home_page'] = page_doclist[0].name
  121. doclist += page_doclist