You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. """
  5. bootstrap client session
  6. """
  7. import webnotes
  8. import webnotes.defaults
  9. import webnotes.model.doc
  10. import webnotes.widgets.page
  11. import json
  12. import webnotes.webutils
  13. def get_bootinfo():
  14. """build and return boot info"""
  15. bootinfo = webnotes._dict()
  16. doclist = []
  17. # profile
  18. get_profile(bootinfo)
  19. # control panel
  20. cp = webnotes.model.doc.getsingle('Control Panel')
  21. # system info
  22. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  23. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  24. bootinfo['server_date'] = webnotes.utils.nowdate()
  25. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  26. None, "send_print_in_body_and_attachment")
  27. if webnotes.session['user'] != 'Guest':
  28. bootinfo['user_info'] = get_fullnames()
  29. bootinfo['sid'] = webnotes.session['sid'];
  30. # home page
  31. bootinfo.modules = webnotes.get_config().modules
  32. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  33. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  34. tabDocType where ifnull(icon,'')!=''"""))
  35. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  36. tabPage where ifnull(icon,'')!=''""")))
  37. # portal links for sending in email
  38. bootinfo.portal_links = webnotes.webutils.get_portal_links()
  39. add_home_page(bootinfo, doclist)
  40. add_allowed_pages(bootinfo)
  41. load_translations(bootinfo)
  42. # ipinfo
  43. if webnotes.session['data'].get('ipinfo'):
  44. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  45. # add docs
  46. bootinfo['docs'] = doclist
  47. # plugins
  48. try:
  49. import startup.boot
  50. startup.boot.boot_session(bootinfo)
  51. except ImportError:
  52. pass
  53. from webnotes.model.utils import compress
  54. bootinfo['docs'] = compress(bootinfo['docs'])
  55. return bootinfo
  56. def add_allowed_pages(bootinfo):
  57. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  58. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  59. def load_translations(bootinfo):
  60. webnotes.set_user_lang(webnotes.session.user)
  61. if webnotes.lang != 'en':
  62. from webnotes.translate import get_lang_data
  63. # framework
  64. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  65. # doctype and module names
  66. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  67. bootinfo["lang"] = webnotes.lang
  68. def get_fullnames():
  69. """map of user fullnames"""
  70. ret = webnotes.conn.sql("""select name,
  71. concat(ifnull(first_name, ''),
  72. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  73. user_image, gender, email
  74. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  75. d = {}
  76. for r in ret:
  77. if not r[2]:
  78. r[2] = 'lib/images/ui/avatar.png'
  79. else:
  80. r[2] = r[2]
  81. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  82. 'email': r[4] or r[0]}
  83. return d
  84. def get_profile(bootinfo):
  85. """get profile info"""
  86. bootinfo['profile'] = webnotes.user.load_profile()
  87. def add_home_page(bootinfo, doclist):
  88. """load home page"""
  89. if webnotes.session.user=="Guest":
  90. return
  91. home_page = webnotes.get_application_home_page(webnotes.session.user)
  92. try:
  93. page_doclist = webnotes.widgets.page.get(home_page)
  94. except webnotes.PermissionError, e:
  95. page_doclist = webnotes.widgets.page.get('Login Page')
  96. bootinfo['home_page_html'] = page_doclist[0].content
  97. bootinfo['home_page'] = page_doclist[0].name
  98. doclist += page_doclist