refactor: moved courses/*/index pages to batch/*
This commit is contained in:
0
community/www/batch/__init__.py
Normal file
0
community/www/batch/__init__.py
Normal file
@@ -11,7 +11,8 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course.name, batch.name) }}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ CourseBasicDetail(course)}}
|
||||
{{ InstructorsSection(course.get_instructor()) }}
|
||||
7
community/www/batch/about.py
Normal file
7
community/www/batch/about.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
|
||||
print("context", context)
|
||||
@@ -11,10 +11,11 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course_slug, batch_code) }}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="">
|
||||
<div class="batch-header">
|
||||
{{ BatchHearder(course.name, member_count) }}
|
||||
{{ BatchHearder(course.title, member_count) }}
|
||||
</div>
|
||||
<div class="messages">
|
||||
<div class="message-section">
|
||||
9
community/www/batch/discuss.py
Normal file
9
community/www/batch/discuss.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
from community.lms.doctype.lms_batch.lms_batch import get_messages
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
|
||||
context.members = utils.get_batch_members(context.batch.name)
|
||||
context.member_count = len(context.members)
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course.name, batch.name) }}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
<div class="lesson-page">
|
||||
@@ -1,37 +1,25 @@
|
||||
import frappe
|
||||
from community.lms.models import Course
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
utils.get_common_context(context)
|
||||
|
||||
course_name = frappe.form_dict["course"]
|
||||
batch_name = frappe.form_dict["batch"]
|
||||
chapter_index = frappe.form_dict.get("chapter")
|
||||
lesson_index = frappe.form_dict.get("lesson")
|
||||
lesson_number = f"{chapter_index}.{lesson_index}"
|
||||
|
||||
course = Course.find(course_name)
|
||||
if not course:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
batch = course.get_batch(batch_name)
|
||||
if not batch:
|
||||
frappe.local.flags.redirect_location = "/courses/" + course_name
|
||||
raise frappe.Redirect
|
||||
course_name = context.course.name
|
||||
batch_name = context.batch.name
|
||||
|
||||
if not chapter_index or not lesson_index:
|
||||
frappe.local.flags.redirect_location = f"/courses/{course_name}/{batch_name}/learn/1.1"
|
||||
raise frappe.Redirect
|
||||
|
||||
context.course = course
|
||||
context.batch = batch
|
||||
context.lesson = course.get_lesson(chapter_index, lesson_index)
|
||||
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
|
||||
context.lesson_index = lesson_index
|
||||
context.chapter_index = chapter_index
|
||||
context.livecode_url = get_livecode_url()
|
||||
|
||||
outline = course.get_outline()
|
||||
outline = context.course.get_outline()
|
||||
next_ = outline.get_next(lesson_number)
|
||||
prev_ = outline.get_prev(lesson_number)
|
||||
context.next_url = get_learn_url(course_name, batch_name, next_)
|
||||
@@ -41,6 +29,3 @@ def get_learn_url(course_name, batch_name, lesson_number):
|
||||
if not lesson_number:
|
||||
return
|
||||
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
|
||||
|
||||
def get_livecode_url():
|
||||
return frappe.db.get_single_value("LMS Settings", "livecode_url")
|
||||
@@ -11,9 +11,10 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course_slug, batch_code) }}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ BatchHearder(course.name, member_count)}}
|
||||
{{ BatchHearder(course.title, member_count)}}
|
||||
{{ MembersList(members)}}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -36,4 +37,4 @@
|
||||
<hr>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
{% endmacro %}
|
||||
8
community/www/batch/members.py
Normal file
8
community/www/batch/members.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
|
||||
context.members = utils.get_batch_members(context.batch.name)
|
||||
context.member_count = len(context.members)
|
||||
@@ -8,7 +8,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch_code) }}
|
||||
{{ Sidebar(course, batch) }}
|
||||
<div class="container">
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -3,7 +3,6 @@ from community.lms.models import Course
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
course_name = frappe.form_dict["course"]
|
||||
batch_name = frappe.form_dict["batch"]
|
||||
|
||||
43
community/www/batch/utils.py
Normal file
43
community/www/batch/utils.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import frappe
|
||||
from community.lms.models import Course
|
||||
|
||||
def get_common_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
course_name = frappe.form_dict["course"]
|
||||
batch_name = frappe.form_dict["batch"]
|
||||
|
||||
course = Course.find(course_name)
|
||||
if not course:
|
||||
context.template = "www/404.html"
|
||||
return
|
||||
|
||||
batch = course.get_batch(batch_name)
|
||||
if not batch:
|
||||
frappe.local.flags.redirect_location = "/courses/" + course_name
|
||||
raise frappe.Redirect
|
||||
|
||||
context.course = course
|
||||
context.batch = batch
|
||||
context.livecode_url = get_livecode_url()
|
||||
|
||||
def get_livecode_url():
|
||||
return frappe.db.get_single_value("LMS Settings", "livecode_url")
|
||||
|
||||
def get_batch_members(batch_name):
|
||||
members = []
|
||||
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch_name}, ["member", "member_type"])
|
||||
|
||||
for membership in memberships:
|
||||
member = get_member_with_name(membership.member)
|
||||
if membership.member_type == "Mentor":
|
||||
member.is_mentor = True
|
||||
members.append(member)
|
||||
return members
|
||||
|
||||
def get_member_with_name(name):
|
||||
try:
|
||||
return frappe.get_doc("Community Member", name)
|
||||
except frappe.DoesNotExistError:
|
||||
return
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import frappe
|
||||
from community.www.courses.utils import redirect_if_not_a_member, get_course, get_batch_members, get_batch
|
||||
from community.lms.doctype.lms_batch.lms_batch import get_messages
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
context.course_slug = frappe.form_dict["course"]
|
||||
context.course = get_course(context.course_slug)
|
||||
context.batch_code = frappe.form_dict["batch"]
|
||||
redirect_if_not_a_member(context.course_slug, context.batch_code)
|
||||
|
||||
context.batch = get_batch(context.batch_code)
|
||||
context.members = get_batch_members(context.batch.name)
|
||||
context.member_count = len(context.members)
|
||||
context.messages = get_messages(context.batch.name)
|
||||
@@ -1,12 +0,0 @@
|
||||
import frappe
|
||||
from community.www.courses.utils import redirect_if_not_a_member, get_batch, get_member_with_name, get_course, get_batch_members
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
context.course_slug = frappe.form_dict["course"]
|
||||
context.course = get_course(context.course_slug)
|
||||
context.batch_code = frappe.form_dict["batch"]
|
||||
redirect_if_not_a_member(context.course_slug, context.batch_code)
|
||||
context.batch = get_batch(context.batch_code)
|
||||
context.members = get_batch_members(context.batch.name)
|
||||
context.member_count = len(context.members)
|
||||
@@ -1,8 +0,0 @@
|
||||
import frappe
|
||||
from community.www.courses.utils import redirect_if_not_a_member
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
context.course = frappe.form_dict["course"]
|
||||
context.batch_code = frappe.form_dict["batch"]
|
||||
redirect_if_not_a_member(context.course, context.batch_code)
|
||||
@@ -1,12 +1,11 @@
|
||||
{% macro Sidebar(course, batch_code) %}
|
||||
{% macro Sidebar(course, batch, is_mentor=False) %}
|
||||
<div class="sidebar-batch">
|
||||
<a href=""><i class="fa fa-bars fa-lg"></i></a>
|
||||
<br>
|
||||
<a href="/courses/{{course}}/{{batch_code}}/learn"><i class="fa fa-book fa-lg"></i></a>
|
||||
<a href="/courses/{{course}}/{{batch_code}}/schedule"><i class="fa fa-calendar fa-lg"></i></a>
|
||||
<a href="/courses/{{course}}/{{batch_code}}/members"><i class="fa fa-users fa-lg"></i></a>
|
||||
<a href="/courses/{{course}}/{{batch_code}}/discuss"><i class="fa fa-comments fa-lg"></i></a>
|
||||
<a href="/courses/{{course}}/{{batch_code}}/about"><i class="fa fa-info-circle fa-lg"></i></a>
|
||||
<!-- <a href="#contact"><i class="fas fa-home fa-lg"></i></a> -->
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/learn"><i class="fa fa-book fa-lg"></i></a>
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/schedule"><i class="fa fa-calendar fa-lg"></i></a>
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/members"><i class="fa fa-users fa-lg"></i></a>
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/discuss"><i class="fa fa-comments fa-lg"></i></a>
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/about"><i class="fa fa-info-circle fa-lg"></i></a>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
Reference in New Issue
Block a user