25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

80 satır
3.1 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. from frappe.website.utils import scrub_relative_urls, get_home_page, can_cache
  6. def get_sitemap_options(path):
  7. sitemap_options = None
  8. cache_key = "sitemap_options:{}".format(path)
  9. if can_cache():
  10. sitemap_options = frappe.cache().get_value(cache_key)
  11. if not sitemap_options:
  12. sitemap_options = build_sitemap_options(path)
  13. if can_cache(sitemap_options.no_cache):
  14. frappe.cache().set_value(cache_key, sitemap_options)
  15. return frappe._dict(sitemap_options)
  16. def build_sitemap_options(path):
  17. sitemap_options = frappe._dict(frappe.get_doc("Website Route", path).fields)
  18. home_page = get_home_page()
  19. sitemap_config = frappe.get_doc("Website Template",
  20. sitemap_options.get("website_template")).fields
  21. # get sitemap config fields too
  22. for fieldname in ("base_template_path", "template_path", "controller",
  23. "no_cache", "no_sitemap", "page_name_field", "condition_field"):
  24. sitemap_options[fieldname] = sitemap_config.get(fieldname)
  25. sitemap_options.doctype = sitemap_options.ref_doctype
  26. sitemap_options.title = sitemap_options.page_title
  27. sitemap_options.pathname = sitemap_options.name
  28. # establish hierarchy
  29. sitemap_options.parents = frappe.db.sql("""select name, page_title from `tabWebsite Route`
  30. where lft < %s and rgt > %s order by lft asc""", (sitemap_options.lft, sitemap_options.rgt), as_dict=True)
  31. if not sitemap_options.no_sidebar:
  32. set_sidebar_items(sitemap_options, sitemap_options.pathname, home_page)
  33. if not sitemap_options.children:
  34. set_sidebar_items(sitemap_options, sitemap_options.parent_website_route, home_page)
  35. # determine templates to be used
  36. if not sitemap_options.base_template_path:
  37. app_base = frappe.get_hooks("base_template")
  38. sitemap_options.base_template_path = app_base[0] if app_base else "templates/base.html"
  39. return sitemap_options
  40. def set_sidebar_items(sitemap_options, pathname, home_page):
  41. if pathname==home_page or not pathname:
  42. sitemap_options.children = frappe.db.sql("""select url as name, label as page_title,
  43. 1 as public_read from `tabTop Bar Item` where parentfield='sidebar_items' order by idx""",
  44. as_dict=True)
  45. else:
  46. sitemap_options.children = frappe.db.sql("""select * from `tabWebsite Route`
  47. where ifnull(parent_website_route,'')=%s
  48. and public_read=1
  49. order by idx, page_title asc""", pathname, as_dict=True)
  50. if sitemap_options.children:
  51. # if children are from generator and sort order is specified, then get that condition
  52. website_template = frappe.get_doc("Website Template", sitemap_options.children[0].website_template)
  53. if website_template.sort_by!="name":
  54. sitemap_options.children = frappe.db.sql("""select t1.* from
  55. `tabWebsite Route` t1, `tab{ref_doctype}` t2
  56. where ifnull(t1.parent_website_route,'')=%s
  57. and t1.public_read=1
  58. and t1.docname = t2.name
  59. order by t2.{sort_by} {sort_order}""".format(**website_template.fields),
  60. pathname, as_dict=True)
  61. sitemap_options.children = [frappe.get_doc("Website Route", pathname).fields] + sitemap_options.children