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.9 KiB

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