Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
13 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. def get_bootinfo():
  27. """build and return boot info"""
  28. import webnotes
  29. bootinfo = {}
  30. doclist = []
  31. webnotes.conn.begin()
  32. # profile
  33. get_profile(bootinfo)
  34. # control panel
  35. import webnotes.model.doc
  36. cp = webnotes.model.doc.getsingle('Control Panel')
  37. from webnotes.utils import cint
  38. # system info
  39. bootinfo['control_panel'] = cp.copy()
  40. bootinfo['account_name'] = cp.get('account_id')
  41. bootinfo['sysdefaults'] = webnotes.utils.get_defaults()
  42. if webnotes.session['user'] != 'Guest':
  43. import webnotes.widgets.menus
  44. bootinfo['user_info'] = get_fullnames()
  45. bootinfo['sid'] = webnotes.session['sid'];
  46. # home page
  47. add_home_page(bootinfo, doclist)
  48. # ipinfo
  49. if webnotes.session['data'].get('ipinfo'):
  50. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  51. # add docs
  52. bootinfo['docs'] = doclist
  53. # plugins
  54. try:
  55. import startup.event_handlers
  56. if getattr(startup.event_handlers, 'boot_session', None):
  57. startup.event_handlers.boot_session(bootinfo)
  58. except ImportError:
  59. pass
  60. webnotes.conn.commit()
  61. return bootinfo
  62. def get_fullnames():
  63. """map of user fullnames"""
  64. import webnotes
  65. ret = webnotes.conn.sql("""select name,
  66. concat(ifnull(first_name, ''),
  67. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  68. user_image, gender
  69. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  70. d = {}
  71. for r in ret:
  72. if not r[2]:
  73. r[2] = 'lib/images/ui/no_img_m.gif'
  74. else:
  75. r[2] = 'files/' + r[2]
  76. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3]}
  77. return d
  78. def get_profile(bootinfo):
  79. """get profile info"""
  80. import webnotes
  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. import webnotes
  86. import webnotes.widgets.page
  87. import webnotes.cms
  88. home_page = webnotes.cms.get_home_page(webnotes.session['user']) or 'Login Page'
  89. try:
  90. page_doclist = webnotes.widgets.page.get(home_page)
  91. except webnotes.PermissionError, e:
  92. page_doclist = webnotes.widgets.page.get('Login Page')
  93. bootinfo['home_page_html'] = page_doclist[0].content
  94. bootinfo['home_page'] = page_doclist[0].name
  95. doclist += page_doclist