2021-09-02 11:14:59 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
import frappe
|
2018-05-22 06:27:21 +00:00
|
|
|
import requests
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2018-05-22 06:27:21 +00:00
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
|
|
|
settings = frappe.get_doc("Support Settings", "Support Settings")
|
|
|
|
s = settings
|
|
|
|
|
|
|
|
# Get Started sections
|
|
|
|
sections = json.loads(s.get_started_sections)
|
|
|
|
context.get_started_sections = sections
|
|
|
|
|
|
|
|
# Forum posts
|
|
|
|
topics_data, post_params = get_forum_posts(s)
|
|
|
|
context.post_params = post_params
|
|
|
|
context.forum_url = s.forum_url
|
|
|
|
context.topics = topics_data[:3]
|
|
|
|
|
|
|
|
# Issues
|
2018-06-12 12:09:12 +00:00
|
|
|
if frappe.session.user != "Guest":
|
|
|
|
context.issues = frappe.get_list("Issue", fields=["name", "status", "subject", "modified"])[:3]
|
|
|
|
else:
|
|
|
|
context.issues = []
|
2018-05-22 06:27:21 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2018-05-22 06:27:21 +00:00
|
|
|
def get_forum_posts(s):
|
2022-03-28 13:22:46 +00:00
|
|
|
response = requests.get(s.forum_url + "/" + s.get_latest_query)
|
2018-05-22 06:27:21 +00:00
|
|
|
response.raise_for_status()
|
|
|
|
response_json = response.json()
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
topics_data = {} # it will actually be an array
|
|
|
|
key_list = s.response_key_list.split(",")
|
2018-05-22 06:27:21 +00:00
|
|
|
for key in key_list:
|
|
|
|
topics_data = response_json.get(key) if not topics_data else topics_data.get(key)
|
|
|
|
|
|
|
|
for topic in topics_data:
|
2022-03-28 13:22:46 +00:00
|
|
|
topic["link"] = s.forum_url + "/" + s.post_route_string + "/" + str(topic.get(s.post_route_key))
|
2018-05-22 06:27:21 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
post_params = {"title": s.post_title_key, "description": s.post_description_key}
|
2018-05-22 06:27:21 +00:00
|
|
|
return topics_data, post_params
|