fix: lesson indexing

This commit is contained in:
pateljannat
2021-07-29 11:54:30 +05:30
parent 508f90f459
commit 33a12c2dec
23 changed files with 230 additions and 226 deletions

View File

@@ -11,7 +11,6 @@
{% block content %}
<div class="container">
{{ widgets.BatchTabs(course=course, membership=membership) }}
<div class="messages-container mt-5">
{{ widgets.BatchHeader(batch_name=batch.title, member_count=member_count)}}
<ol class="messages">

View File

@@ -30,7 +30,7 @@
<div class="lesson-pagination-parent">
{{ LessonContent(lesson) }}
{% if membership %}
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
{{ pagination(prev_url, next_url) }}
{% endif %}
</div>
</div>
@@ -49,16 +49,15 @@
{% if membership or lesson.include_in_preview %}
<div class="common-card-style lesson-content-card from-markdown">{{ lesson.render_html() }}</div>
{% else %}
<div class="no-preview-message">
<span>This lesson is not available for Preview. Please join the course to access this lesson.</span>
<a href="/courses/{{ course.name }}">Checkout Course Details.</a>
<div class="common-card-style lesson-content-card">
<span>This lesson is not available for Preview. Please join the course to access this lesson. <a href="/courses/{{ course.name }}">Checkout Course Details.</a></span>
</div>
{% endif %}
</div>
{% endmacro %}
{% macro pagination(prev_chap, prev_url, next_chap, next_url) %}
{% macro pagination(prev_url, next_url) %}
<div class="lesson-pagination">
<div>

View File

@@ -12,7 +12,6 @@ def get_context(context):
lesson_index = frappe.form_dict.get("lesson")
lesson_number = f"{chapter_index}.{lesson_index}"
course_name = context.course.name
if not chapter_index or not lesson_index:
if context.batch:
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
@@ -21,20 +20,12 @@ def get_context(context):
frappe.local.flags.redirect_location = context.course.get_learn_url(index_) + context.course.query_parameter
raise frappe.Redirect
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
context.lesson_index = lesson_index
context.chapter_index = chapter_index
outline = context.course.get_outline()
prev_ = outline.get_prev(lesson_number)
next_ = outline.get_next(lesson_number)
context.prev_chap = get_chapter_title(course_name, prev_)
context.next_chap = get_chapter_title(course_name, next_)
context.next_url = context.course.get_learn_url(next_) and context.course.get_learn_url(next_) + context.course.query_parameter
context.prev_url = context.course.get_learn_url(prev_) and context.course.get_learn_url(prev_) + context.course.query_parameter
context.lesson = list(filter(lambda x: cstr(x.number) == lesson_number, context.lessons))[0]
neighbours = context.course.get_neighbours(lesson_number, context.lessons)
context.next_url = get_learn_url(neighbours["next"], context.course)
context.prev_url = get_learn_url(neighbours["prev"], context.course)
context.page_extensions = get_page_extensions()
context.page_context = {
"course": context.course.name,
"batch": context.get("batch") and context.batch.name,
@@ -42,6 +33,9 @@ def get_context(context):
"is_member": context.membership is not None
}
def get_learn_url(lesson_number, course):
return course.get_learn_url(lesson_number) and course.get_learn_url(lesson_number) + course.query_parameter
def get_chapter_title(course_name, lesson_number):
if not lesson_number:
return

View File

@@ -10,12 +10,12 @@ def get_common_context(context):
except KeyError:
batch_name = None
course = Course.find(course_name)
course = frappe.get_doc("LMS Course", course_name)
if not course:
context.template = "www/404.html"
return
context.course = course
context.lessons = course.get_lessons()
membership = course.get_membership(frappe.session.user, batch_name)
context.membership = membership
if membership: