feat: course enrollment and my courses page
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
{% block title %}{{ 'Courses' }}{% endblock %}
|
||||
{% from "www/courses/macros/card.html" import course_card, topic_card %}
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Courses" />
|
||||
<meta name="keywords" content="Courses {{course.title}}" />
|
||||
<style>
|
||||
</style>
|
||||
<meta name="description" content="Courses" />
|
||||
<meta name="keywords" content="Courses {{course.title}}" />
|
||||
<style>
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@@ -13,22 +13,32 @@
|
||||
<div class='container pb-5'>
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item" aria-current="page"><a href="/courses">Courses</a></li>
|
||||
<li class="breadcrumb-item" aria-current="page"><a href="/courses">Courses</a></li>
|
||||
</ol>
|
||||
</nav>
|
||||
<h1>{{ course.title }}</h1>
|
||||
|
||||
<div>{{ course.description }}</div>
|
||||
{% if course_enrolled %}
|
||||
<p>
|
||||
<div class="badge badge-info">Enrolled</div>
|
||||
</p>
|
||||
{% endif %}
|
||||
<div>
|
||||
{% if not course_enrolled %}
|
||||
<button class="btn btn-dark btn-enroll float-right" data-course={{course.name}}>Enroll</button>
|
||||
{% endif %}
|
||||
<h1>{{ course.title }}</h1>
|
||||
</div>
|
||||
<div>{{ frappe.utils.md_to_html(course.description) }}</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='container'>
|
||||
<div class="list-group">
|
||||
{% for topic in course.topics %}
|
||||
{% for topic in course.topics %}
|
||||
<div class="list-group-item">
|
||||
<h5><a href="/courses/topic?course={{course.name}}&topic={{topic.name}}">{{topic.title}}</a></h5>
|
||||
<div>{{topic.description}}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
17
community/www/courses/course.js
Normal file
17
community/www/courses/course.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* frappe.ready(() => {
|
||||
var url_params = new URLSearchParams(window.location.search);
|
||||
frappe.call('community.www.courses.course.has_enrolled', { course: url_params.get("course") }, (data) => {
|
||||
if (data.message) {
|
||||
$(".btn-enroll").addClass("hide");
|
||||
$(".enrollment-details").removeClass("hide");
|
||||
}
|
||||
})
|
||||
}) */
|
||||
|
||||
$('.btn-enroll').on('click', (e) => {
|
||||
frappe.call('community.www.courses.course.enroll', { course: $(e.target).attr("data-course") }, (data) => {
|
||||
$(".btn-enroll").addClass("hide");
|
||||
$(".enrollment-details").removeClass("hide");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
try:
|
||||
course_id = frappe.form_dict['course']
|
||||
except KeyError:
|
||||
frappe.local.flags.redirect_location = '/courses'
|
||||
raise frappe.Redirect
|
||||
context.course = get_course(course_id)
|
||||
context.no_cache = 1
|
||||
try:
|
||||
course_id = frappe.form_dict['course']
|
||||
except KeyError:
|
||||
frappe.local.flags.redirect_location = '/courses'
|
||||
raise frappe.Redirect
|
||||
context.course = get_course(course_id)
|
||||
context.course_enrolled = has_enrolled(course_id)
|
||||
|
||||
def get_course(name):
|
||||
course = frappe.db.get_value('Community Course', name,
|
||||
['name', 'title', 'description'], as_dict=1)
|
||||
course['topics'] = frappe.db.get_all('Community Course Topic',
|
||||
filters={
|
||||
'course': name
|
||||
},
|
||||
fields=['name', 'title', 'description'],
|
||||
order_by='creation'
|
||||
)
|
||||
print(course)
|
||||
return course
|
||||
course = frappe.db.get_value('Community Course', name,
|
||||
['name', 'title', 'description'], as_dict=1)
|
||||
course['topics'] = frappe.db.get_all('Community Course Topic',
|
||||
filters={
|
||||
'course': name
|
||||
},
|
||||
fields=['name', 'title', 'description'],
|
||||
order_by='creation'
|
||||
)
|
||||
return course
|
||||
|
||||
def has_enrolled(course):
|
||||
return frappe.db.get_value("Community Course Enrollment", {"course": course, "owner": frappe.session.user})
|
||||
|
||||
@frappe.whitelist()
|
||||
def enroll(course):
|
||||
return frappe.get_doc({
|
||||
"doctype": "Community Course Enrollment",
|
||||
"course": course
|
||||
}).save()
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<div class="card mb-5 w-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><a href="/courses/course?course={{course.name}}">{{course.title}}</a></h5>
|
||||
<p class="card-text">{{course.description}}</p>
|
||||
<a href="/courses/course?id={{course.name}}" class="card-link">See more →</a>
|
||||
<p class="card-text">{{ frappe.utils.md_to_html(course.description[:250]) }}</p>
|
||||
<a href="/courses/course?course={{course.name}}" class="card-link">See more →</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<h1>jannat</h1>
|
||||
67
community/www/my-courses/index.html
Normal file
67
community/www/my-courses/index.html
Normal file
@@ -0,0 +1,67 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/hackathons/macros/card.html" import null_card %}
|
||||
|
||||
{% block title %}{{ 'My Courses' }}{% endblock %}
|
||||
{% block head_include %}
|
||||
<meta name="description" content="My Courses" />
|
||||
<meta name="keywords" content="" />
|
||||
<style>
|
||||
div.card-hero-img {
|
||||
height: 220px;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-color: rgb(250, 251, 252);
|
||||
}
|
||||
|
||||
.card-image-wrapper {
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
height: 220px;
|
||||
background-color: rgb(250, 251, 252);
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.image-body {
|
||||
align-self: center;
|
||||
color: #d1d8dd;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
section {
|
||||
padding: 5rem 0 5rem 0;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% macro card(course) %}
|
||||
<div class="col-sm-4 mb-4 text-left">
|
||||
<a href="//courses/course?course={{course.name}}" class="no-decoration no-underline">
|
||||
<div class="card h-100">
|
||||
<div class='card-body'>
|
||||
<h5 class='card-title'>{{ course.title }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<section class="section">
|
||||
<div class='container'>
|
||||
<div class="row mt-5">
|
||||
{% for course in my_courses %}
|
||||
{{ card(course) }}
|
||||
{% endfor %}
|
||||
{% if my_courses %}
|
||||
{% for n in range( (3 - (my_courses|length)) %3) %}
|
||||
{{ null_card() }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
15
community/www/my-courses/index.py
Normal file
15
community/www/my-courses/index.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
context.my_courses = get_my_courses()
|
||||
|
||||
def get_my_courses():
|
||||
my_courses = []
|
||||
courses = frappe.get_all("Community Course Enrollment", {"owner": frappe.session.user}, ["course"])
|
||||
for course in courses:
|
||||
my_courses.append({
|
||||
"name": course.course,
|
||||
"title": frappe.db.get_value("Community Course", course.course, ["title"])
|
||||
})
|
||||
return my_courses
|
||||
Reference in New Issue
Block a user