fix: api and orm

This commit is contained in:
pateljannat
2021-06-02 20:19:36 +05:30
parent 4fd7af053b
commit 671b4a0650
5 changed files with 30 additions and 18 deletions

View File

@@ -4,7 +4,6 @@
import frappe
from frappe.model.document import Document
from ..lms_sketch.livecode import livecode_to_svg
from ..lesson.lesson import update_progress
class Exercise(Document):
def before_save(self):
@@ -57,8 +56,5 @@ class Exercise(Document):
solution=code)
doc.insert(ignore_permissions=True)
if not (course.is_mentor(frappe.session.user) or frappe.flags.in_test):
update_progress(self.lesson)
return doc

View File

@@ -1,8 +1,13 @@
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
# import frappe
import frappe
from frappe.model.document import Document
from ..lesson.lesson import update_progress
class ExerciseSubmission(Document):
pass
def after_insert(self):
course_details = frappe.get_doc("LMS Course", self.course)
if not (course_details.is_mentor(frappe.session.user) or frappe.flags.in_test):
update_progress(self.lesson)

View File

@@ -53,7 +53,13 @@ class Lesson(Document):
return
@frappe.whitelist()
def save_progress(lesson):
def save_progress(lesson, batch):
if not frappe.db.exists("LMS Batch Membership",
{
"member": frappe.session.user,
"batch": batch
}):
return
if frappe.db.exists("LMS Course Progress",
{
"lesson": lesson,
@@ -82,15 +88,20 @@ def update_progress(lesson):
user = frappe.session.user
if not all_dynamic_content_submitted(lesson, user):
return
course_progress = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
course_progress.status = "Complete"
course_progress.save()
if frappe.db.exists("LMS Course Progress", {"lesson": lesson, "owner": user}):
course_progress = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
course_progress.status = "Complete"
course_progress.save()
def all_dynamic_content_submitted(lesson, user):
exercises = frappe.get_all("Exercise", {"lesson": lesson}, ["name"])
all_exercises_submitted = True
for exercise in exercises:
if not frappe.db.count("Exercise Submission", {"exercise": exercise.name, "owner": user}):
all_exercises_submitted = False
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, ["name"], pluck="name")
all_exercises_submitted = False
print(exercise_names)
query = {
"exercise": ["in", exercise_names],
"owner": user
}
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
all_exercises_submitted = True
return all_exercises_submitted