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.
 
 
 
 
 
 

75 regels
2.2 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. no_sitemap = 1
  5. no_cache = 1
  6. base_template_path = "templates/www/desk.html"
  7. import os, re
  8. import frappe
  9. from frappe import _
  10. import frappe.sessions
  11. def get_context(context):
  12. if (frappe.session.user == "Guest" or
  13. frappe.db.get_value("User", frappe.session.user, "user_type")=="Website User"):
  14. frappe.throw(_("You are not permitted to access this page."), frappe.PermissionError)
  15. hooks = frappe.get_hooks()
  16. try:
  17. boot = frappe.sessions.get()
  18. except Exception as e:
  19. boot = frappe._dict(status='failed', error = str(e))
  20. print frappe.get_traceback()
  21. # this needs commit
  22. csrf_token = frappe.sessions.get_csrf_token()
  23. frappe.db.commit()
  24. boot_json = frappe.as_json(boot)
  25. # remove script tags from boot
  26. boot_json = re.sub("\<script\>[^<]*\</script\>", "", boot_json)
  27. return {
  28. "build_version": get_build_version(),
  29. "include_js": hooks["app_include_js"],
  30. "include_css": hooks["app_include_css"],
  31. "sounds": hooks["sounds"],
  32. "boot": boot if context.get("for_mobile") else boot_json,
  33. "csrf_token": csrf_token,
  34. "background_image": (boot.status != 'failed' and
  35. (boot.user.background_image or boot.default_background_image) or None),
  36. "google_analytics_id": frappe.conf.get("google_analytics_id"),
  37. "mixpanel_id": frappe.conf.get("mixpanel_id")
  38. }
  39. @frappe.whitelist()
  40. def get_desk_assets(build_version):
  41. """Get desk assets to be loaded for mobile app"""
  42. data = get_context({"for_mobile": True})
  43. assets = [{"type": "js", "data": ""}, {"type": "css", "data": ""}]
  44. if build_version != data["build_version"]:
  45. # new build, send assets
  46. for path in data["include_js"]:
  47. with open(os.path.join(frappe.local.sites_path, path) ,"r") as f:
  48. assets[0]["data"] = assets[0]["data"] + "\n" + unicode(f.read(), "utf-8")
  49. for path in data["include_css"]:
  50. with open(os.path.join(frappe.local.sites_path, path) ,"r") as f:
  51. assets[1]["data"] = assets[1]["data"] + "\n" + unicode(f.read(), "utf-8")
  52. return {
  53. "build_version": data["build_version"],
  54. "boot": data["boot"],
  55. "assets": assets
  56. }
  57. def get_build_version():
  58. return str(os.path.getmtime(os.path.join(frappe.local.sites_path, "assets", "js",
  59. "desk.min.js")))