feat: added student profile page

This commit is contained in:
Shivam Mishra 2019-06-05 17:29:48 +05:30
parent 6593263df8
commit 16b4129ede
6 changed files with 128 additions and 32 deletions

View File

@ -96,29 +96,6 @@ class ProgramEnrollment(Document):
quiz_progress.program = self.program
return quiz_progress
def get_program_progress(self):
import math
program = frappe.get_doc("Program", self.program)
program_progress = {}
progress = []
for course in program.get_all_children():
course_progress = lms.get_student_course_details(course.course, self.program)
is_complete = False
if course_progress['flag'] == "Completed":
is_complete = True
progress.append({'course_name': course.course_name, 'name': course.course, 'is_complete': is_complete})
program_progress['progress'] = progress
program_progress['name'] = self.program
program_progress['program'] = frappe.get_value("Program", self.program, 'program_name')
try:
program_progress['percentage'] = math.ceil((sum([item['is_complete'] for item in progress] * 100)/len(progress)))
except ZeroDivisionError:
program_progress['percentage'] = 0
return program_progress
@frappe.whitelist()
def get_program_courses(doctype, txt, searchfield, start, page_len, filters):
if filters.get('program'):

View File

@ -239,7 +239,7 @@ def get_quiz(quiz_name, course):
status, score, result = check_quiz_completion(quiz, course_enrollment)
return {'questions': questions, 'activity': {'is_complete': status, 'score': score, 'result': result}}
def get_student_topic_details(topic, course_name, program):
def get_topic_progress(topic, course_name, program):
"""
Return the porgress of a course in a program as well as the content to continue from.
:param topic_name:
@ -260,7 +260,7 @@ def get_student_topic_details(topic, course_name, program):
elif count < len(progress):
return {'completed': False, 'started': True}
def get_student_course_details(course, program):
def get_course_progress(course, program):
"""
Return the porgress of a course in a program as well as the content to continue from.
:param topic_name:
@ -269,16 +269,14 @@ def get_student_course_details(course, program):
course_progress = []
for course_topic in course.topics:
topic = frappe.get_doc("Topic", course_topic.topic)
progress = get_student_topic_details(topic, course.name, program)
progress = get_topic_progress(topic, course.name, program)
if progress:
course_progress.append(progress)
if course_progress:
number_of_completed_topics = sum([activity['completed'] for activity in course_progress])
total_topics = len(course_progress)
print("course_progress", course_progress)
print("number_of_completed_topics", number_of_completed_topics)
print("total_topics", total_topics)
if total_topics == 1:
return course_progress[0]
if number_of_completed_topics == 0:
return {'completed': False, 'started': False}
if number_of_completed_topics == total_topics:
@ -288,6 +286,47 @@ def get_student_course_details(course, program):
return None
def get_program_progress(program):
program_progress = []
if not program.courses:
return None
for program_course in program.courses:
course = frappe.get_doc("Course", program_course.course)
progress = get_course_progress(course, program.name)
if progress:
progress['name'] = course.name
progress['course'] = course.course_name
program_progress.append(progress)
if program_progress:
return program_progress
return None
def get_program_completion(program):
topics = frappe.db.sql("""select `tabcourse topic`.topic, `tabcourse topic`.parent
from `tabcourse topic`,
`tabprogram course`
where `tabcourse topic`.parent = `tabprogram course`.course
and `tabprogram course`.parent = '{0}'""".format(program.name))
progress = []
for topic in topics:
topic_doc = frappe.get_doc('Topic', topic[0])
topic_progress = get_topic_progress(topic_doc, topic[1], program.name)
if topic_progress:
progress.append(topic_progress)
if progress:
number_of_completed_topics = sum([activity['completed'] for activity in progress if activity])
total_topics = len(progress)
try:
return int((float(number_of_completed_topics)/total_topics)*100)
except ZeroDivisionError:
return 0
return 0
def create_student_from_current_user():
user = frappe.get_doc("User", frappe.session.user)

View File

@ -15,5 +15,5 @@ def get_context(context):
context.progress = get_topic_progress(context.topics, course, context.program)
def get_topic_progress(topics, course, program):
progress = {topic.name: utils.get_student_topic_details(topic, course.name, program) for topic in topics}
progress = {topic.name: utils.get_topic_progress(topic, course.name, program) for topic in topics}
return progress

View File

@ -0,0 +1,56 @@
{% extends "templates/base.html" %}
{% block title %}Profile{% endblock %}
{% from "www/lms/macros/hero.html" import hero %}
{% macro card(program) %}
<div class="col-sm-4 mb-4 text-left">
<a href="/lms/program?program={{ program.name }}" class="no-decoration no-underline">
<div class="card h-100">
<div class='card-body'>
<h5 class='card-title'>{{ program.program }}</h5>
<ul class="list-unstyled text-muted">
{% for course in program.progress %}
<li>
{% if course.completed %} <span class="indicator green">
{% elif course.started %} <span class="indicator orange">
{% else %} <span class="indicator blue">{{ course }}</span>
{% endif %}
<a class="text-muted" href="/lms/course?program={{ program.name }}&name={{ course.course }}">{{ course.course }}</a>
</span>
</li>
{% endfor %}
</ul>
</div>
<div class='card-footer'>
<span class="small">{{ program.completion }}% Complete</span>
</div>
</div>
</a>
</div>
{% endmacro %}
{% block content %}
<section class="section">
<div class='container pb-5'>
<div class="mb-3 row">
<div class="col-md-7">
<a href="/lms" class="text-muted">
<i class="fa fa-chevron-left"></i> Back to Home
</a>
</div>
<div class="col-md-5 text-right">
<a href="/update-profile?name={{ frappe.session.user }}" target="blank" class="mt-0 text-muted">Edit Profile</a>
</div>
</div>
<h1>{{ student.first_name }} {{ student.last_name or '' }}</h1>
<p class="lead" style="max-width: 100%;">{{ student.name }}</p>
</div>
<div class='container'>
<div class="row mt-5">
{% for program in progress %}
{{ card(program) }}
{% endfor %}
</div>
</div>
</section>
{% endblock %}

View File

@ -0,0 +1,24 @@
from __future__ import unicode_literals
import erpnext.education.utils as utils
import frappe
no_cache = 1
def get_context(context):
context.student = utils.get_current_student()
context.progress = get_program_progress(context.student.name)
def get_program_progress(student):
enrolled_programs = frappe.get_all("Program Enrollment", filters={'student':student}, fields=['program'])
student_progress = []
for list_item in enrolled_programs:
program = frappe.get_doc("Program", list_item.program)
progress = utils.get_program_progress(program)
completion = utils.get_program_completion(program)
student_progress.append({'program': program.program_name, 'name': program.name, 'progress':progress, 'completion': completion})
return student_progress

View File

@ -18,5 +18,5 @@ def get_program(program_name):
frappe.throw(_("Program {0} does not exist.".format(program_name)))
def get_course_progress(courses, program):
progress = {course.name: utils.get_student_course_details(course, program) for course in courses}
progress = {course.name: utils.get_course_progress(course, program) for course in courses}
return progress