fix: rename parenttype for lesson reference

This commit is contained in:
pateljannat
2021-09-30 11:27:27 +05:30
parent b3840e056f
commit 5488947922
9 changed files with 33 additions and 27 deletions

View File

@@ -13,14 +13,14 @@
"fieldtype": "Link",
"in_list_view": 1,
"label": "Chapter",
"options": "Chapter",
"options": "Course Chapter",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-07-27 16:25:02.903245",
"modified": "2021-09-30 10:35:30.014950",
"modified_by": "Administrator",
"module": "LMS",
"name": "Chapter Reference",

View File

@@ -2,7 +2,7 @@
"actions": [],
"allow_rename": 1,
"autoname": "format:{####} {title}",
"creation": "2021-05-03 05:49:08.383050",
"creation": "2021-05-03 05:49:08.383058",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
@@ -58,7 +58,7 @@
"link_fieldname": "chapter"
}
],
"modified": "2021-09-29 15:33:44.611221",
"modified": "2021-09-29 15:33:44.611223",
"modified_by": "Administrator",
"module": "LMS",
"name": "Course Chapter",

View File

@@ -2,7 +2,7 @@
"actions": [],
"allow_rename": 1,
"autoname": "format:{####} {title}",
"creation": "2021-05-03 06:21:12.995981",
"creation": "2021-05-03 06:21:12.995984",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
@@ -71,7 +71,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-09-29 15:28:51.418015",
"modified": "2021-09-29 15:28:51.418013",
"modified_by": "Administrator",
"module": "LMS",
"name": "Course Lesson",

View File

@@ -13,14 +13,14 @@
"fieldtype": "Link",
"in_list_view": 1,
"label": "Lesson",
"options": "Lesson",
"options": "Course Lesson",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-08-31 10:44:42.048232",
"modified": "2021-09-30 10:35:47.832547",
"modified_by": "Administrator",
"module": "LMS",
"name": "Lesson Reference",

View File

@@ -148,7 +148,7 @@
"links": [
{
"group": "Chapters",
"link_doctype": "Chapter",
"link_doctype": "Course Chapter",
"link_fieldname": "course"
},
{
@@ -167,7 +167,7 @@
"link_fieldname": "course"
}
],
"modified": "2021-09-20 12:00:18.325579",
"modified": "2021-09-30 10:36:48.759994",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",

View File

@@ -153,7 +153,7 @@ class LMSCourse(Document):
"""
chapters = []
for row in self.chapters:
chapter_details = frappe.db.get_value("Chapter", row.chapter,
chapter_details = frappe.db.get_value("Course Chapter", row.chapter,
["name", "title", "description"],
as_dict=True)
chapter_details.idx = row.idx
@@ -217,7 +217,7 @@ class LMSCourse(Document):
if not lesson:
return None
chapter = frappe.db.get_value("Chapters", {"chapter": lesson.parent}, ["idx"], as_dict=True)
chapter = frappe.db.get_value("Chapter Reference", {"chapter": lesson.parent}, ["idx"], as_dict=True)
if not chapter:
return None

View File

@@ -79,7 +79,7 @@
"hidden": 0,
"is_query_report": 0,
"label": "Chapter",
"link_to": "Chapter",
"link_to": "Course Chapter",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
@@ -166,4 +166,4 @@
"type": "DocType"
}
]
}
}

View File

@@ -12,4 +12,4 @@ community.patches.v0_0.course_instructor_update
execute:frappe.delete_doc("DocType", "Discussion Message")
execute:frappe.delete_doc("DocType", "Discussion Thread")
community.patches.v0_0.rename_chapters_and_lessons_doctype
community.patches.v0_0.rename_chapter_and_lesson_doctype #27-09-2021
community.patches.v0_0.rename_chapter_and_lesson_doctype #29-09-2021

View File

@@ -10,25 +10,31 @@ def execute():
if not frappe.db.count("Course Lesson"):
move_lessons()
frappe.delete_doc("DocType", "Chapter")
frappe.delete_doc("DocType", "Lesson")
change_parent_for_lesson_reference()
def move_chapters():
docs = frappe.get_all("Chapter", fields=["*"])
for doc in docs:
if frappe.db.exists("LMS Course", doc.course):
keys = doc
keys.update({"doctype": "Course Chapter"})
del keys["name"]
frappe.get_doc(keys).save()
name = doc.name
doc.update({"doctype": "Course Chapter"})
del doc["name"]
new_doc = frappe.get_doc(doc)
new_doc.save()
frappe.rename_doc("Course Chapter", new_doc.name, name)
def move_lessons():
docs = frappe.get_all("Lesson", fields=["*"])
for doc in docs:
print(frappe.db.exists("Chapter", doc.chapter))
if frappe.db.exists("Chapter", doc.chapter):
keys = doc
print(doc)
keys.update({"doctype": "Course Lesson"})
del keys["name"]
frappe.get_doc(keys).save()
name = doc.name
doc.update({"doctype": "Course Lesson"})
del doc["name"]
new_doc = frappe.get_doc(doc)
new_doc.save()
frappe.rename_doc("Course Lesson", new_doc.name, name)
def change_parent_for_lesson_reference():
lesson_reference = frappe.get_all("Lesson Reference", fields=["name", "parent"])
for reference in lesson_reference:
frappe.db.set_value("Lesson Reference", reference.name, "parenttype", "Course Chapter")