Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

boot.py 4.8 KiB

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