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.

boot.py 3.3 KiB

13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. def get_bootinfo():
  13. """build and return boot info"""
  14. bootinfo = webnotes._dict()
  15. doclist = []
  16. # profile
  17. get_profile(bootinfo)
  18. # control panel
  19. cp = webnotes.model.doc.getsingle('Control Panel')
  20. # system info
  21. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  22. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  23. bootinfo['server_date'] = webnotes.utils.nowdate()
  24. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  25. None, "send_print_in_body_and_attachment")
  26. if webnotes.session['user'] != 'Guest':
  27. bootinfo['user_info'] = get_fullnames()
  28. bootinfo['sid'] = webnotes.session['sid'];
  29. # home page
  30. bootinfo.modules = webnotes.get_config().modules
  31. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  32. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  33. tabDocType where ifnull(icon,'')!=''"""))
  34. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  35. tabPage where ifnull(icon,'')!=''""")))
  36. add_home_page(bootinfo, doclist)
  37. add_allowed_pages(bootinfo)
  38. load_translations(bootinfo)
  39. # ipinfo
  40. if webnotes.session['data'].get('ipinfo'):
  41. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  42. # add docs
  43. bootinfo['docs'] = doclist
  44. # plugins
  45. try:
  46. import startup.boot
  47. startup.boot.boot_session(bootinfo)
  48. except ImportError:
  49. pass
  50. from webnotes.model.utils import compress
  51. bootinfo['docs'] = compress(bootinfo['docs'])
  52. return bootinfo
  53. def add_allowed_pages(bootinfo):
  54. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  55. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  56. def load_translations(bootinfo):
  57. webnotes.set_user_lang(webnotes.session.user)
  58. if webnotes.lang != 'en':
  59. from webnotes.translate import get_lang_data
  60. # framework
  61. bootinfo["__messages"] = get_lang_data("../lib/public/js/wn", None, "js")
  62. # doctype and module names
  63. bootinfo["__messages"].update(get_lang_data('../app/public/js', None, "js"))
  64. bootinfo["lang"] = webnotes.lang
  65. def get_fullnames():
  66. """map of user fullnames"""
  67. ret = webnotes.conn.sql("""select name,
  68. concat(ifnull(first_name, ''),
  69. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  70. user_image, gender, email
  71. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  72. d = {}
  73. for r in ret:
  74. if not r[2]:
  75. r[2] = 'lib/images/ui/avatar.png'
  76. else:
  77. r[2] = r[2]
  78. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  79. 'email': r[4] or r[0]}
  80. return d
  81. def get_profile(bootinfo):
  82. """get profile info"""
  83. bootinfo['profile'] = webnotes.user.load_profile()
  84. def add_home_page(bootinfo, doclist):
  85. """load home page"""
  86. if webnotes.session.user=="Guest":
  87. return
  88. home_page = webnotes.get_application_home_page(webnotes.session.user)
  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