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 年之前
12 年之前
12 年之前
13 年之前
13 年之前
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. hooks = webnotes.get_hooks()
  17. doclist = []
  18. # profile
  19. get_profile(bootinfo)
  20. # control panel
  21. cp = webnotes.model.doc.getsingle('Control Panel')
  22. # system info
  23. bootinfo['control_panel'] = webnotes._dict(cp.copy())
  24. bootinfo['sysdefaults'] = webnotes.defaults.get_defaults()
  25. bootinfo['server_date'] = webnotes.utils.nowdate()
  26. bootinfo["send_print_in_body_and_attachment"] = webnotes.conn.get_value("Email Settings",
  27. None, "send_print_in_body_and_attachment")
  28. if webnotes.session['user'] != 'Guest':
  29. bootinfo['user_info'] = get_fullnames()
  30. bootinfo['sid'] = webnotes.session['sid'];
  31. # home page
  32. bootinfo.modules = {}
  33. for app in webnotes.get_installed_apps():
  34. desktop_icons_path = webnotes.get_pymodule_path(app, "desktop.json")
  35. bootinfo.modules.update(json.loads(webnotes.read_file(desktop_icons_path) or "{}"))
  36. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  37. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  38. tabDocType where ifnull(icon,'')!=''"""))
  39. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  40. tabPage where ifnull(icon,'')!=''""")))
  41. add_home_page(bootinfo, doclist)
  42. add_allowed_pages(bootinfo)
  43. load_translations(bootinfo)
  44. load_conf_settings(bootinfo)
  45. load_startup_js(bootinfo)
  46. # ipinfo
  47. if webnotes.session['data'].get('ipinfo'):
  48. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  49. # add docs
  50. bootinfo['docs'] = doclist
  51. for method in hooks.boot_session or []:
  52. webnotes.get_attr(method)(bootinfo)
  53. from webnotes.model.utils import compress
  54. bootinfo['docs'] = compress(bootinfo['docs'])
  55. # deal with __slots__ in lang
  56. if bootinfo.lang:
  57. bootinfo.lang = unicode(bootinfo.lang)
  58. bootinfo.metadata_version = webnotes.cache().get_value("metadata_version")
  59. if not bootinfo.metadata_version:
  60. bootinfo.metadata_version = webnotes.reset_metadata_version()
  61. return bootinfo
  62. def load_conf_settings(bootinfo):
  63. from webnotes import conf
  64. for key in ['developer_mode']:
  65. if key in conf: bootinfo[key] = conf.get(key)
  66. def add_allowed_pages(bootinfo):
  67. bootinfo.page_info = dict(webnotes.conn.sql("""select distinct parent, modified from `tabPage Role`
  68. where role in ('%s')""" % "', '".join(webnotes.get_roles())))
  69. def load_translations(bootinfo):
  70. webnotes.set_user_lang(webnotes.session.user)
  71. if webnotes.lang != 'en':
  72. bootinfo["__messages"] = webnotes.get_lang_dict("include")
  73. bootinfo["lang"] = webnotes.lang
  74. def get_fullnames():
  75. """map of user fullnames"""
  76. ret = webnotes.conn.sql("""select name,
  77. concat(ifnull(first_name, ''),
  78. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  79. user_image, gender, email
  80. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  81. d = {}
  82. for r in ret:
  83. if not r[2]:
  84. r[2] = '/assets/webnotes/images/ui/avatar.png'
  85. else:
  86. r[2] = r[2]
  87. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  88. 'email': r[4] or r[0]}
  89. return d
  90. def load_startup_js(bootinfo):
  91. bootinfo.startup_js = ""
  92. for method in webnotes.get_hooks().startup_js or []:
  93. bootinfo.startup_js += webnotes.get_attr(method)()
  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