2020-06-17 10:46:59 +00:00
|
|
|
import frappe
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
2022-03-28 13:22:46 +00:00
|
|
|
context.align_greeting = ""
|
2020-06-17 10:46:59 +00:00
|
|
|
setting = frappe.get_doc("Support Settings")
|
|
|
|
|
|
|
|
context.greeting_title = setting.greeting_title
|
|
|
|
context.greeting_subtitle = setting.greeting_subtitle
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
# Support content
|
|
|
|
favorite_articles = get_favorite_articles_by_page_view()
|
|
|
|
if len(favorite_articles) < 6:
|
|
|
|
name_list = []
|
|
|
|
if favorite_articles:
|
|
|
|
for article in favorite_articles:
|
|
|
|
name_list.append(article.name)
|
2022-03-28 13:22:46 +00:00
|
|
|
for record in frappe.get_all(
|
|
|
|
"Help Article",
|
2021-08-19 08:11:10 +00:00
|
|
|
fields=["title", "content", "route", "category"],
|
2022-03-28 13:22:46 +00:00
|
|
|
filters={"name": ["not in", tuple(name_list)], "published": 1},
|
|
|
|
order_by="creation desc",
|
|
|
|
limit=(6 - len(favorite_articles)),
|
|
|
|
):
|
2020-06-17 10:46:59 +00:00
|
|
|
favorite_articles.append(record)
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
context.favorite_article_list = get_favorite_articles(favorite_articles)
|
|
|
|
context.help_article_list = get_help_article_list()
|
2021-08-19 08:11:10 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
def get_favorite_articles_by_page_view():
|
|
|
|
return frappe.db.sql(
|
2022-03-28 13:22:46 +00:00
|
|
|
"""
|
2020-06-17 10:46:59 +00:00
|
|
|
SELECT
|
|
|
|
t1.name as name,
|
|
|
|
t1.title as title,
|
|
|
|
t1.content as content,
|
|
|
|
t1.route as route,
|
|
|
|
t1.category as category,
|
2021-08-19 08:11:10 +00:00
|
|
|
count(t1.route) as count
|
|
|
|
FROM `tabHelp Article` AS t1
|
2020-06-17 10:46:59 +00:00
|
|
|
INNER JOIN
|
2021-08-19 08:11:10 +00:00
|
|
|
`tabWeb Page View` AS t2
|
|
|
|
ON t1.route = t2.path
|
2020-06-17 10:46:59 +00:00
|
|
|
WHERE t1.published = 1
|
2021-08-19 08:11:10 +00:00
|
|
|
GROUP BY route
|
2020-06-17 10:46:59 +00:00
|
|
|
ORDER BY count DESC
|
|
|
|
LIMIT 6;
|
2022-03-28 13:22:46 +00:00
|
|
|
""",
|
|
|
|
as_dict=True,
|
|
|
|
)
|
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
|
|
|
|
def get_favorite_articles(favorite_articles):
|
2022-03-28 13:22:46 +00:00
|
|
|
favorite_article_list = []
|
2020-06-17 10:46:59 +00:00
|
|
|
for article in favorite_articles:
|
|
|
|
description = frappe.utils.strip_html(article.content)
|
2020-06-17 13:18:15 +00:00
|
|
|
if len(description) > 120:
|
2022-03-28 13:22:46 +00:00
|
|
|
description = description[:120] + "..."
|
2020-06-17 10:46:59 +00:00
|
|
|
favorite_article_dict = {
|
2022-03-28 13:22:46 +00:00
|
|
|
"title": article.title,
|
|
|
|
"description": description,
|
|
|
|
"route": article.route,
|
|
|
|
"category": article.category,
|
2020-06-17 10:46:59 +00:00
|
|
|
}
|
|
|
|
favorite_article_list.append(favorite_article_dict)
|
|
|
|
return favorite_article_list
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-06-17 10:46:59 +00:00
|
|
|
def get_help_article_list():
|
2022-03-28 13:22:46 +00:00
|
|
|
help_article_list = []
|
2020-06-17 10:46:59 +00:00
|
|
|
category_list = frappe.get_all("Help Category", fields="name")
|
|
|
|
for category in category_list:
|
2022-03-28 13:22:46 +00:00
|
|
|
help_articles = frappe.get_all(
|
|
|
|
"Help Article",
|
|
|
|
fields="*",
|
|
|
|
filters={"category": category.name, "published": 1},
|
|
|
|
order_by="modified desc",
|
|
|
|
limit=5,
|
|
|
|
)
|
2020-06-17 10:46:59 +00:00
|
|
|
if help_articles:
|
|
|
|
help_aricles_per_caetgory = {
|
2022-03-28 13:22:46 +00:00
|
|
|
"category": category,
|
|
|
|
"articles": help_articles,
|
2020-06-17 10:46:59 +00:00
|
|
|
}
|
|
|
|
help_article_list.append(help_aricles_per_caetgory)
|
2021-08-19 08:11:10 +00:00
|
|
|
return help_article_list
|