Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

boot.py 4.0 KiB

13 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. try:
  35. bootinfo.modules.update(webnotes.get_attr(app + ".config.desktop.data") or {})
  36. except ImportError, e:
  37. pass
  38. bootinfo.hidden_modules = webnotes.conn.get_global("hidden_modules")
  39. bootinfo.doctype_icons = dict(webnotes.conn.sql("""select name, icon from
  40. tabDocType where ifnull(icon,'')!=''"""))
  41. bootinfo.doctype_icons.update(dict(webnotes.conn.sql("""select name, icon from
  42. tabPage where ifnull(icon,'')!=''""")))
  43. add_home_page(bootinfo, doclist)
  44. add_allowed_pages(bootinfo)
  45. load_translations(bootinfo)
  46. load_conf_settings(bootinfo)
  47. load_startup_js(bootinfo)
  48. # ipinfo
  49. if webnotes.session['data'].get('ipinfo'):
  50. bootinfo['ipinfo'] = webnotes.session['data']['ipinfo']
  51. # add docs
  52. bootinfo['docs'] = doclist
  53. for method in hooks.boot_session or []:
  54. webnotes.get_attr(method)(bootinfo)
  55. from webnotes.model.utils import compress
  56. bootinfo['docs'] = compress(bootinfo['docs'])
  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. bootinfo["__messages"] = webnotes.get_lang_dict("include")
  74. bootinfo["lang"] = webnotes.lang
  75. def get_fullnames():
  76. """map of user fullnames"""
  77. ret = webnotes.conn.sql("""select name,
  78. concat(ifnull(first_name, ''),
  79. if(ifnull(last_name, '')!='', ' ', ''), ifnull(last_name, '')),
  80. user_image, gender, email
  81. from tabProfile where ifnull(enabled, 0)=1""", as_list=1)
  82. d = {}
  83. for r in ret:
  84. if not r[2]:
  85. r[2] = '/assets/webnotes/images/ui/avatar.png'
  86. else:
  87. r[2] = r[2]
  88. d[r[0]]= {'fullname': r[1], 'image': r[2], 'gender': r[3],
  89. 'email': r[4] or r[0]}
  90. return d
  91. def load_startup_js(bootinfo):
  92. bootinfo.startup_js = ""
  93. for method in webnotes.get_hooks().startup_js or []:
  94. bootinfo.startup_js += webnotes.get_attr(method)()
  95. def get_profile(bootinfo):
  96. """get profile info"""
  97. bootinfo['profile'] = webnotes.user.load_profile()
  98. def add_home_page(bootinfo, doclist):
  99. """load home page"""
  100. if webnotes.session.user=="Guest":
  101. return
  102. home_page = webnotes.get_application_home_page(webnotes.session.user)
  103. try:
  104. page_doclist = webnotes.widgets.page.get(home_page)
  105. except (webnotes.DoesNotExistError, webnotes.PermissionError), e:
  106. page_doclist = webnotes.widgets.page.get('desktop')
  107. bootinfo['home_page_html'] = page_doclist[0].content
  108. bootinfo['home_page'] = page_doclist[0].name
  109. doclist += page_doclist