Compare commits

...

8 Commits

Author SHA1 Message Date
pateljannat
6c751cdf39 fix: test 2021-06-22 12:17:06 +05:30
pateljannat
2c570ea214 fix: added default value for arguements 2021-06-22 10:48:33 +05:30
pateljannat
ecfcc8a2f7 fix: redirects and urls 2021-06-22 10:45:07 +05:30
pateljannat
3384f974e5 fix: batch switch with query parameters 2021-06-22 10:11:21 +05:30
pateljannat
eb435261fe feat: learning modes 2021-06-18 18:31:10 +05:30
Jannat Patel
dc7eabefb9 Merge pull request #131 from fossunited/minor-fixes
fix: web form, progress ui, title non unique
2021-06-16 13:15:10 +05:30
pateljannat
fed4b5568b fix: web form, progress ui, title non unique 2021-06-16 13:04:45 +05:30
Jannat Patel
aa77c60abd Merge pull request #129 from fossunited/minor-fix
fix: minor issues
2021-06-15 18:46:33 +05:30
31 changed files with 175 additions and 187 deletions

View File

@@ -165,6 +165,7 @@ whitelist = [
"/add-a-new-batch",
"/new-sign-up",
"/message"
"/about"
]
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]

View File

@@ -29,13 +29,13 @@ def submit_solution(exercise, code):
return {"name": doc.name, "creation": doc.creation}
@frappe.whitelist()
def save_current_lesson(batch_name, lesson_name):
def save_current_lesson(course_name, lesson_name):
"""Saves the current lesson for a student/mentor.
"""
name = frappe.get_value(
doctype="LMS Batch Membership",
filters={
"batch": batch_name,
"course": course_name,
"member": frappe.session.user
},
fieldname="name")

View File

@@ -55,11 +55,11 @@ class Lesson(Document):
return
@frappe.whitelist()
def save_progress(lesson, batch):
def save_progress(lesson, course):
if not frappe.db.exists("LMS Batch Membership",
{
"member": frappe.session.user,
"batch": batch
"course": course
}):
return
if frappe.db.exists("LMS Course Progress",

View File

@@ -33,8 +33,7 @@
{
"fieldname": "title",
"fieldtype": "Data",
"label": "Title",
"unique": 1
"label": "Title"
},
{
"fieldname": "description",
@@ -120,7 +119,7 @@
"link_fieldname": "batch"
}
],
"modified": "2021-05-26 16:43:57.399747",
"modified": "2021-06-16 10:51:05.403726",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch",

View File

@@ -19,15 +19,7 @@ class LMSBatch(Document):
frappe.throw(_("You are not a mentor of the course {0}").format(course.title))
def after_insert(self):
create_membership(batch=self.name, member_type="Mentor")
def get_mentors(self):
memberships = frappe.get_all(
"LMS Batch Membership",
{"batch": self.name, "member_type": "Mentor"},
["member"])
member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names])
create_membership(batch=self.name, course=self.course, member_type="Mentor")
def is_member(self, email, member_type=None):
"""Checks if a person is part of a batch.
@@ -43,16 +35,6 @@ class LMSBatch(Document):
filters['member_type'] = member_type
return frappe.db.exists("LMS Batch Membership", filters)
def get_students(self):
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
"""
memberships = frappe.get_all(
"LMS Batch Membership",
{"batch": self.name, "member_type": "Student"},
["member"])
member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names])
def get_messages(self):
messages = frappe.get_all("LMS Message", {"batch": self.name}, ["*"], order_by="creation")
for message in messages:

View File

@@ -13,8 +13,7 @@
"course",
"member_type",
"role",
"current_lesson",
"is_current"
"current_lesson"
],
"fields": [
{
@@ -81,19 +80,11 @@
"fieldtype": "Data",
"label": "Memeber Username",
"read_only": 1
},
{
"default": "0",
"fieldname": "is_current",
"fieldtype": "Check",
"hidden": 1,
"label": "Is Currently Being Used",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-06-14 10:24:35.425498",
"modified": "2021-06-21 12:10:28.808803",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch Membership",

View File

@@ -14,18 +14,22 @@ class LMSBatchMembership(Document):
self.validate_membership_in_different_batch_same_course()
def validate_membership_in_same_batch(self):
filters={
"member": self.member,
"course": self.course,
"name": ["!=", self.name]
}
if self.batch:
filters["batch"] = self.batch
previous_membership = frappe.db.get_value("LMS Batch Membership",
filters={
"member": self.member,
"batch": self.batch,
"name": ["!=", self.name]
},
filters,
fieldname=["member_type","member"],
as_dict=1)
if previous_membership:
member_name = frappe.db.get_value("User", self.member, "full_name")
frappe.throw(_("{0} is already a {1} of {2}").format(member_name, previous_membership.member_type, self.batch))
course_title = frappe.db.get_value("LMS Course", self.course, "title")
frappe.throw(_("{0} is already a {1} of the course {2}").format(member_name, previous_membership.member_type, course_title))
def validate_membership_in_different_batch_same_course(self):
course = frappe.db.get_value("LMS Batch", self.batch, "course")
@@ -44,10 +48,11 @@ class LMSBatchMembership(Document):
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
@frappe.whitelist()
def create_membership(batch, member=None, member_type="Student", role="Member"):
def create_membership(course, batch=None, member=None, member_type="Student", role="Member"):
frappe.get_doc({
"doctype": "LMS Batch Membership",
"batch": batch,
"course": course,
"role": role,
"member_type": member_type,
"member": member or frappe.session.user

View File

@@ -22,6 +22,7 @@
"field_order": [
"title",
"is_published",
"disable_self_learning",
"column_break_3",
"short_code",
"video_link",
@@ -73,6 +74,12 @@
"fieldtype": "Small Text",
"label": "Short Introduction",
"reqd": 1
},
{
"default": "0",
"fieldname": "disable_self_learning",
"fieldtype": "Check",
"label": "Disable Self Learning"
}
],
"index_web_pages_for_search": 1,
@@ -99,7 +106,7 @@
"link_fieldname": "course"
}
],
"modified": "2021-06-01 04:36:45.696776",
"modified": "2021-06-21 11:34:04.552376",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",

View File

@@ -82,11 +82,11 @@ class LMSCourse(Document):
"""
if not email:
return False
return frappe.db.exists({
"doctype": "LMS Course Mentor Mapping",
"course": self.name,
"mentor": email
})
return frappe.db.count("LMS Course Mentor Mapping",
{
"course": self.name,
"mentor": email
})
def get_student_batch(self, email):
"""Returns the batch the given student is part of.
@@ -192,22 +192,53 @@ class LMSCourse(Document):
return
return f"/courses/{self.name}/learn/{lesson_number}"
def get_current_batch(self, member):
current_membership = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name, "is_current": 1}, pluck="batch")
print(current_membership, member, self.name, frappe.session.user)
if len(current_membership):
return current_membership[0]
print(frappe.db.get_value("LMS Batch Membership", {"member": member, "course": self.name}, "batch"))
return frappe.db.get_value("LMS Batch Membership", {"member": member, "course": self.name}, "batch")
def get_membership(self, member, batch=None):
filters = {
"member": member,
"course": self.name
}
if batch:
filters["batch"] = batch
return frappe.db.get_value("LMS Batch Membership", filters, ["name","batch", "current_lesson"], as_dict=True)
def get_all_memberships(self, member=frappe.session.user):
print(member, frappe.session.user)
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch", "is_current"])
print(all_memberships)
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch"])
for membership in all_memberships:
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
print(all_memberships)
return all_memberships
def get_mentors(self, batch=None):
filters = {
"course": self.name,
"member_type": "Mentor"
}
if batch:
filters["batch"] = batch
memberships = frappe.get_all(
"LMS Batch Membership",
filters,
["member"])
member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names])
def get_students(self, batch=None):
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
"""
filters = {
"course": self.name,
"member_type": "Student"
}
if batch:
filters["batch"] = batch
memberships = frappe.get_all(
"LMS Batch Membership",
filters,
["member"])
member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names])
def get_outline(self):
return CourseOutline(self)

View File

@@ -26,7 +26,6 @@ class TestLMSCourse(unittest.TestCase):
course = self.new_course("Test Course")
assert course.title == "Test Course"
assert course.name == "test-course"
assert course.get_mentors() == []
def test_find_all(self):
courses = LMSCourse.find_all()

View File

@@ -19,7 +19,7 @@
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2021-06-14 15:28:08.206622",
"modified": "2021-06-15 18:49:50.530001",
"modified_by": "Administrator",
"module": "LMS",
"name": "add-a-new-batch",
@@ -38,7 +38,7 @@
{
"allow_read_on_all_link_options": 0,
"fieldname": "course",
"fieldtype": "Link",
"fieldtype": "Data",
"hidden": 1,
"label": "Course",
"max_length": 0,

View File

@@ -4,74 +4,62 @@
{{ course.title }}</span> {% endif %}
{% set all_memberships = course.get_all_memberships() %}
{% if all_memberships | length > 1 %}
<a class="nav-link pull-right" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
<a class="nav-link pull-right" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
Switch Batch
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for membership in all_memberships %}
{% if not membership.is_current %}
<a class="dropdown-item switch-batch" href="#" data-batch="{{ membership.batch | urlencode }}" data-course="{{ course.name | urlencode }}">{{ membership.batch_title }}</a>
{% for data in all_memberships %}
{% if data.batch != membership.batch %}
<a class="dropdown-item switch-batch" href="/courses/{{ course.name }}/home?batch={{ data.batch }}">{{ data.batch_title }}</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
{% if not batch %}
{% if not membership %}
{% set display_class = "hide" %}
{% else %}
{% set display_class = "" %}
{% endif %}
<ul class="nav nav-tabs mt-4">
<li class="nav-item {{ display_class }}">
<a class="nav-link" id="home" href="/courses/{{course.name}}/home">Home</a>
<li class="nav-item">
<a class="nav-link" id="home" href="/courses/{{course.name}}/home{{ course.query_parameter }}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="learn" href="/courses/{{course.name}}/learn">Lessons</a>
{% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and membership.current_lesson else '1.1' %}
<a class="nav-link" id="learn"
href="{{ course.get_learn_url(lesson_index) }}{{ course.query_parameter }}">Lessons</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/schedule">Schedule</a>
</li> -->
<li class="nav-item {{ display_class }}">
<a class="nav-link" id="members" href="/courses/{{course.name}}/members">Members</a>
<a class="nav-link" id="members" href="/courses/{{course.name}}/members{{ course.query_parameter }}">Members</a>
</li>
<li class="nav-item {{ display_class }}">
<!-- <li class="nav-item {{ display_class }}">
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/discuss">Discussion</a>
</li>
</li> -->
<!-- <li class="nav-item">
<a class="nav-link" id="about" href="/courses/{{course.name}}/about">About</a>
</li> -->
{% if batch and batch.is_member(frappe.session.user, member_type="Mentor") %}
{% if membership and membership.batch and course.is_mentor(frappe.session.user) %}
<li class="nav-item">
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress">Progress</a>
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress{{ course.query_parameter }}">Progress</a>
</li>
{% endif %}
</ul>
{% block script %}
<script>
frappe.ready(() => {
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}"]`)
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}{{ course.query_parameter }}"]`)
if (selector) {
selector.classList.add('active');
}
else {
$("#learn").addClass('active')
}
$(".switch-batch").click((e) => {
e.preventDefault();
var batch = decodeURIComponent($(e.currentTarget).attr("data-batch"));
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
frappe.call({
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
args: {
batch: batch,
course: course,
member: frappe.session.user
},
callback: (data) => {
window.location.reload();
}
})
})
})
</script>
{% endblock %}

View File

@@ -8,11 +8,10 @@
{% for lesson in chapter.get_lessons() %}
<div class="lesson-teaser">
<a {% if show_link or lesson.include_in_preview %}
href="{{ course.get_learn_url(course.get_lesson_index(lesson.name)) }}" {% else %} href="" class="no-preview"
href="{{ course.get_learn_url(course.get_lesson_index(lesson.name)) }}{{course.query_parameter}}" {% else %} href="" class="no-preview"
{% endif %} data-course="{{ course.name }}">{{ lesson.title }}</a>
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %}
<a class="ml-5 badge p-1 {{ lesson.get_slugified_class() }}"> <img class="progress-image"
src="/assets/community/images/Vector.png"> {{ lesson.get_progress() }}</a>
<span class="ml-5 badge p-2 {{ lesson.get_slugified_class() }}"> {{ lesson.get_progress() }}</span>
{% endif %}
</div>
{% endfor %}

View File

@@ -7,7 +7,7 @@
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
{% for m in batch.get_mentors() %}
{% for m in course.get_mentors(batch.name) %}
<div>
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
<span class="instructor-title">{{m.full_name}}</span>
@@ -18,10 +18,10 @@
<div class="cta">
<div class="">
{% if can_manage %}
<a href="" class="btn btn-primary manage-batch" data-batch="{{ batch.name | urlencode }}"
<a href="/courses/{{ course.name }}/home?batch={{ batch.name }}" class="btn btn-primary manage-batch" data-batch="{{ batch.name | urlencode }}"
data-course="{{ course.name | urlencode }}">Manage</a>
{% elif can_join %}
<button class="join-batch btn btn-primary" data-batch="{{ batch.name | urlencode }}"
<button class="join-batch btn btn-secondary" data-batch="{{ batch.name | urlencode }}"
data-course="{{ course.name | urlencode }}">Join this Batch</button>
{% endif %}
</div>

View File

@@ -23,6 +23,7 @@
--cta-color: var(--c4);
--send-message: var(--c7);
--received-message: var(--c8);
--control-bg: var(--gray-100);
}
body {

View File

@@ -11,7 +11,7 @@
{% block content %}
<div class="container">
{{ widgets.BatchTabs(course=course, batch=batch) }}
{{ 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

@@ -4,5 +4,5 @@ from . import utils
def get_context(context):
utils.get_common_context(context)
context.messages = context.batch.get_messages()
if not context.batch:
if not context.membership:
utils.redirect_to_lesson(context.course)

View File

@@ -8,15 +8,13 @@
{% endblock %}
{% block content %}
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/join?batch=" + batch.name %}
<div class="container mt-5">
{{ widgets.BatchTabs(course=course, batch=batch) }}
<!-- <div>
<h1 class="mt-5">{{ batch.title }}</h1>
</div> -->
{{ widgets.BatchTabs(course=course, membership=membership) }}
<div class="course-details mt-5">
{{ widgets.CourseOutline(course=course, batch=batch, show_link=True, show_progress=True) }}
</div>
{% if batch %}
<div class="w-25">
<h3>Batch Schedule</h3>
{{ widgets.RenderBatch(course=course, batch=batch) }}
@@ -28,8 +26,9 @@
{{ frappe.utils.md_to_html(batch.description) }}
</div>
{% endif %}
{% endif %}
{% if course.is_mentor(frappe.session.user) %}
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/join?batch=" + batch.name %}
<div class="">
<h3> Invite Members </h3>
<a href="" class="" id="invite-link" data-link="{{ invite_link }}">Get Batch Invitation

View File

@@ -3,5 +3,3 @@ from . import utils
def get_context(context):
utils.get_common_context(context)
if not context.batch:
utils.redirect_to_lesson(context.course)

View File

@@ -51,7 +51,8 @@ frappe.ready(() => {
frappe.call({
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
"args": {
"batch": "{{ batch.name }}"
"batch": {{ batch.name }},
"course": {{ batch.course }}
},
"callback": (data) => {
if (data.message == "OK") {
@@ -66,20 +67,6 @@ frappe.ready(() => {
}
})
})
$("#batch-home").click((e) => {
frappe.call({
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
args: {
"batch": "{{ batch.name }}",
"course": "{{ batch.course}}",
"member": frappe.session.user
},
callback: (data) => {
window.location.href = "/courses/{{ batch.course }}/home"
}
})
})
})
</script>
{% endblock %}

View File

@@ -13,7 +13,7 @@
<link rel="stylesheet" href="/assets/frappe/css/hljs-night-owl.css">
{% for ext in page_extensions %}
{{ ext.render_header() }}
{{ ext.render_header() }}
{% endfor %}
{% endblock %}
@@ -22,17 +22,18 @@
{% block content %}
<div class="container">
{{ widgets.BatchTabs(course=course, batch=batch) }}
{{ widgets.BatchTabs(course=course, membership=membership) }}
<div class="lesson-page">
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" {% if batch %} data-batch="{{ batch.name }}" {% endif %}>{{ lesson.title }}</h2>
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-lesson="{{ lesson.name }}"
data-course="{{ course.name }}" {% if membership%} data-membership="{{membership.name}}" {% endif %}>{{ lesson.title }}</h2>
{% if batch or lesson.include_in_preview %}
{% if membership or lesson.include_in_preview %}
{{ lesson.render_html() }}
{% else %}
<div class="no-preview-message">
<span>This lesson is not available for Preview. Please join a batch to access the complete course.</span>
<a href="/courses/{{ course.name }}">Checkout Upcoming Batches</a>
<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>
{% endif %}
@@ -61,7 +62,6 @@
{%- block script %}
{{ super() }}
{% for ext in page_extensions %}
{{ ext.render_footer() }}
{{ ext.render_footer() }}
{% endfor %}
{%- endblock %}

View File

@@ -1,17 +1,17 @@
frappe.ready(() => {
if ($(".title").attr("data-batch") && !$(".title").hasClass("is_mentor")) {
if ($(".title").attr("data-membership") && !$(".title").hasClass("is_mentor")) {
frappe.call({
method: "community.lms.doctype.lesson.lesson.save_progress",
args: {
lesson: $(".title").attr("data-name"),
batch: $(".title").attr("data-batch")
lesson: $(".title").attr("data-lesson"),
course: $(".title").attr("data-course")
}
})
}
if ($(".title").attr("data-batch")) {
if ($(".title").attr("data-membership")) {
frappe.call("community.lms.api.save_current_lesson", {
"batch_name": $(".title").attr("data-batch"),
"lesson_name": $(".title").attr("data-name")
course_name: $(".title").attr("data-course"),
lesson_name: $(".title").attr("data-lesson")
})
}
})

View File

@@ -18,7 +18,7 @@ def get_context(context):
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
else:
index_ = "1.1"
frappe.local.flags.redirect_location = context.course.get_learn_url(index_)
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)
@@ -30,8 +30,8 @@ def get_context(context):
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_)
context.prev_url = context.course.get_learn_url(prev_)
context.next_url = context.course.get_learn_url(next_) + context.course.query_parameter
context.prev_url = context.course.get_learn_url(prev_) + context.course.query_parameter
context.page_extensions = get_page_extensions()

View File

@@ -10,7 +10,7 @@
{% block content %}
<div class="container">
{{ widgets.BatchTabs(course=course, batch=batch) }}
{{ widgets.BatchTabs(course=course, membership=membership) }}
{{ MembersList(members)}}
</div>
{% endblock %}

View File

@@ -3,5 +3,5 @@ from . import utils
def get_context(context):
utils.get_common_context(context)
if not context.batch:
if not context.membership:
utils.redirect_to_lesson(context.course)

View File

@@ -24,7 +24,7 @@
{% block content %}
<div class="container">
{{ widgets.BatchTabs(course=course, batch=batch) }}
{{ widgets.BatchTabs(course=course, membership=membership) }}
<div class="mentor-dashboard">
<h3>Batch Progress</h3>
{% for exercise in report.exercises %}

View File

@@ -17,7 +17,7 @@ def get_context(context):
class BatchReport:
def __init__(self, course, batch):
self.submissions = get_submissions(batch)
self.submissions = get_submissions(course, batch)
self.exercises = self.get_exercises(course.name)
self.submissions_by_exercise = defaultdict(list)
for s in self.submissions:
@@ -29,8 +29,10 @@ class BatchReport:
def get_submissions_of_exercise(self, exercise_name):
return self.submissions_by_exercise[exercise_name]
def get_submissions(batch):
students = batch.get_students()
def get_submissions(course, batch):
students = course.get_students(batch.name)
if not len(students):
return []
students_map = {s.email: s for s in students}
names, values = nparams("s", students_map.keys())
sql = """

View File

@@ -5,26 +5,34 @@ def get_common_context(context):
context.no_cache = 1
course_name = frappe.form_dict["course"]
try:
batch_name = frappe.form_dict["batch"]
except KeyError:
batch_name = None
course = Course.find(course_name)
if not course:
context.template = "www/404.html"
return
context.course = course
batch_name = course.get_current_batch(frappe.session.user)
batch = course.get_batch(batch_name)
context.batch = batch
if batch_name:
context.members = batch.get_mentors() + batch.get_students()
membership = course.get_membership(frappe.session.user, batch_name)
if membership:
context.membership = membership
batch = course.get_batch(membership.batch)
if batch:
context.batch = batch
context.members = course.get_mentors(membership.batch) + course.get_students(membership.batch)
context.member_count = len(context.members)
context.course = course
context.course.query_parameter = "?batch=" + membership.batch if membership and membership.batch else ""
context.livecode_url = get_livecode_url()
def get_livecode_url():
return frappe.db.get_single_value("LMS Settings", "livecode_url")
def redirect_to_lesson(course, index_="1.1"):
frappe.local.flags.redirect_location = course.get_learn_url(index_)
frappe.local.flags.redirect_location = course.get_learn_url(index_) + course.query_parameter
raise frappe.Redirect

View File

@@ -12,7 +12,14 @@
<div class="mb-5">
<a class="anchor_style" href="/courses">Courses</a> / <span class="text-muted">{{ course.title }}</span>
</div>
<h2 id="course-title" data-course="{{course.name}}">{{course.title}}</h2>
<div class="d-flex justify-content-between align-items-end">
<h2 id="course-title" data-course="{{course.name}}">{{course.title}}</h2>
{% if not course.disable_self_learning and not course.is_mentor(frappe.session.user) %}
<div>
<button class="btn btn-primary join-batch" data-course="{{ course.name | urlencode }}"> Start Learning </button>
</div>
{% endif %}
</div>
<div class="course-short-intro">{{ course.short_introduction }}</div>
</div>
@@ -75,12 +82,12 @@
{% endfor %}
</div>
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.name}}">Add a new
batch</a>
{% else %}
<div class="mentor_message">
<p> You are a mentor for this course. </p>
<a class="" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Create your first batch</a>
<a class="" href="/add-a-new-batch?new=1&course={{course.name}}">Create your first batch</a>
</div>
{% endif %}
{% endmacro %}
@@ -96,8 +103,8 @@
</div>
{% endfor %}
</div>
{% else %}
<div class="mt-5 upcoming">There are no Upcoming Batches for this course currently.</div>
{% endif %}
{% else %}
<div class="mt-5 upcoming">There are no Upcoming Batches for this course currently.</div>
{% endif %}
</div>
{% endmacro %}

View File

@@ -57,11 +57,13 @@ frappe.ready(() => {
window.location.href = `/login?redirect-to=/courses/${course}`;
return;
}
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
var batch = $(e.currentTarget).attr("data-batch");
batch = batch ? decodeURIComponent(batch) : "";
frappe.call({
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
"args": {
"batch": batch
"batch": batch ? batch : "",
"course": course
},
"callback": (data) => {
if (data.message == "OK") {
@@ -73,21 +75,4 @@ frappe.ready(() => {
}
})
})
$(".manage-batch").click((e) => {
e.preventDefault();
var batch = decodeURIComponent($(e.currentTarget).attr("data-batch"));
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
frappe.call({
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
args: {
batch: batch,
course: course,
member: frappe.session.user
},
callback: (data) => {
window.location.href = `/courses/${course}/home`;
}
})
})
})

View File

@@ -16,9 +16,8 @@ def get_context(context):
raise frappe.Redirect
context.course = course
batch = course.get_student_batch(frappe.session.user)
if batch:
frappe.local.flags.redirect_location = f"/courses/{course.name}/learn"
raise frappe.Redirect
if not course.is_mentor(frappe.session.user):
batch = course.get_membership(frappe.session.user)
if batch:
frappe.local.flags.redirect_location = f"/courses/{course.name}/learn"
raise frappe.Redirect