No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

117 líneas
3.4 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. import webnotes.cms
  30. def get_bootinfo():
  31. """build and return boot info"""
  32. bootinfo = webnotes.DictObj()
  33. doclist = []
  34. # profile
  35. get_profile(bootinfo)
  36. # control panel
  37. cp = webnotes.model.doc.getsingle('Control Panel')
  38. from webnotes.utils import cint
  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. bootinfo['server_date'] = webnotes.utils.nowdate()
  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. # 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 get_fullnames():
  65. """map of user fullnames"""
  66. ret = webnotes.conn.sql("""select name,
  67. concat(ifnull(first_name, ''),
  68. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  69. user_image, gender
  70. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  71. d = {}
  72. for r in ret:
  73. if not r[2]:
  74. r[2] = 'lib/images/ui/avatar.png'
  75. else:
  76. r[2] = 'files/' + r[2]
  77. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3]}
  78. return d
  79. def get_profile(bootinfo):
  80. """get profile info"""
  81. bootinfo['profile'] = webnotes.user.load_profile()
  82. webnotes.session['data']['profile'] = bootinfo['profile']
  83. def add_home_page(bootinfo, doclist):
  84. """load home page"""
  85. home_page = webnotes.cms.get_home_page(webnotes.session['user']) or 'Login Page'
  86. try:
  87. page_doclist = webnotes.widgets.page.get(home_page)
  88. except webnotes.PermissionError, e:
  89. page_doclist = webnotes.widgets.page.get('Login Page')
  90. bootinfo['home_page_html'] = page_doclist[0].content
  91. bootinfo['home_page'] = page_doclist[0].name
  92. doclist += page_doclist