Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

139 рядки
4.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. from __future__ import unicode_literals
  23. """
  24. bootstrap client session
  25. """
  26. import webnotes
  27. import webnotes.model.doc
  28. import webnotes.widgets.page
  29. def get_bootinfo():
  30. """build and return boot info"""
  31. bootinfo = webnotes._dict()
  32. doclist = []
  33. # profile
  34. get_profile(bootinfo)
  35. # control panel
  36. cp = webnotes.model.doc.getsingle('Control Panel')
  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. bootinfo['server_date'] = webnotes.utils.nowdate()
  42. if webnotes.session['user'] != 'Guest':
  43. bootinfo['user_info'] = get_fullnames()
  44. bootinfo['sid'] = webnotes.session['sid'];
  45. # home page
  46. add_home_page(bootinfo, doclist)
  47. add_allowed_pages(bootinfo)
  48. load_translations(bootinfo)
  49. load_country_and_currency(bootinfo, doclist)
  50. # ipinfo
  51. if webnotes.session['data'].get('ipinfo'):
  52. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  53. # add docs
  54. bootinfo['docs'] = doclist
  55. # plugins
  56. try:
  57. from startup import event_handlers
  58. if getattr(event_handlers, 'boot_session', None):
  59. event_handlers.boot_session(bootinfo)
  60. except ImportError:
  61. pass
  62. from webnotes.model.utils import compress
  63. bootinfo['docs'] = compress(bootinfo['docs'])
  64. return bootinfo
  65. def load_country_and_currency(bootinfo, doclist):
  66. country_doc = webnotes.doc("Country", bootinfo.sysdefaults.country)
  67. doclist += [country_doc]
  68. if country_doc.currency:
  69. doclist += [webnotes.doc("Currency", country_doc.currency)]
  70. def add_allowed_pages(bootinfo):
  71. bootinfo.allowed_pages = [p[0] for p in webnotes.conn.sql("""select distinct parent from `tabPage Role`
  72. where role in ('%s')""" % "', '".join(webnotes.get_roles()))]
  73. def load_translations(bootinfo):
  74. if webnotes.lang != 'en':
  75. from webnotes.translate import get_lang_data
  76. # framework
  77. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  78. # doctype and module names
  79. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  80. bootinfo["lang"] = webnotes.lang
  81. def get_fullnames():
  82. """map of user fullnames"""
  83. ret = webnotes.conn.sql("""select name,
  84. concat(ifnull(first_name, ''),
  85. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  86. user_image, gender, email
  87. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  88. d = {}
  89. for r in ret:
  90. if not r[2]:
  91. r[2] = 'lib/images/ui/avatar.png'
  92. else:
  93. r[2] = r[2]
  94. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  95. 'email': r[4] or r[0]}
  96. return d
  97. def get_profile(bootinfo):
  98. """get profile info"""
  99. bootinfo['profile'] = webnotes.user.load_profile()
  100. def add_home_page(bootinfo, doclist):
  101. """load home page"""
  102. if webnotes.session.user=="Guest":
  103. return
  104. home_page = webnotes.get_application_home_page(webnotes.session.user)
  105. try:
  106. page_doclist = webnotes.widgets.page.get(home_page)
  107. except webnotes.PermissionError, e:
  108. page_doclist = webnotes.widgets.page.get('Login Page')
  109. bootinfo['home_page_html'] = page_doclist[0].content
  110. bootinfo['home_page'] = page_doclist[0].name
  111. doclist += page_doclist