feat: Only student progress is recorded in LMS
Changes
- Instructors can freely audit the course and their progress will not be recorded
- Added check for super access for get_program in utils.py
- Guests can view topics page
- Instructors can see explore topic button
- Content Activity is only saved for a student in lms.py
- Modified variable names in topic.py
diff --git a/erpnext/education/doctype/topic/topic.py b/erpnext/education/doctype/topic/topic.py
index 71bfc18..b890935 100644
--- a/erpnext/education/doctype/topic/topic.py
+++ b/erpnext/education/doctype/topic/topic.py
@@ -9,8 +9,8 @@
class Topic(Document):
def get_contents(self):
try:
- course_content_list = self.get_all_children()
- content_data = [frappe.get_doc(course_content.content_type, course_content.content) for course_content in course_content_list]
+ topic_content_list = self.get_all_children()
+ content_data = [frappe.get_doc(topic_content.content_type, topic_content.content) for topic_content in topic_content_list]
except Exception as e:
return None
return content_data
\ No newline at end of file
diff --git a/erpnext/education/utils.py b/erpnext/education/utils.py
index 8166ac7..a88f66b 100644
--- a/erpnext/education/utils.py
+++ b/erpnext/education/utils.py
@@ -70,6 +70,11 @@
except IndexError:
return None
+def check_super_access():
+ current_user = frappe.get_doc('User', frappe.session.user)
+ roles = set([role.role for role in current_user.roles])
+ return bool(roles & {'Administrator', 'Instructor', 'Education Manager', 'System Manager', 'Academic User'})
+
def get_program_enrollment(program_name):
"""
Function to get program enrollments for a particular student for a program
@@ -86,7 +91,7 @@
def get_program(program_name):
program = frappe.get_doc('Program', program_name)
- is_enrolled = bool(get_program_enrollment(program_name))
+ is_enrolled = bool(get_program_enrollment(program_name)) or check_super_access()
return {'program': program, 'is_enrolled': is_enrolled}
def get_course_enrollment(course_name):
diff --git a/erpnext/public/js/education/lms/components/CourseCard.vue b/erpnext/public/js/education/lms/components/CourseCard.vue
index b9cb548..90c0c7b 100644
--- a/erpnext/public/js/education/lms/components/CourseCard.vue
+++ b/erpnext/public/js/education/lms/components/CourseCard.vue
@@ -14,7 +14,7 @@
</span>
</div>
<div class='course-buttons text-center col-xs-4 col-sm-3 col-md-2'>
- <a-button v-if="isLogin"
+ <a-button
:type="buttonType"
size="sm btn-block"
:route="courseRoute"
@@ -61,18 +61,18 @@
}
}
else {
- return " hidden"
+ return "info"
}
},
isLogin() {
return lms.store.checkLogin()
},
buttonName() {
- if(lms.store.checkLogin()){
+ if(lms.store.checkProgramEnrollment(this.program_name)){
return this.courseMeta.flag
}
else {
- return "Enroll"
+ return "Explore"
}
}
},
diff --git a/erpnext/public/js/education/lms/components/TopicCard.vue b/erpnext/public/js/education/lms/components/TopicCard.vue
index 9a3a2c2..3018c02 100644
--- a/erpnext/public/js/education/lms/components/TopicCard.vue
+++ b/erpnext/public/js/education/lms/components/TopicCard.vue
@@ -70,7 +70,7 @@
}
}
else {
- return " hidden"
+ return "info"
}
},
isLogin() {
@@ -78,11 +78,11 @@
return lms.store.checkLogin()
},
buttonName() {
- if(lms.store.checkLogin()){
+ if(lms.store.checkProgramEnrollment(this.program_name)){
return this.topicMeta.flag
}
else {
- return "Enroll"
+ return "Explore"
}
}
},
diff --git a/erpnext/www/lms.py b/erpnext/www/lms.py
index ab06b37..46c2cbc 100644
--- a/erpnext/www/lms.py
+++ b/erpnext/www/lms.py
@@ -110,7 +110,6 @@
import json
quiz_response = json.loads(quiz_response)
quiz = frappe.get_doc("Quiz", quiz_name)
- enrollment = utils.get_course_enrollment(course).name
answers, score, status = quiz.evaluate(quiz_response, quiz_name)
result = {k: ('Correct' if v else 'Wrong') for k,v in answers.items()}
@@ -124,12 +123,14 @@
except:
item['selected_option'] = "Unattempted"
result_data.append(item)
- # result_data = [{'question': key, 'selected_option': frappe.get_value('Options', quiz_response[key], 'option'), 'quiz_result': result[key]} for key in answers]
- add_quiz_activity(enrollment, quiz_name, result_data, score, status)
+ add_quiz_activity(course, quiz_name, result_data, score, status)
return(score)
-def add_quiz_activity(enrollment, quiz_name, result_data, score, status):
+def add_quiz_activity(course, quiz_name, result_data, score, status):
+ if not utils.get_current_student():
+ return None
+ enrollment = utils.get_course_enrollment(course).name
quiz_activity = frappe.get_doc({
"doctype": "Quiz Activity",
"enrollment": enrollment,
@@ -153,6 +154,8 @@
# Academty Activity
@frappe.whitelist()
def add_activity(course, content_type, content):
+ if not utils.get_current_student():
+ return
enrollment = utils.get_course_enrollment(course)
if(utils.check_activity_exists(enrollment.name, content_type, content)):
pass
@@ -174,6 +177,8 @@
:param course_name:
:param program_name:
"""
+ if not utils.get_current_student():
+ return {'flag':'Start Course' }
course_enrollment = utils.get_course_enrollment(course_name)
program_enrollment = utils.get_program_enrollment(program_name)
student = frappe.get_doc("Student", utils.get_current_student())
@@ -184,12 +189,12 @@
progress = course_enrollment.get_progress(student)
count = sum([activity['is_complete'] for activity in progress])
if count == 0:
- return {'flag':'Start Course', 'content_type': progress[0]['content_type'], 'content': progress[0]['content']}
+ return {'flag':'Start Course'}
elif count == len(progress):
- return {'flag':'Completed', 'content_type': progress[0]['content_type'], 'content': progress[0]['content']}
+ return {'flag':'Completed'}
elif count < len(progress):
next_item = next(item for item in progress if item['is_complete']==False)
- return {'flag':'Continue', 'content_type': next_item['content_type'], 'content': next_item['content']}
+ return {'flag':'Continue'}
@frappe.whitelist()
def get_topic_meta(topic_name, course_name):
@@ -198,9 +203,15 @@
:param topic_name:
:param course_name:
"""
+ topic = frappe.get_doc("Topic", topic_name)
+ if not utils.get_current_student():
+ topic_content = topic.get_all_children()
+ if topic_content:
+ return {'flag':'Start Course', 'content_type': topic_content[0].content_type, 'content': topic_content[0].content}
+ else:
+ return None
course_enrollment = utils.get_course_enrollment(course_name)
student = frappe.get_doc("Student", utils.get_current_student())
- topic = frappe.get_doc("Topic", topic_name)
progress = student.get_topic_progress(course_enrollment.name, topic)
if not progress:
return { 'flag':'Start Topic', 'content_type': None, 'content': None }