|
3 | 3 |
|
4 | 4 | import frappe |
5 | 5 | from frappe.website.page_renderers.document_page import DocumentPage |
6 | | -from frappe.website.router import get_doctypes_with_web_view |
7 | 6 | from frappe.website.utils import build_response |
8 | 7 |
|
9 | 8 | from wiki.wiki.doctype.wiki_page.wiki_page import get_sidebar_for_page |
|
13 | 12 |
|
14 | 13 | class WikiPageRenderer(DocumentPage): |
15 | 14 | def can_render(self): |
16 | | - if wiki_space_name := frappe.get_value("Wiki Space", {"route": self.path}): |
17 | | - wiki_space = frappe.get_doc("Wiki Space", wiki_space_name) |
18 | | - topmost_wiki_route = frappe.get_value("Wiki Page", wiki_space.wiki_sidebars[0].wiki_page, "route") |
| 15 | + doctype = "Wiki Page" |
| 16 | + try: |
| 17 | + self.docname = frappe.db.get_value(doctype, {"route": self.path, "published": 1}, "name") |
| 18 | + if self.docname: |
| 19 | + self.doctype = doctype |
| 20 | + return True |
| 21 | + except Exception as e: |
| 22 | + if not frappe.db.is_missing_column(e): |
| 23 | + raise e |
| 24 | + |
| 25 | + if wiki_space_name := frappe.db.get_value("Wiki Space", {"route": self.path}): |
| 26 | + wiki_space = frappe.get_cached_doc("Wiki Space", wiki_space_name) |
| 27 | + topmost_wiki_route = frappe.db.get_value( |
| 28 | + "Wiki Page", wiki_space.wiki_sidebars[0].wiki_page, "route" |
| 29 | + ) |
19 | 30 | frappe.redirect(f"/{quote(topmost_wiki_route)}") |
20 | | - return self.search_in_doctypes_with_web_view() |
21 | | - |
22 | | - def search_in_doctypes_with_web_view(self): |
23 | | - for doctype in get_doctypes_with_web_view(): |
24 | | - if doctype != "Wiki Page": |
25 | | - continue |
26 | | - filters = dict(route=self.path) |
27 | | - meta = frappe.get_meta(doctype) |
28 | | - condition_field = self.get_condition_field(meta) |
29 | | - |
30 | | - if condition_field: |
31 | | - filters[condition_field] = 1 |
32 | | - |
33 | | - try: |
34 | | - self.docname = frappe.db.get_value(doctype, filters, "name") |
35 | | - if self.docname: |
36 | | - self.doctype = doctype |
37 | | - return True |
38 | | - except Exception as e: |
39 | | - if not frappe.db.is_missing_column(e): |
40 | | - raise e |
41 | 31 |
|
42 | 32 | def render(self): |
43 | 33 | html = self.get_html() |
|
0 commit comments