feat: added portal page to join a cohort

Issue #271
This commit is contained in:
Anand Chitipothu
2021-11-30 08:29:24 +05:30
parent 1277cfed64
commit f1157895db
5 changed files with 142 additions and 0 deletions

View 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 %}

View 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