fix: save lesson details in quiz
This commit is contained in:
1
frontend/components.d.ts
vendored
1
frontend/components.d.ts
vendored
@@ -23,6 +23,7 @@ declare module 'vue' {
|
|||||||
BatchCourses: typeof import('./src/components/BatchCourses.vue')['default']
|
BatchCourses: typeof import('./src/components/BatchCourses.vue')['default']
|
||||||
BatchDashboard: typeof import('./src/components/BatchDashboard.vue')['default']
|
BatchDashboard: typeof import('./src/components/BatchDashboard.vue')['default']
|
||||||
BatchFeedback: typeof import('./src/components/BatchFeedback.vue')['default']
|
BatchFeedback: typeof import('./src/components/BatchFeedback.vue')['default']
|
||||||
|
BatchIcon: typeof import('./src/components/Icons/BatchIcon.vue')['default']
|
||||||
BatchOverlay: typeof import('./src/components/BatchOverlay.vue')['default']
|
BatchOverlay: typeof import('./src/components/BatchOverlay.vue')['default']
|
||||||
BatchStudentProgress: typeof import('./src/components/Modals/BatchStudentProgress.vue')['default']
|
BatchStudentProgress: typeof import('./src/components/Modals/BatchStudentProgress.vue')['default']
|
||||||
BatchStudents: typeof import('./src/components/BatchStudents.vue')['default']
|
BatchStudents: typeof import('./src/components/BatchStudents.vue')['default']
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ const { updateOnboardingStep } = useOnboarding('learning')
|
|||||||
|
|
||||||
const existingQuestion = reactive({
|
const existingQuestion = reactive({
|
||||||
question: '',
|
question: '',
|
||||||
marks: 0,
|
marks: 1,
|
||||||
})
|
})
|
||||||
const question = reactive({
|
const question = reactive({
|
||||||
question: '',
|
question: '',
|
||||||
|
|||||||
@@ -11,66 +11,34 @@ import json
|
|||||||
|
|
||||||
|
|
||||||
class CourseLesson(Document):
|
class CourseLesson(Document):
|
||||||
def validate(self):
|
def on_update(self):
|
||||||
# self.check_and_create_folder()
|
|
||||||
self.validate_quiz_id()
|
self.validate_quiz_id()
|
||||||
|
|
||||||
def validate_quiz_id(self):
|
def validate_quiz_id(self):
|
||||||
if self.quiz_id and not frappe.db.exists("LMS Quiz", self.quiz_id):
|
if self.quiz_id and not frappe.db.exists("LMS Quiz", self.quiz_id):
|
||||||
frappe.throw(_("Invalid Quiz ID"))
|
frappe.throw(_("Invalid Quiz ID"))
|
||||||
|
|
||||||
def on_update(self):
|
if self.content:
|
||||||
dynamic_documents = ["Exercise", "Quiz"]
|
self.save_lesson_details_in_quiz(self.content)
|
||||||
for section in dynamic_documents:
|
|
||||||
self.update_lesson_name_in_document(section)
|
|
||||||
|
|
||||||
def update_lesson_name_in_document(self, section):
|
if self.instructor_content:
|
||||||
doctype_map = {"Exercise": "LMS Exercise", "Quiz": "LMS Quiz"}
|
self.save_lesson_details_in_quiz(self.instructor_content)
|
||||||
macros = find_macros(self.body)
|
|
||||||
documents = [value for name, value in macros if name == section]
|
|
||||||
index = 1
|
|
||||||
for name in documents:
|
|
||||||
e = frappe.get_doc(doctype_map[section], name)
|
|
||||||
e.lesson = self.name
|
|
||||||
e.index_ = index
|
|
||||||
e.course = self.course
|
|
||||||
e.save(ignore_permissions=True)
|
|
||||||
index += 1
|
|
||||||
self.update_orphan_documents(doctype_map[section], documents)
|
|
||||||
|
|
||||||
def update_orphan_documents(self, doctype, documents):
|
def save_lesson_details_in_quiz(self, content):
|
||||||
"""Updates the documents that were previously part of this lesson,
|
content = json.loads(self.content)
|
||||||
but not any more.
|
for block in content.get("blocks"):
|
||||||
"""
|
if block.get("type") == "quiz":
|
||||||
linked_documents = {
|
quiz = block.get("data").get("quiz")
|
||||||
row["name"] for row in frappe.get_all(doctype, {"lesson": self.name})
|
if not frappe.db.exists("LMS Quiz", quiz):
|
||||||
}
|
frappe.throw(_("Invalid Quiz ID in content"))
|
||||||
active_documents = set(documents)
|
frappe.db.set_value(
|
||||||
orphan_documents = linked_documents - active_documents
|
"LMS Quiz",
|
||||||
for name in orphan_documents:
|
quiz,
|
||||||
ex = frappe.get_doc(doctype, name)
|
{
|
||||||
ex.lesson = None
|
"course": self.course,
|
||||||
ex.course = None
|
"lesson": self.name,
|
||||||
ex.index_ = 0
|
},
|
||||||
ex.save(ignore_permissions=True)
|
)
|
||||||
|
|
||||||
def check_and_create_folder(self):
|
|
||||||
args = {
|
|
||||||
"doctype": "File",
|
|
||||||
"is_folder": True,
|
|
||||||
"file_name": f"{self.name} {self.course}",
|
|
||||||
}
|
|
||||||
if not frappe.db.exists(args):
|
|
||||||
folder = frappe.get_doc(args)
|
|
||||||
folder.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
def get_exercises(self):
|
|
||||||
if not self.body:
|
|
||||||
return []
|
|
||||||
|
|
||||||
macros = find_macros(self.body)
|
|
||||||
exercises = [value for name, value in macros if name == "Exercise"]
|
|
||||||
return [frappe.get_doc("LMS Exercise", name) for name in exercises]
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@@ -102,7 +70,7 @@ def save_progress(lesson, course):
|
|||||||
progress = get_course_progress(course)
|
progress = get_course_progress(course)
|
||||||
capture_progress_for_analytics(progress, course)
|
capture_progress_for_analytics(progress, course)
|
||||||
|
|
||||||
# Had to get doc, as on_change doesn't trigger when you use set_value. The trigger is necesary for badge to get assigned.
|
# Had to get doc, as on_change doesn't trigger when you use set_value. The trigger is necessary for badge to get assigned.
|
||||||
enrollment = frappe.get_doc("LMS Enrollment", membership)
|
enrollment = frappe.get_doc("LMS Enrollment", membership)
|
||||||
enrollment.progress = progress
|
enrollment.progress = progress
|
||||||
enrollment.save()
|
enrollment.save()
|
||||||
|
|||||||
@@ -136,9 +136,15 @@
|
|||||||
"label": "Duration (in minutes)"
|
"label": "Duration (in minutes)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"grid_page_length": 50,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [
|
||||||
"modified": "2025-01-06 11:02:09.749207",
|
{
|
||||||
|
"link_doctype": "LMS Quiz Submission",
|
||||||
|
"link_fieldname": "quiz"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"modified": "2025-04-07 15:03:48.525458",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Quiz",
|
"name": "LMS Quiz",
|
||||||
@@ -190,10 +196,11 @@
|
|||||||
"share": 1
|
"share": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"row_format": "Dynamic",
|
||||||
"show_title_field_in_link": 1,
|
"show_title_field_in_link": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
"title_field": "title",
|
"title_field": "title",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ from fuzzywuzzy import fuzz
|
|||||||
from lms.lms.doctype.course_lesson.course_lesson import save_progress
|
from lms.lms.doctype.course_lesson.course_lesson import save_progress
|
||||||
from lms.lms.utils import (
|
from lms.lms.utils import (
|
||||||
generate_slug,
|
generate_slug,
|
||||||
has_course_moderator_role,
|
|
||||||
has_course_instructor_role,
|
|
||||||
)
|
)
|
||||||
from binascii import Error as BinasciiError
|
from binascii import Error as BinasciiError
|
||||||
from frappe.utils.file_manager import safe_b64decode
|
from frappe.utils.file_manager import safe_b64decode
|
||||||
|
|||||||
Reference in New Issue
Block a user