feat: added next/prev links to learn pages

This commit is contained in:
Anand Chitipothu
2021-05-14 15:29:44 +05:30
parent 49b41749e8
commit 8b657f2f40
6 changed files with 95 additions and 9 deletions

View File

@@ -23,15 +23,31 @@
{% block content %}
{{ Sidebar(course.name, batch.name) }}
<div class="container lesson">
<h1>{{ lesson.title }} - {{ lesson.name }}</h1>
<div class="container">
<div class="lesson-page">
<div class="lesson-pagination">
{% if prev_url %}
<a href="{{prev_url}}" class="btn">&larr; Prev</a>
{% endif %}
{% if next_url %}
<a href="{{next_url}}" class="btn pull-right">Next &rarr;</a>
{% endif %}
</div>
{% for s in lesson.get_sections() %}
<div class="section section-{{ s.type }}">
{{ render_section(s) }}
<h2>{{ lesson.title }}</h2>
{% for s in lesson.get_sections() %}
<div class="section section-{{ s.type }}">
{{ render_section(s) }}
</div>
{% endfor %}
<div class="lesson-pagination">
<a href="#" class="btn">&larr; Prev</a>
<a href="#" class="btn pull-right">Next &rarr;</a>
</div>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@@ -8,6 +8,7 @@ def get_context(context):
batch_name = frappe.form_dict["batch"]
chapter_index = frappe.form_dict.get("chapter")
lesson_index = frappe.form_dict.get("lesson")
lesson_number = f"{chapter_index}.{lesson_index}"
course = Course.find(course_name)
if not course:
@@ -30,5 +31,16 @@ def get_context(context):
context.chapter_index = chapter_index
context.livecode_url = get_livecode_url()
outline = course.get_outline()
next_ = outline.get_next(lesson_number)
prev_ = outline.get_prev(lesson_number)
context.next_url = get_learn_url(course_name, batch_name, next_)
context.prev_url = get_learn_url(course_name, batch_name, prev_)
def get_learn_url(course_name, batch_name, lesson_number):
if not lesson_number:
return
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
def get_livecode_url():
return frappe.db.get_single_value("LMS Settings", "livecode_url")