Skip to content

Commit

Permalink
Merge pull request #247 from mgiadach/fix/patch-publish
Browse files Browse the repository at this point in the history
fix: add new pages to sidebar after patch approval
  • Loading branch information
rmehta authored Jun 12, 2024
2 parents c01ecd2 + 468e7f7 commit 5976585
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions wiki/wiki/doctype/wiki_page_patch/wiki_page_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def update_old_page(self):

def update_sidebars(self):
if not hasattr(self, "new_sidebar_items") or not self.new_sidebar_items:
self.new_sidebar_items = "{}"
self.insert_on_sidebar(self.new_sidebar_group, self.new_wiki_page.name)
return

sidebars = json.loads(self.new_sidebar_items)

Expand All @@ -73,24 +74,25 @@ def update_sidebars(self):
idx += 1
if item["name"] == "new-wiki-page":
item["name"] = self.new_wiki_page.name
wiki_space_name = frappe.get_value(
"Wiki Space", {"route": self.wiki_page_doc.get_space_route()}
)

wiki_space = frappe.get_doc("Wiki Space", wiki_space_name)
wiki_space.append(
"wiki_sidebars",
{
"wiki_page": self.new_wiki_page.name,
"parent_label": list(sidebars)[-1],
},
)
wiki_space.save()
self.insert_on_sidebar(list(sidebars)[-1], self.new_wiki_page.name)

frappe.db.set_value(
"Wiki Group Item", {"wiki_page": str(item["name"])}, {"parent_label": sidebar, "idx": idx}
)

def insert_on_sidebar(self, parent_label: str, wiki_page: str):
wiki_space_name = frappe.get_value("Wiki Space", {"route": self.wiki_page_doc.get_space_route()})

wiki_space = frappe.get_doc("Wiki Space", wiki_space_name)
wiki_space.append(
"wiki_sidebars",
{
"wiki_page": wiki_page,
"parent_label": parent_label,
},
)
wiki_space.save()


@frappe.whitelist()
def add_comment_to_patch(reference_name, content):
Expand Down

0 comments on commit 5976585

Please sign in to comment.