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 4.0 KiB

13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  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.app_version = webnotes.get_config().app_version
  33. bootinfo.framework_version = webnotes.get_config().framework_version
  34. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  35. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  36. tabDocType where ifnull(icon,'')!=''"""))
  37. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  38. tabPage where ifnull(icon,'')!=''""")))
  39. add_home_page(bootinfo, doclist)
  40. add_allowed_pages(bootinfo)
  41. load_translations(bootinfo)
  42. load_conf_settings(bootinfo)
  43. # ipinfo
  44. if webnotes.session['data'].get('ipinfo'):
  45. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  46. # add docs
  47. bootinfo['docs'] = doclist
  48. # plugins
  49. try:
  50. import startup.boot
  51. startup.boot.boot_session(bootinfo)
  52. except ImportError:
  53. pass
  54. from webnotes.model.utils import compress
  55. bootinfo['docs'] = compress(bootinfo['docs'])
  56. # deal with __slots__ in lang
  57. if bootinfo.lang:
  58. bootinfo.lang = unicode(bootinfo.lang)
  59. bootinfo.metadata_version = webnotes.cache().get_value("metadata_version")
  60. if not bootinfo.metadata_version:
  61. bootinfo.metadata_version = webnotes.reset_metadata_version()
  62. return bootinfo
  63. def load_conf_settings(bootinfo):
  64. from webnotes import conf
  65. for key in ['developer_mode']:
  66. if key in conf: bootinfo[key] = conf.get(key)
  67. def add_allowed_pages(bootinfo):
  68. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  69. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  70. def load_translations(bootinfo):
  71. webnotes.set_user_lang(webnotes.session.user)
  72. if webnotes.lang != 'en':
  73. from webnotes.translate import get_lang_data
  74. from webnotes.utils import get_path
  75. # framework
  76. bootinfo["__messages"] = get_lang_data(get_path("lib","public", "js", "wn"), None, "js")
  77. # doctype and module names
  78. bootinfo["__messages"].update(get_lang_data(get_path("app","public", "js"), None, "js"))
  79. bootinfo["lang"] = webnotes.lang
  80. def get_fullnames():
  81. """map of user fullnames"""
  82. ret = webnotes.conn.sql("""select name,
  83. concat(ifnull(first_name, ''),
  84. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  85. user_image, gender, email
  86. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  87. d = {}
  88. for r in ret:
  89. if not r[2]:
  90. r[2] = 'lib/images/ui/avatar.png'
  91. else:
  92. r[2] = r[2]
  93. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  94. 'email': r[4] or r[0]}
  95. return d
  96. def get_profile(bootinfo):
  97. """get profile info"""
  98. bootinfo['profile'] = webnotes.user.load_profile()
  99. def add_home_page(bootinfo, doclist):
  100. """load home page"""
  101. if webnotes.session.user=="Guest":
  102. return
  103. home_page = webnotes.get_application_home_page(webnotes.session.user)
  104. try:
  105. page_doclist = webnotes.widgets.page.get(home_page)
  106. except (webnotes.DoesNotExistError, webnotes.PermissionError), e:
  107. page_doclist = webnotes.widgets.page.get('desktop')
  108. bootinfo['home_page_html'] = page_doclist[0].content
  109. bootinfo['home_page'] = page_doclist[0].name
  110. doclist += page_doclist