Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

13 anni fa
13 anni fa
13 anni fa
13 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. """
  23. bootstrap client session
  24. """
  25. def get_bootinfo():
  26. """build and return boot info"""
  27. import webnotes
  28. bootinfo = {}
  29. doclist = []
  30. webnotes.conn.begin()
  31. # profile
  32. get_profile(bootinfo)
  33. # control panel
  34. import webnotes.model.doc
  35. cp = webnotes.model.doc.getsingle('Control Panel')
  36. # remove email settings from control panel dict
  37. for field in ['mail_login', 'mail_password', 'mail_port', 'outgoing_mail_server', 'use_ssl']:
  38. del cp[field]
  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. if webnotes.session['user'] != 'Guest':
  44. import webnotes.widgets.menus
  45. bootinfo['dt_labels'] = get_dt_labels()
  46. bootinfo['user_info'] = get_fullnames()
  47. bootinfo['sid'] = webnotes.session['sid'];
  48. # home page
  49. get_home_page(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. import startup.event_handlers
  57. if getattr(startup.event_handlers, 'boot_session'):
  58. startup.event_handlers.boot_session(bootinfo)
  59. webnotes.conn.commit()
  60. return bootinfo
  61. def get_fullnames():
  62. """map of user fullnames"""
  63. import webnotes
  64. ret = webnotes.conn.sql("""select name,
  65. concat(ifnull(first_name, ''),
  66. if(ifnull(first_name, '')!='', ' ', ''), ifnull(last_name, '')),
  67. user_image, gender
  68. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  69. d = {}
  70. for r in ret:
  71. if not r[2]:
  72. r[2] = 'lib/images/ui/no_img_m.gif'
  73. else:
  74. r[2] = 'files/' + r[2]
  75. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3]}
  76. return d
  77. def get_profile(bootinfo):
  78. """get profile info"""
  79. import webnotes
  80. bootinfo['profile'] = webnotes.user.load_profile()
  81. webnotes.session['data']['profile'] = bootinfo['profile']
  82. def get_home_page(bootinfo, doclist):
  83. """load home page"""
  84. import webnotes
  85. home_page = webnotes.user.get_home_page()
  86. if home_page:
  87. import webnotes.widgets.page
  88. page_doclist = webnotes.widgets.page.get(home_page)
  89. doclist += webnotes.widgets.page.get(home_page)
  90. bootinfo['home_page_html'] = page_doclist[0].content
  91. bootinfo['home_page'] = home_page or ''
  92. def get_dt_labels():
  93. import webnotes
  94. res = webnotes.conn.sql("select name, dt_label from `tabDocType Label`")
  95. return dict(res)