Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

140 řádky
4.3 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'] = webnotes._dict(cp.copy())
  39. bootinfo['sysdefaults'] = webnotes.utils.get_defaults()
  40. bootinfo['server_date'] = webnotes.utils.nowdate()
  41. if webnotes.session['user'] != 'Guest':
  42. bootinfo['user_info'] = get_fullnames()
  43. bootinfo['sid'] = webnotes.session['sid'];
  44. # home page
  45. add_home_page(bootinfo, doclist)
  46. add_allowed_pages(bootinfo)
  47. load_translations(bootinfo)
  48. load_country_and_currency(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. try:
  56. from startup import event_handlers
  57. if getattr(event_handlers, 'boot_session', None):
  58. event_handlers.boot_session(bootinfo)
  59. except ImportError:
  60. pass
  61. from webnotes.model.utils import compress
  62. bootinfo['docs'] = compress(bootinfo['docs'])
  63. return bootinfo
  64. def load_country_and_currency(bootinfo, doclist):
  65. if bootinfo.control_panel.country and \
  66. webnotes.conn.exists("Country", bootinfo.control_panel.country):
  67. doclist += [webnotes.doc("Country", bootinfo.control_panel.country)]
  68. if bootinfo.sysdefaults.currency and \
  69. webnotes.conn.exists("Currency", bootinfo.sysdefaults.currency):
  70. doclist += [webnotes.doc("Currency", bootinfo.sysdefaults.currency)]
  71. def add_allowed_pages(bootinfo):
  72. bootinfo.allowed_pages = [p[0] for p in webnotes.conn.sql("""select distinct parent from `tabPage Role`
  73. where role in ('%s')""" % "', '".join(webnotes.get_roles()))]
  74. def load_translations(bootinfo):
  75. if webnotes.lang != 'en':
  76. from webnotes.translate import get_lang_data
  77. # framework
  78. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  79. # doctype and module names
  80. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  81. bootinfo["lang"] = webnotes.lang
  82. def get_fullnames():
  83. """map of user fullnames"""
  84. ret = webnotes.conn.sql("""select name,
  85. concat(ifnull(first_name, ''),
  86. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  87. user_image, gender, email
  88. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  89. d = {}
  90. for r in ret:
  91. if not r[2]:
  92. r[2] = 'lib/images/ui/avatar.png'
  93. else:
  94. r[2] = r[2]
  95. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  96. 'email': r[4] or r[0]}
  97. return d
  98. def get_profile(bootinfo):
  99. """get profile info"""
  100. bootinfo['profile'] = webnotes.user.load_profile()
  101. def add_home_page(bootinfo, doclist):
  102. """load home page"""
  103. if webnotes.session.user=="Guest":
  104. return
  105. home_page = webnotes.get_application_home_page(webnotes.session.user)
  106. try:
  107. page_doclist = webnotes.widgets.page.get(home_page)
  108. except webnotes.PermissionError, e:
  109. page_doclist = webnotes.widgets.page.get('Login Page')
  110. bootinfo['home_page_html'] = page_doclist[0].content
  111. bootinfo['home_page'] = page_doclist[0].name
  112. doclist += page_doclist