fix: Get title only when necessary (#13831)
* fix: query only if necessary * fix: titile not found * chore: linting * chore: use `not in` * chore: translate title * chore: quotes * chore: quotes
This commit is contained in:
parent
7908fb1284
commit
e9076a1e33
2 changed files with 8 additions and 2 deletions
|
|
@ -931,6 +931,9 @@ def validate_fields(meta):
|
|||
if meta.website_search_field not in fieldname_list:
|
||||
frappe.throw(_("Website Search Field must be a valid fieldname"), InvalidFieldNameError)
|
||||
|
||||
if "title" not in fieldname_list:
|
||||
frappe.throw(_('Field "title" is mandatory if "Website Search Field" is set.'), title=_("Missing Field"))
|
||||
|
||||
def check_timeline_field(meta):
|
||||
if not meta.timeline_field:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -90,19 +90,22 @@ class WebsiteSearch(FullTextSearch):
|
|||
def slugs_with_web_view(_items_to_index):
|
||||
all_routes = []
|
||||
filters = { "has_web_view": 1, "allow_guest_to_view": 1, "index_web_pages_for_search": 1}
|
||||
fields = ["name", "is_published_field", 'website_search_field']
|
||||
fields = ["name", "is_published_field", "website_search_field"]
|
||||
doctype_with_web_views = frappe.get_all("DocType", filters=filters, fields=fields)
|
||||
|
||||
for doctype in doctype_with_web_views:
|
||||
if doctype.is_published_field:
|
||||
docs = frappe.get_all(doctype.name, filters={doctype.is_published_field: 1}, fields=["route", doctype.website_search_field, 'title'])
|
||||
fields=["route", doctype.website_search_field]
|
||||
filters={doctype.is_published_field: 1},
|
||||
if doctype.website_search_field:
|
||||
docs = frappe.get_all(doctype.name, filters=filters, fields=fields.append("title"))
|
||||
for doc in docs:
|
||||
content = frappe.utils.md_to_html(getattr(doc, doctype.website_search_field))
|
||||
soup = BeautifulSoup(content, "html.parser")
|
||||
text_content = soup.text if soup else ""
|
||||
_items_to_index += [frappe._dict(title=doc.title, content=text_content, path=doc.route)]
|
||||
else:
|
||||
docs = frappe.get_all(doctype.name, filters=filters, fields=fields)
|
||||
all_routes += [route.route for route in docs]
|
||||
|
||||
return all_routes
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue