Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

93 wiersze
2.8 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 webnotes
  5. from webnotes.website.doctype.website_slideshow.website_slideshow import get_slideshow
  6. doctype = "Web Page"
  7. condition_field = "published"
  8. def get_context(context):
  9. web_page = context.bean
  10. if web_page.doc.slideshow:
  11. web_page.doc.fields.update(get_slideshow(web_page))
  12. web_page.doc.meta_description = web_page.doc.description
  13. # web_page.doc.breadcrumbs = get_breadcrumbs(web_page)
  14. web_page.doc.toc_list = get_toc_list(web_page)
  15. # parent, child, next sibling links
  16. web_page.doc.links = get_navigation_links(web_page)
  17. if web_page.doc.enable_comments:
  18. web_page.doc.comment_list = webnotes.conn.sql("""select
  19. comment, comment_by_fullname, creation
  20. from `tabComment` where comment_doctype="Web Page"
  21. and comment_docname=%s order by creation""", web_page.doc.name, as_dict=1) or []
  22. web_page.doc.fields.update({
  23. "style": web_page.doc.css or "",
  24. "script": web_page.doc.javascript or ""
  25. })
  26. web_page.doc.fields.update(context)
  27. return web_page.doc.fields
  28. def get_breadcrumbs(web_page):
  29. breadcrumbs = []
  30. def add_parent_of(web_page):
  31. parent = webnotes.conn.sql("""select name, page_name, title from `tabWeb Page`
  32. where exists (select parent from `tabTable of Contents`
  33. where `tabTable of Contents`.parent=`tabWeb Page`.name
  34. and web_page=%s)""", web_page, as_dict=True)
  35. if parent and parent[0]:
  36. parent = parent[0]
  37. add_parent_of(parent.name)
  38. breadcrumbs.append(parent)
  39. add_parent_of(web_page.doc.name)
  40. return breadcrumbs
  41. def get_toc_list(web_page):
  42. toc_list = web_page.doclist.get({"parentfield": "toc"})
  43. if not toc_list: return []
  44. out = webnotes.conn.sql("""select name, page_name, title
  45. from `tabWeb Page` where name in (%s)""" % \
  46. (", ".join(["%s"]*len(toc_list))),
  47. tuple([d.web_page for d in toc_list]),
  48. as_dict=True)
  49. toc_idx = dict(((toc.web_page, toc.idx) for toc in toc_list))
  50. return sorted(out, key=lambda x: toc_idx.get(x.name))
  51. def get_navigation_links(web_page):
  52. links = {}
  53. if web_page.doc.toc_list:
  54. links["child"] = web_page.doc.toc_list[0]
  55. if web_page.doc.breadcrumbs:
  56. if web_page.doc.breadcrumbs[-1]:
  57. links["parent"] = web_page.doc.breadcrumbs[-1]
  58. def set_next(current, parent, breadcrumbs):
  59. web_page = webnotes.get_obj("Web Page", parent)
  60. toc_list = web_page.get_toc_list()
  61. for i, toc in enumerate(toc_list):
  62. if toc.name == current and ((i+1)<len(toc_list)):
  63. links["next"] = toc_list[i+1]
  64. break
  65. if not links.get("next") and breadcrumbs:
  66. set_next(parent, breadcrumbs[-1].name, breadcrumbs[:-1])
  67. set_next(web_page.doc.name, web_page.doc.breadcrumbs[-1].name, web_page.doc.breadcrumbs[:-1])
  68. return links