style: format code with black

This commit is contained in:
Ankush Menat
2022-03-28 18:52:46 +05:30
parent 21e00da3d6
commit 494bd9ef78
1395 changed files with 91704 additions and 62532 deletions

View File

@@ -4,28 +4,27 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
# Load Query Parameters
try:
program = frappe.form_dict['program']
content = frappe.form_dict['content']
content_type = frappe.form_dict['type']
course = frappe.form_dict['course']
topic = frappe.form_dict['topic']
program = frappe.form_dict["program"]
content = frappe.form_dict["content"]
content_type = frappe.form_dict["type"]
course = frappe.form_dict["course"]
topic = frappe.form_dict["topic"]
except KeyError:
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
# Check if user has access to the content
has_program_access = utils.allowed_program_access(program)
has_content_access = allowed_content_access(program, content, content_type)
if frappe.session.user == "Guest" or not has_program_access or not has_content_access:
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
# Set context for content to be displayer
context.content = frappe.get_doc(content_type, content).as_dict()
context.content_type = content_type
@@ -34,35 +33,43 @@ def get_context(context):
context.topic = topic
topic = frappe.get_doc("Topic", topic)
content_list = [{'content_type':item.content_type, 'content':item.content} for item in topic.topic_content]
content_list = [
{"content_type": item.content_type, "content": item.content} for item in topic.topic_content
]
# Set context for progress numbers
context.position = content_list.index({'content': content, 'content_type': content_type})
context.position = content_list.index({"content": content, "content_type": content_type})
context.length = len(content_list)
# Set context for navigation
context.previous = get_previous_content(content_list, context.position)
context.next = get_next_content(content_list, context.position)
def get_next_content(content_list, current_index):
try:
return content_list[current_index + 1]
except IndexError:
return None
def get_previous_content(content_list, current_index):
if current_index == 0:
return None
else:
return content_list[current_index - 1]
def allowed_content_access(program, content, content_type):
contents_of_program = frappe.db.sql("""select `tabTopic Content`.content, `tabTopic Content`.content_type
contents_of_program = frappe.db.sql(
"""select `tabTopic Content`.content, `tabTopic Content`.content_type
from `tabCourse Topic`,
`tabProgram Course`,
`tabTopic Content`
where `tabCourse Topic`.parent = `tabProgram Course`.course
and `tabTopic Content`.parent = `tabCourse Topic`.topic
and `tabProgram Course`.parent = %(program)s""", {'program': program})
and `tabProgram Course`.parent = %(program)s""",
{"program": program},
)
return (content, content_type) in contents_of_program

View File

@@ -4,23 +4,25 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
try:
program = frappe.form_dict['program']
course_name = frappe.form_dict['name']
program = frappe.form_dict["program"]
course_name = frappe.form_dict["name"]
except KeyError:
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
context.education_settings = frappe.get_single("Education Settings")
course = frappe.get_doc('Course', course_name)
course = frappe.get_doc("Course", course_name)
context.program = program
context.course = course
context.topics = course.get_topics()
context.has_access = utils.allowed_program_access(context.program)
context.has_access = utils.allowed_program_access(context.program)
context.progress = get_topic_progress(context.topics, course, context.program)
def get_topic_progress(topics, course, program):
progress = {topic.name: utils.get_topic_progress(topic, course.name, program) for topic in topics}
return progress

View File

@@ -4,10 +4,11 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
context.education_settings = frappe.get_single("Education Settings")
if not context.education_settings.enable_lms:
frappe.local.flags.redirect_location = '/'
frappe.local.flags.redirect_location = "/"
raise frappe.Redirect
context.featured_programs = get_featured_programs()

View File

@@ -4,23 +4,34 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
if frappe.session.user == "Guest":
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
context.student = utils.get_current_student()
if not context.student:
context.student = frappe.get_doc('User', frappe.session.user)
context.student = frappe.get_doc("User", frappe.session.user)
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'])
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})
student_progress.append(
{
"program": program.program_name,
"name": program.name,
"progress": progress,
"completion": completion,
}
)
return student_progress

View File

@@ -5,11 +5,12 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
try:
program = frappe.form_dict['program']
program = frappe.form_dict["program"]
except KeyError:
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
context.education_settings = frappe.get_single("Education Settings")
@@ -18,12 +19,14 @@ def get_context(context):
context.has_access = utils.allowed_program_access(program)
context.progress = get_course_progress(context.courses, context.program)
def get_program(program_name):
try:
return frappe.get_doc('Program', program_name)
return frappe.get_doc("Program", program_name)
except frappe.DoesNotExistError:
frappe.throw(_("Program {0} does not exist.").format(program_name))
def get_course_progress(courses, program):
progress = {course.name: utils.get_course_progress(course, program) for course in courses}
return progress or {}

View File

@@ -4,20 +4,22 @@ import erpnext.education.utils as utils
no_cache = 1
def get_context(context):
try:
course = frappe.form_dict['course']
program = frappe.form_dict['program']
topic = frappe.form_dict['topic']
course = frappe.form_dict["course"]
program = frappe.form_dict["program"]
topic = frappe.form_dict["topic"]
except KeyError:
frappe.local.flags.redirect_location = '/lms'
frappe.local.flags.redirect_location = "/lms"
raise frappe.Redirect
context.program = program
context.course = course
context.topic = frappe.get_doc("Topic", topic)
context.contents = get_contents(context.topic, course, program)
context.has_access = utils.allowed_program_access(program)
context.has_access = utils.allowed_program_access(program)
def get_contents(topic, course, program):
student = utils.get_current_student()
@@ -27,19 +29,29 @@ def get_contents(topic, course, program):
progress = []
if contents:
for content in contents:
if content.doctype in ('Article', 'Video'):
if content.doctype in ("Article", "Video"):
if student:
status = utils.check_content_completion(content.name, content.doctype, course_enrollment.name)
else:
status = True
progress.append({'content': content, 'content_type': content.doctype, 'completed': status})
elif content.doctype == 'Quiz':
progress.append({"content": content, "content_type": content.doctype, "completed": status})
elif content.doctype == "Quiz":
if student:
status, score, result, time_taken = utils.check_quiz_completion(content, course_enrollment.name)
status, score, result, time_taken = utils.check_quiz_completion(
content, course_enrollment.name
)
else:
status = False
score = None
result = None
progress.append({'content': content, 'content_type': content.doctype, 'completed': status, 'score': score, 'result': result})
progress.append(
{
"content": content,
"content_type": content.doctype,
"completed": status,
"score": score,
"result": result,
}
)
return progress