Added portal pages for courses and topics.

This commit is contained in:
Anand Chitipothu
2021-03-02 07:00:14 +00:00
parent 972399d72f
commit 5ab4f86f90
7 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
{% extends "templates/base.html" %}
{% 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>
{% endblock %}
{% block content %}
<section class="top-section" style="padding: 1rem 0rem;">
<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>
</ol>
</nav>
<h1>{{ course.title }}</h1>
<div>{{ course.description }}</div>
</div>
<div class='container'>
<div class="list-group">
{% 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 %}
</div>
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,23 @@
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)
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

View File

@@ -0,0 +1,24 @@
{% extends "templates/base.html" %}
{% block title %}{{ 'Courses' }}{% endblock %}
{% from "www/courses/macros/card.html" import course_card %}
{% block head_include %}
<meta name="description" content="{{ 'Courses' }}" />
<meta name="keywords" content="Courses" />
<style>
</style>
{% endblock %}
{% block content %}
<section class="top-section" style="padding: 1rem 0rem;">
<div class='container pb-5'>
<h1>{{ 'Courses' }}</h1>
</div>
<div class='container'>
<div class="row mt-5">
{% for course in courses %}
{{ course_card(course) }}
{% endfor %}
</div>
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,13 @@
import frappe
def get_context(context):
context.no_cache = 1
context.courses = get_courses()
def get_courses():
courses = frappe.get_all(
"Community Course",
fields=['name', 'title', 'description']
)
print(courses)
return courses

View File

@@ -0,0 +1,19 @@
{% macro course_card(course) %}
<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 &rarr;</a>
</div>
</div>
{% endmacro %}
{% macro topic_card(course, topic) %}
<div class="card mb-5 w-100">
<div class="card-body">
<h5 class="card-title"><a href="/courses/topic?course={{course.name}}&topic={{topic.name}}">{{topic.title}}</a></h5>
<p class="card-text">{{topic.description}}</p>
</div>
</div>
{% endmacro %}

View File

@@ -0,0 +1,25 @@
{% extends "templates/base.html" %}
{% block title %}{{topic.title}} ({{course.title}}){% endblock %}
{% block head_include %}
<meta name="description" content="Topic {{topic.title}} of the course {{course.title}}" />
<meta name="keywords" content="course {{course.title}} {{topic.title}}" />
<style>
</style>
{% endblock %}
{% block content %}
<section class="top-section" style="padding: 1rem 0rem;">
<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/course?course={{course.name}}">{{course.title}}</a></li>
</ol>
</nav>
<h1>{{ topic.title }}</h1>
<div>{{ topic.description }}</div>
</div>
</section>
{% endblock %}

View File

@@ -0,0 +1,34 @@
import frappe
def get_context(context):
context.no_cache = 1
course_name = get_queryparam("course", '/courses')
context.course = get_course(course_name)
topic_name = get_queryparam("topic", '/courses?course=' + course_name)
context.topic = get_topic(course_name, topic_name)
print("topic", context.topic)
def get_queryparam(name, redirect_when_not_found):
try:
return frappe.form_dict[name]
except KeyError:
frappe.local.flags.redirect_location = redirect_when_not_found
raise frappe.Redirect
def get_course(name):
try:
course = frappe.get_doc('Community Course', name)
except frappe.exceptions.DoesNotExistError:
raise frappe.NotFound
return course
def get_topic(course_name, topic_name):
try:
topic = frappe.get_doc('Community Course Topic', topic_name)
except frappe.exceptions.DoesNotExistError:
raise frappe.NotFound
if topic.course != course_name:
raise frappe.NotFound
return topic