refactor: moved courses/*/index pages to batch/*

This commit is contained in:
Anand Chitipothu
2021-05-21 13:12:52 +05:30
parent a2b856aaf8
commit e04bbb633d
20 changed files with 148 additions and 81 deletions

View File

@@ -141,12 +141,12 @@ primary_rules = [
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"}, {"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
{"from_route": "/dashboard", "to_route": ""}, {"from_route": "/dashboard", "to_route": ""},
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"}, {"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "courses/learn"}, {"from_route": "/courses/<course>/<batch>/learn", "to_route": "batch/learn"},
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "courses/learn"}, {"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "courses/schedule"}, {"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
{"from_route": "/courses/<course>/<batch>/members", "to_route": "courses/members"}, {"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "courses/discuss"}, {"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
{"from_route": "/courses/<course>/<batch>/about", "to_route": "courses/about"} {"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
] ]
# Any frappe default URL is blocked by profile-rules, add it here to unblock it # Any frappe default URL is blocked by profile-rules, add it here to unblock it

View File

@@ -37,13 +37,37 @@ class LMSBatch(Document):
member_names = [m['member'] for m in memberships] member_names = [m['member'] for m in memberships]
return find_all("Community Member", name=["IN", member_names]) return find_all("Community Member", name=["IN", member_names])
def is_member(self, email): def is_member(self, email, member_type=None):
"""Checks if a person is part of a batch. """Checks if a person is part of a batch.
If member_type is specified, checks if the person is a Student/Mentor.
""" """
member = find("Community Member", email=email) member = find("Community Member", email=email)
return member and frappe.db.exists( if not member:
return
filters = {
"batch": self.name,
"member": member.name
}
if member_type:
filters['member_type'] = member_type
return frappe.db.exists("LMS Batch Membership", filters)
def get_students(self):
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
"""
memberships = frappe.get_all(
"LMS Batch Membership", "LMS Batch Membership",
{"batch": self.name, "member": member.name}) {"batch": self.name, "member_type": "Student"},
["member"])
member_names = [m['member'] for m in memberships]
members = frappe.get_all(
"Community Member",
{"name": ["IN", member_names]},
["email", "full_name", "username"])
return members
@frappe.whitelist() @frappe.whitelist()
def get_messages(batch): def get_messages(batch):

View File

@@ -312,3 +312,28 @@ section.lightgray {
border: 1px solid #ddd; border: 1px solid #ddd;
margin-bottom: 20px; margin-bottom: 20px;
} }
.svg-200 svg {
width: 200px;
height: 200px;
}
.livecode-editor-small .livecode-editor {
.CodeMirror-scroll {
max-height: 160px;
min-height: 160px;
}
canvas {
width: 150px;
height: 150px;
}
}
.mentor-dashboard {
margin-top: 20px;
.submission {
margin: 40px 0px 0px 20px;
}
}

View File

View File

@@ -11,7 +11,8 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course.name, batch.name) }} {{ Sidebar(course, batch) }}
<div class="container"> <div class="container">
{{ CourseBasicDetail(course)}} {{ CourseBasicDetail(course)}}
{{ InstructorsSection(course.get_instructor()) }} {{ InstructorsSection(course.get_instructor()) }}

View File

@@ -0,0 +1,7 @@
import frappe
from . import utils
def get_context(context):
utils.get_common_context(context)
print("context", context)

View File

@@ -11,10 +11,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course_slug, batch_code) }} {{ Sidebar(course, batch) }}
<div class=""> <div class="">
<div class="batch-header"> <div class="batch-header">
{{ BatchHearder(course.name, member_count) }} {{ BatchHearder(course.title, member_count) }}
</div> </div>
<div class="messages"> <div class="messages">
<div class="message-section"> <div class="message-section">

View 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)

View File

@@ -23,7 +23,7 @@
{% block content %} {% block content %}
{{ Sidebar(course.name, batch.name) }} {{ Sidebar(course, batch) }}
<div class="container"> <div class="container">
<div class="lesson-page"> <div class="lesson-page">

View File

@@ -1,37 +1,25 @@
import frappe import frappe
from community.lms.models import Course from . import utils
def get_context(context): 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") chapter_index = frappe.form_dict.get("chapter")
lesson_index = frappe.form_dict.get("lesson") lesson_index = frappe.form_dict.get("lesson")
lesson_number = f"{chapter_index}.{lesson_index}" lesson_number = f"{chapter_index}.{lesson_index}"
course = Course.find(course_name) course_name = context.course.name
if not course: batch_name = context.batch.name
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
if not chapter_index or not lesson_index: if not chapter_index or not lesson_index:
frappe.local.flags.redirect_location = f"/courses/{course_name}/{batch_name}/learn/1.1" frappe.local.flags.redirect_location = f"/courses/{course_name}/{batch_name}/learn/1.1"
raise frappe.Redirect raise frappe.Redirect
context.course = course context.lesson = context.course.get_lesson(chapter_index, lesson_index)
context.batch = batch
context.lesson = course.get_lesson(chapter_index, lesson_index)
context.lesson_index = lesson_index context.lesson_index = lesson_index
context.chapter_index = chapter_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) next_ = outline.get_next(lesson_number)
prev_ = outline.get_prev(lesson_number) prev_ = outline.get_prev(lesson_number)
context.next_url = get_learn_url(course_name, batch_name, next_) 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: if not lesson_number:
return return
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}" return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
def get_livecode_url():
return frappe.db.get_single_value("LMS Settings", "livecode_url")

View File

@@ -11,9 +11,10 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course_slug, batch_code) }} {{ Sidebar(course, batch) }}
<div class="container"> <div class="container">
{{ BatchHearder(course.name, member_count)}} {{ BatchHearder(course.title, member_count)}}
{{ MembersList(members)}} {{ MembersList(members)}}
</div> </div>
{% endblock %} {% endblock %}
@@ -36,4 +37,4 @@
<hr> <hr>
{% endfor %} {% endfor %}
</div> </div>
{% endmacro %} {% endmacro %}

View 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)

View File

@@ -8,7 +8,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course, batch_code) }} {{ Sidebar(course, batch) }}
<div class="container"> <div class="container">
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -3,7 +3,6 @@ from community.lms.models import Course
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
course_name = frappe.form_dict["course"] course_name = frappe.form_dict["course"]
batch_name = frappe.form_dict["batch"] batch_name = frappe.form_dict["batch"]

View 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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -1,12 +1,11 @@
{% macro Sidebar(course, batch_code) %} {% macro Sidebar(course, batch, is_mentor=False) %}
<div class="sidebar-batch"> <div class="sidebar-batch">
<a href=""><i class="fa fa-bars fa-lg"></i></a> <a href=""><i class="fa fa-bars fa-lg"></i></a>
<br> <br>
<a href="/courses/{{course}}/{{batch_code}}/learn"><i class="fa fa-book 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}}/{{batch_code}}/schedule"><i class="fa fa-calendar 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}}/{{batch_code}}/members"><i class="fa fa-users 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}}/{{batch_code}}/discuss"><i class="fa fa-comments 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}}/{{batch_code}}/about"><i class="fa fa-info-circle fa-lg"></i></a> <a href="/courses/{{course.name}}/{{batch.name}}/about"><i class="fa fa-info-circle fa-lg"></i></a>
<!-- <a href="#contact"><i class="fas fa-home fa-lg"></i></a> -->
</div> </div>
{% endmacro %} {% endmacro %}