@@ -146,6 +146,7 @@ website_route_rules = [
|
|||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>", "to_route": "cohorts/subgroup", "defaults": {"page": "info"}},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/students", "to_route": "cohorts/subgroup", "defaults": {"page": "students"}},
|
||||||
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
|
{"from_route": "/courses/<course>/subgroups/<cohort>/<subgroup>/join-requests", "to_route": "cohorts/subgroup", "defaults": {"page": "join-requests"}},
|
||||||
|
{"from_route": "/courses/<course>/join/<cohort>/<subgroup>/<invite_code>", "to_route": "cohorts/join"},
|
||||||
{"from_route": "/users", "to_route": "profiles/profile"}
|
{"from_route": "/users", "to_route": "profiles/profile"}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,28 @@ def save_current_lesson(course_name, lesson_name):
|
|||||||
doc.current_lesson = lesson_name
|
doc.current_lesson = lesson_name
|
||||||
doc.save(ignore_permissions=True)
|
doc.save(ignore_permissions=True)
|
||||||
return {"current_lesson": doc.current_lesson}
|
return {"current_lesson": doc.current_lesson}
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def join_cohort(course, cohort, subgroup, invite_code):
|
||||||
|
"""Creates a Cohort Join Request for given user.
|
||||||
|
"""
|
||||||
|
course_doc = frappe.get_doc("LMS Course", course)
|
||||||
|
cohort_doc = course_doc and course_doc.get_cohort(cohort)
|
||||||
|
subgroup_doc = cohort_doc and cohort_doc.get_subgroup(subgroup)
|
||||||
|
|
||||||
|
if not subgroup_doc or subgroup_doc.invite_code != invite_code:
|
||||||
|
return {
|
||||||
|
"ok": False,
|
||||||
|
"error": "Invalid join link"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"doctype": "Cohort Join Request",
|
||||||
|
"cohort": cohort_doc.name,
|
||||||
|
"subgroup": subgroup_doc.name,
|
||||||
|
"email": frappe.session.user
|
||||||
|
}
|
||||||
|
doc = frappe.get_doc(data)
|
||||||
|
doc.insert(ignore_permissions=True)
|
||||||
|
return {"ok": True}
|
||||||
|
|||||||
@@ -213,6 +213,10 @@ class LMSCourse(Document):
|
|||||||
def get_cohorts(self):
|
def get_cohorts(self):
|
||||||
return find_all("Cohort", course=self.name, order_by="creation")
|
return find_all("Cohort", course=self.name, order_by="creation")
|
||||||
|
|
||||||
|
def get_cohort(self, cohort_slug):
|
||||||
|
name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug})
|
||||||
|
return name and frappe.get_doc("Cohort", name)
|
||||||
|
|
||||||
def is_cohort_staff(self, user_email):
|
def is_cohort_staff(self, user_email):
|
||||||
"""Returns True if the user is either a mentor or a staff for one or more active cohorts of this course.
|
"""Returns True if the user is either a mentor or a staff for one or more active cohorts of this course.
|
||||||
"""
|
"""
|
||||||
|
|||||||
88
school/www/cohorts/join.html
Normal file
88
school/www/cohorts/join.html
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
{% extends "www/cohorts/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Join Course{% endblock %}
|
||||||
|
|
||||||
|
{% block page_content %}
|
||||||
|
|
||||||
|
<h2>Join Course</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Course: {{course.title}}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Cohort: {{cohort.title}}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Subgroup: {{subgroup.title}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% if frappe.session.user == "Guest" %}
|
||||||
|
|
||||||
|
<div class="alert alert-warning">
|
||||||
|
<p>
|
||||||
|
Please login to be able to join the course.</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you don't already have an account, you can <a href="/login#signup">sign up for a new account</a>.
|
||||||
|
</p>
|
||||||
|
<a class="btn btn-primary" href="/login">Login to continue</a>
|
||||||
|
</div>
|
||||||
|
{% elif subgroup.has_student(frappe.session.user) %}
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<p>You are already a student of this course.</p>
|
||||||
|
<a class="btn btn-primary" href="#">Go to the course</a>
|
||||||
|
</div>
|
||||||
|
{% elif subgroup.has_join_request(frappe.session.user) %}
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<p>We have received your request to join the course. You'll hear back from us soon.</p>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
<a class="btn btn-primary" id="join">Join the course</a>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
console.log("ready!")
|
||||||
|
$("#join").click(function() {
|
||||||
|
var parts = window.location.pathname.split("/")
|
||||||
|
var course = parts[2];
|
||||||
|
var cohort = parts[4];
|
||||||
|
var subgroup = parts[5];
|
||||||
|
var invite_code = parts[6];
|
||||||
|
|
||||||
|
frappe.call('school.lms.api.join_cohort', {
|
||||||
|
course: course,
|
||||||
|
cohort: cohort,
|
||||||
|
subgroup: subgroup,
|
||||||
|
invite_code: invite_code
|
||||||
|
})
|
||||||
|
.then(r => {
|
||||||
|
if (r.message.ok) {
|
||||||
|
let d = new frappe.ui.Dialog({
|
||||||
|
title: "Notification",
|
||||||
|
primary_action_label: "Proceed",
|
||||||
|
primary_action() {
|
||||||
|
d.hide();
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var message = "We've received your interest to join the course. We'll hear from us soon.";
|
||||||
|
d.show();
|
||||||
|
d.set_message(message);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frappe.msgprint(r.message.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
24
school/www/cohorts/join.py
Normal file
24
school/www/cohorts/join.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
context.no_cache = 1
|
||||||
|
|
||||||
|
course = utils.get_course(frappe.form_dict["course"])
|
||||||
|
cohort = course and utils.get_cohort(course, frappe.form_dict["cohort"])
|
||||||
|
subgroup = cohort and utils.get_subgroup(cohort, frappe.form_dict["subgroup"])
|
||||||
|
if not subgroup:
|
||||||
|
context.template = "www/404.html"
|
||||||
|
return
|
||||||
|
|
||||||
|
invite_code = frappe.form_dict["invite_code"]
|
||||||
|
if subgroup.invite_code != invite_code:
|
||||||
|
context.template = "www/404.html"
|
||||||
|
return
|
||||||
|
|
||||||
|
utils.add_nav(context, "All Courses", "/courses")
|
||||||
|
utils.add_nav(context, course.title, "/courses/" + course.name)
|
||||||
|
|
||||||
|
context.course = course
|
||||||
|
context.cohort = cohort
|
||||||
|
context.subgroup = subgroup
|
||||||
Reference in New Issue
Block a user