fix: api and orm
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from ..lms_sketch.livecode import livecode_to_svg
|
from ..lms_sketch.livecode import livecode_to_svg
|
||||||
from ..lesson.lesson import update_progress
|
|
||||||
|
|
||||||
class Exercise(Document):
|
class Exercise(Document):
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
@@ -57,8 +56,5 @@ class Exercise(Document):
|
|||||||
solution=code)
|
solution=code)
|
||||||
doc.insert(ignore_permissions=True)
|
doc.insert(ignore_permissions=True)
|
||||||
|
|
||||||
if not (course.is_mentor(frappe.session.user) or frappe.flags.in_test):
|
|
||||||
update_progress(self.lesson)
|
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
# Copyright (c) 2021, FOSS United and contributors
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from ..lesson.lesson import update_progress
|
||||||
|
|
||||||
class ExerciseSubmission(Document):
|
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)
|
||||||
|
|||||||
@@ -53,7 +53,13 @@ class Lesson(Document):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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",
|
if frappe.db.exists("LMS Course Progress",
|
||||||
{
|
{
|
||||||
"lesson": lesson,
|
"lesson": lesson,
|
||||||
@@ -82,15 +88,20 @@ def update_progress(lesson):
|
|||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
if not all_dynamic_content_submitted(lesson, user):
|
if not all_dynamic_content_submitted(lesson, user):
|
||||||
return
|
return
|
||||||
|
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 = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
|
||||||
course_progress.status = "Complete"
|
course_progress.status = "Complete"
|
||||||
course_progress.save()
|
course_progress.save()
|
||||||
|
|
||||||
def all_dynamic_content_submitted(lesson, user):
|
def all_dynamic_content_submitted(lesson, user):
|
||||||
exercises = frappe.get_all("Exercise", {"lesson": lesson}, ["name"])
|
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, ["name"], pluck="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
|
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
|
return all_exercises_submitted
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||||
<div class="lesson-page">
|
<div class="lesson-page">
|
||||||
|
|
||||||
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}">{{ lesson.title }}</h2>
|
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" data-batch="{{ batch.name }}">{{ lesson.title }}</h2>
|
||||||
|
|
||||||
{% for s in lesson.get_sections() %}
|
{% for s in lesson.get_sections() %}
|
||||||
<div class="section section-{{ s.type }}">
|
<div class="section section-{{ s.type }}">
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
console.log($(".title").hasClass("is_mentor"))
|
|
||||||
if (!$(".title").hasClass("is_mentor")) {
|
if (!$(".title").hasClass("is_mentor")) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "community.lms.doctype.lesson.lesson.save_progress",
|
method: "community.lms.doctype.lesson.lesson.save_progress",
|
||||||
args: {
|
args: {
|
||||||
lesson: $(".title").attr("data-name")
|
lesson: $(".title").attr("data-name"),
|
||||||
|
batch: $(".title").attr("data-batch")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user