Compare commits
47 Commits
community-
...
ui-fixes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fa8bdd40c | ||
|
|
17f03aeee7 | ||
|
|
7840512a13 | ||
|
|
f5f3c808d4 | ||
|
|
1e3152e303 | ||
|
|
344661cf83 | ||
|
|
d9185c0b6b | ||
|
|
5363fb7eb3 | ||
|
|
d90a1247f1 | ||
|
|
ef0c3e4a24 | ||
|
|
3619b136f8 | ||
|
|
671b4a0650 | ||
|
|
586b39c0fd | ||
|
|
4fd7af053b | ||
|
|
5fd1143f76 | ||
|
|
0dc4743556 | ||
|
|
c96a14c972 | ||
|
|
400e706be1 | ||
|
|
a12a52747e | ||
|
|
b9a93bb160 | ||
|
|
9c65ff8ae6 | ||
|
|
bb0aa09b4e | ||
|
|
a8752afb3b | ||
|
|
327bde870b | ||
|
|
640ead4922 | ||
|
|
687f7f7f7b | ||
|
|
527a563e4a | ||
|
|
5bc9a7fe37 | ||
|
|
24835acd9c | ||
|
|
3648b3ab47 | ||
|
|
914f8504a0 | ||
|
|
ab8546a121 | ||
|
|
f327c6fb10 | ||
|
|
c7ccefa632 | ||
|
|
823cf4e431 | ||
|
|
18f074d8ac | ||
|
|
c9185ae68c | ||
|
|
82fa0fa4d7 | ||
|
|
64752433d2 | ||
|
|
50856fdfa5 | ||
|
|
cac4f2afef | ||
|
|
df431165e8 | ||
|
|
69125e571f | ||
|
|
68f7215b95 | ||
|
|
ca42c32f54 | ||
|
|
20adc8079e | ||
|
|
631275e9a8 |
@@ -3,13 +3,14 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
class CommunityProjectMember(Document):
|
||||
def validate(self):
|
||||
self.validate_if_already_member()
|
||||
|
||||
|
||||
def validate_if_already_member(self):
|
||||
if frappe.get_all("Community Project Member", {"owner": self.owner}):
|
||||
frappe.throw(_("You have already applied for the membership of this project."))
|
||||
|
||||
@@ -136,13 +136,15 @@ primary_rules = [
|
||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||
{"from_route": "/dashboard", "to_route": ""},
|
||||
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
||||
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
|
||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
|
||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
|
||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
|
||||
{"from_route": "/courses/<course>/<batch>/progress", "to_route": "batch/progress"}
|
||||
{"from_route": "/courses/<course>/home", "to_route": "batch/home"},
|
||||
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/schedule", "to_route": "batch/schedule"},
|
||||
{"from_route": "/courses/<course>/members", "to_route": "batch/members"},
|
||||
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
|
||||
{"from_route": "/courses/<course>/about", "to_route": "batch/about"},
|
||||
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
|
||||
{"from_route": "/courses/<course>/join", "to_route": "batch/join"}
|
||||
]
|
||||
|
||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||
@@ -174,3 +176,15 @@ profile_rules = [
|
||||
website_route_rules = primary_rules + whitelist_rules + profile_rules
|
||||
|
||||
update_website_context = 'community.widgets.update_website_context'
|
||||
|
||||
## Specify the additional tabs to be included in the user profile page.
|
||||
## Each entry must be a subclass of community.community.plugins.ProfileTab
|
||||
# profile_tabs = []
|
||||
|
||||
## Specify the extension to be used to control what scripts and stylesheets
|
||||
## to be included in lesson pages. The specified value must be be a
|
||||
## subclass of community.community.plugins.PageExtension
|
||||
# community_lesson_page_extension = None
|
||||
|
||||
## Markdown Macros for Lessons
|
||||
# community_markdown_macro_renderers = {"Exercise": "myapp.mymodule.plugins.render_exercise"}
|
||||
|
||||
@@ -15,13 +15,6 @@ def autosave_section(section, code):
|
||||
doc.insert()
|
||||
return {"name": doc.name}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_section(name):
|
||||
"""Saves the code edited in one of the sections.
|
||||
"""
|
||||
doc = frappe.get_doc("LMS Section", name)
|
||||
return doc and doc.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
def submit_solution(exercise, code):
|
||||
"""Submits a solution.
|
||||
@@ -34,3 +27,21 @@ def submit_solution(exercise, code):
|
||||
return
|
||||
doc = ex.submit(code)
|
||||
return {"name": doc.name, "creation": doc.creation}
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_current_lesson(batch_name, lesson_name):
|
||||
"""Saves the current lesson for a student/mentor.
|
||||
"""
|
||||
name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"batch": batch_name,
|
||||
"member": frappe.session.user
|
||||
},
|
||||
fieldname="name")
|
||||
if not name:
|
||||
return
|
||||
doc = frappe.get_doc("LMS Batch Membership", name)
|
||||
doc.current_lesson = lesson_name
|
||||
doc.save(ignore_permissions=True)
|
||||
return {"current_lesson": doc.current_lesson}
|
||||
|
||||
@@ -10,6 +10,6 @@ class Chapter(Document):
|
||||
def get_lessons(self):
|
||||
rows = frappe.db.get_all("Lesson",
|
||||
filters={"chapter": self.name},
|
||||
fields='*',
|
||||
fields='name',
|
||||
order_by="index_")
|
||||
return [frappe.get_doc(dict(row, doctype='Lesson')) for row in rows]
|
||||
return [frappe.get_doc('Lesson', row['name']) for row in rows]
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-04-07 00:26:28.806520",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"section",
|
||||
"code",
|
||||
"author"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "section",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Section",
|
||||
"options": "LMS Section"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "author",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Author",
|
||||
"options": "User"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-14 11:26:19.628317",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Code Revision",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "section",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -15,7 +15,9 @@
|
||||
"hints",
|
||||
"tests",
|
||||
"image",
|
||||
"lesson"
|
||||
"lesson",
|
||||
"index_",
|
||||
"index_label"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -27,6 +29,7 @@
|
||||
{
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
@@ -73,13 +76,27 @@
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "index_",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-20 13:23:12.340928",
|
||||
"modified": "2021-06-01 05:22:15.656013",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Exercise",
|
||||
@@ -99,8 +116,8 @@
|
||||
}
|
||||
],
|
||||
"search_fields": "title",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"sort_field": "index_label",
|
||||
"sort_order": "ASC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -25,7 +25,6 @@ class Exercise(Document):
|
||||
order_by="creation desc",
|
||||
page_length=1)
|
||||
|
||||
print("get_user_submission", result)
|
||||
if result:
|
||||
return result[0]
|
||||
|
||||
@@ -55,5 +54,6 @@ class Exercise(Document):
|
||||
image=image,
|
||||
solution=code)
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ class TestExercise(unittest.TestCase):
|
||||
course = frappe.get_doc({
|
||||
"doctype": "LMS Course",
|
||||
"name": "test-course",
|
||||
"title": "Test Course"
|
||||
"title": "Test Course",
|
||||
"short_introduction": "Test Course",
|
||||
"description": "Test Course"
|
||||
})
|
||||
course.insert()
|
||||
e = frappe.get_doc({
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ..lesson.lesson import update_progress
|
||||
|
||||
class ExerciseSubmission(Document):
|
||||
pass
|
||||
|
||||
def after_insert(self):
|
||||
course_details = frappe.get_doc("LMS Course", self.course)
|
||||
if not (course_details.is_mentor(frappe.session.user) or frappe.flags.in_test):
|
||||
update_progress(self.lesson)
|
||||
|
||||
@@ -58,7 +58,8 @@ def create_invite_request(invite_email):
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "Invite Request",
|
||||
"invite_email": invite_email
|
||||
"invite_email": invite_email,
|
||||
"status": "Approved"
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestInviteRequest(unittest.TestCase):
|
||||
filters={"invite_email": "test_invite@example.com"},
|
||||
fieldname=["invite_email", "status", "signup_email"],
|
||||
as_dict=True)
|
||||
self.assertEqual(invite.status, "Pending")
|
||||
self.assertEqual(invite.status, "Approved")
|
||||
self.assertEqual(invite.signup_email, None)
|
||||
|
||||
def test_create_invite_request_update(self):
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
"field_order": [
|
||||
"chapter",
|
||||
"lesson_type",
|
||||
"include_in_preview",
|
||||
"column_break_4",
|
||||
"title",
|
||||
"index_",
|
||||
"body",
|
||||
"sections"
|
||||
"index_label",
|
||||
"section_break_6",
|
||||
"body"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -47,15 +50,30 @@
|
||||
"label": "Body"
|
||||
},
|
||||
{
|
||||
"fieldname": "sections",
|
||||
"fieldtype": "Table",
|
||||
"label": "Sections",
|
||||
"options": "LMS Section"
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "include_in_preview",
|
||||
"fieldtype": "Check",
|
||||
"label": "Include In Preview"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-13 20:03:51.510605",
|
||||
"modified": "2021-06-11 19:03:23.138165",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Lesson",
|
||||
|
||||
@@ -5,41 +5,100 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ...section_parser import SectionParser
|
||||
from ...md import markdown_to_html, find_macros
|
||||
|
||||
class Lesson(Document):
|
||||
def before_save(self):
|
||||
sections = SectionParser().parse(self.body or "")
|
||||
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
|
||||
for s in self.sections:
|
||||
if s.type == "exercise":
|
||||
e = s.get_exercise()
|
||||
e.lesson = self.name
|
||||
e.save()
|
||||
macros = find_macros(self.body)
|
||||
exercises = [value for name, value in macros if name == "Exercise"]
|
||||
|
||||
def get_sections(self):
|
||||
return sorted(self.get('sections'), key=lambda s: s.index)
|
||||
index = 1
|
||||
for name in exercises:
|
||||
e = frappe.get_doc("Exercise", name)
|
||||
e.lesson = self.name
|
||||
e.index_ = index
|
||||
e.save()
|
||||
index += 1
|
||||
self.update_orphan_exercises(exercises)
|
||||
|
||||
def make_lms_section(self, index, section):
|
||||
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
|
||||
s.type = section.type
|
||||
s.id = section.id
|
||||
s.label = section.label
|
||||
s.contents = section.contents
|
||||
s.index = index
|
||||
return s
|
||||
|
||||
def get_next(self):
|
||||
"""Returns the number for the next lesson.
|
||||
|
||||
The return value would be like 1.2, 2.1 etc.
|
||||
It will be None if there is no next lesson.
|
||||
def update_orphan_exercises(self, active_exercises):
|
||||
"""Updates the exercises that were previously part of this lesson,
|
||||
but not any more.
|
||||
"""
|
||||
linked_exercises = {row['name'] for row in frappe.get_all('Exercise', {"lesson": self.name})}
|
||||
active_exercises = set(active_exercises)
|
||||
orphan_exercises = linked_exercises - active_exercises
|
||||
for name in orphan_exercises:
|
||||
ex = frappe.get_doc("Exercise", name)
|
||||
ex.lesson = None
|
||||
ex.index_ = 0
|
||||
ex.index_label = ""
|
||||
ex.save()
|
||||
|
||||
def render_html(self):
|
||||
return markdown_to_html(self.body)
|
||||
|
||||
def get_prev(self):
|
||||
"""Returns the number for the prev lesson.
|
||||
def get_exercises(self):
|
||||
if not self.body:
|
||||
return []
|
||||
|
||||
The return value would be like 1.2, 2.1 etc.
|
||||
It will be None if there is no next lesson.
|
||||
"""
|
||||
macros = find_macros(self.body)
|
||||
exercises = [value for name, value in macros if name == "Exercise"]
|
||||
return [frappe.get_doc("Exercise", name) for name in exercises]
|
||||
|
||||
def get_progress(self):
|
||||
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
||||
|
||||
def get_slugified_class(self):
|
||||
if self.get_progress():
|
||||
return ("").join([ s for s in self.get_progress().lower().split() ])
|
||||
return
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_progress(lesson, batch):
|
||||
if not frappe.db.exists("LMS Batch Membership",
|
||||
{
|
||||
"member": frappe.session.user,
|
||||
"batch": batch
|
||||
}):
|
||||
return
|
||||
if frappe.db.exists("LMS Course Progress",
|
||||
{
|
||||
"lesson": lesson,
|
||||
"owner": frappe.session.user
|
||||
}):
|
||||
return
|
||||
|
||||
lesson_details = frappe.get_doc("Lesson", lesson)
|
||||
dynamic_content = find_macros(lesson_details.body)
|
||||
|
||||
status = "Complete"
|
||||
if dynamic_content:
|
||||
status = "Partially Complete"
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Progress",
|
||||
"lesson": lesson_details.name,
|
||||
"status": status
|
||||
}).save(ignore_permissions=True)
|
||||
|
||||
def update_progress(lesson):
|
||||
user = frappe.session.user
|
||||
if not all_dynamic_content_submitted(lesson, user):
|
||||
return
|
||||
if frappe.db.exists("LMS Course Progress", {"lesson": lesson, "owner": user}):
|
||||
course_progress = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
|
||||
course_progress.status = "Complete"
|
||||
course_progress.save(ignore_permissions=True)
|
||||
|
||||
def all_dynamic_content_submitted(lesson, user):
|
||||
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, pluck="name", ignore_permissions=True)
|
||||
all_exercises_submitted = False
|
||||
query = {
|
||||
"exercise": ["in", exercise_names],
|
||||
"owner": user
|
||||
}
|
||||
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
|
||||
all_exercises_submitted = True
|
||||
|
||||
return all_exercises_submitted
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"course",
|
||||
"title",
|
||||
"start_date",
|
||||
"start_time",
|
||||
"column_break_3",
|
||||
"code",
|
||||
"title",
|
||||
"sessions_on",
|
||||
"end_time",
|
||||
"section_break_5",
|
||||
@@ -31,13 +30,6 @@
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Data",
|
||||
"label": "Code",
|
||||
"read_only": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
@@ -84,7 +76,8 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_5",
|
||||
"fieldtype": "Section Break"
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Batch Description"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_9",
|
||||
@@ -92,7 +85,8 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_7",
|
||||
"fieldtype": "Section Break"
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Batch Settings"
|
||||
},
|
||||
{
|
||||
"fieldname": "start_date",
|
||||
@@ -126,7 +120,7 @@
|
||||
"link_fieldname": "batch"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-06 05:46:38.469120",
|
||||
"modified": "2021-05-26 16:43:57.399747",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch",
|
||||
|
||||
@@ -12,8 +12,6 @@ from community.query import find, find_all
|
||||
class LMSBatch(Document):
|
||||
def validate(self):
|
||||
self.validate_if_mentor()
|
||||
if not self.code:
|
||||
self.generate_code()
|
||||
|
||||
def validate_if_mentor(self):
|
||||
course = frappe.get_doc("LMS Course", self.course)
|
||||
@@ -23,11 +21,6 @@ class LMSBatch(Document):
|
||||
def after_insert(self):
|
||||
create_membership(batch=self.name, member_type="Mentor")
|
||||
|
||||
def generate_code(self):
|
||||
short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
|
||||
course_batches = frappe.get_all("LMS Batch",{"course":self.course})
|
||||
self.code = short_code + str(len(course_batches) + 1)
|
||||
|
||||
def get_mentors(self):
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
@@ -69,6 +62,24 @@ class LMSBatch(Document):
|
||||
message.is_author = True
|
||||
return messages
|
||||
|
||||
def get_membership(self, email):
|
||||
"""Returns the membership document of given user.
|
||||
"""
|
||||
name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"batch": self.name,
|
||||
"member": email
|
||||
},
|
||||
fieldname="name")
|
||||
return frappe.get_doc("LMS Batch Membership", name)
|
||||
|
||||
def get_current_lesson(self, user):
|
||||
"""Returns the name of the current lesson for the given user.
|
||||
"""
|
||||
membership = self.get_membership(user)
|
||||
return membership and membership.current_lesson
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_message(message, batch):
|
||||
doc = frappe.get_doc({
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Batch Membership', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function(frm) {
|
||||
frm.set_query('member', function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"ignore_user_type": 1,
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
"batch",
|
||||
"member",
|
||||
"member_name",
|
||||
"member_email",
|
||||
"member_username",
|
||||
"column_break_3",
|
||||
"course",
|
||||
"member_type",
|
||||
"role"
|
||||
"role",
|
||||
"current_lesson",
|
||||
"is_current"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -59,15 +61,6 @@
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.email",
|
||||
"fieldname": "member_email",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Member Email",
|
||||
"read_only": 1,
|
||||
"read_only_depends_on": "member.email"
|
||||
},
|
||||
{
|
||||
"fetch_from": "batch.course",
|
||||
"fieldname": "course",
|
||||
@@ -75,11 +68,32 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "current_lesson",
|
||||
"fieldtype": "Link",
|
||||
"label": "Current Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.username",
|
||||
"fieldname": "member_username",
|
||||
"fieldtype": "Data",
|
||||
"label": "Memeber Username",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_current",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 1,
|
||||
"label": "Is Currently Being Used",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-24 09:32:04.128620",
|
||||
"modified": "2021-06-14 10:24:35.425498",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch Membership",
|
||||
|
||||
@@ -17,7 +17,8 @@ class LMSBatchMembership(Document):
|
||||
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
||||
filters={
|
||||
"member": self.member,
|
||||
"batch": self.batch, "name": ["!=", self.name]
|
||||
"batch": self.batch,
|
||||
"name": ["!=", self.name]
|
||||
},
|
||||
fieldname=["member_type","member"],
|
||||
as_dict=1)
|
||||
@@ -30,9 +31,10 @@ class LMSBatchMembership(Document):
|
||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||
previous_membership = frappe.get_all("LMS Batch Membership",
|
||||
filters={
|
||||
"member": self.member
|
||||
"member": self.member,
|
||||
"name": ["!=", self.name]
|
||||
},
|
||||
fields=["batch", "member_type"]
|
||||
fields=["batch", "member_type", "name"]
|
||||
)
|
||||
|
||||
for membership in previous_membership:
|
||||
@@ -51,3 +53,13 @@ def create_membership(batch, member=None, member_type="Student", role="Member"):
|
||||
"member": member or frappe.session.user
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_current_membership(batch, course, member=frappe.session.user):
|
||||
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": course})
|
||||
for membership in all_memberships:
|
||||
frappe.db.set_value("LMS Batch Membership", membership.name, "is_current", 0)
|
||||
|
||||
current_membership = frappe.get_all("LMS Batch Membership", {"batch": batch, "member": member})
|
||||
if len(current_membership):
|
||||
frappe.db.set_value("LMS Batch Membership", current_membership[0].name, "is_current", 1)
|
||||
|
||||
@@ -3,8 +3,78 @@
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSBatchMembership(unittest.TestCase):
|
||||
pass
|
||||
def setUp(self):
|
||||
frappe.db.sql("DELETE FROM `tabLMS Batch Membership`")
|
||||
frappe.db.sql("DELETE FROM `tabLMS Batch`")
|
||||
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
|
||||
frappe.db.sql("DELETE FROM `tabLMS Course`")
|
||||
frappe.db.sql("DELETE FROM `tabUser` where email like '%@test.com'")
|
||||
|
||||
def new_course_batch(self):
|
||||
course = frappe.get_doc({
|
||||
"doctype": "LMS Course",
|
||||
"name": "test-course",
|
||||
"title": "Test Course",
|
||||
"short_code": "XX",
|
||||
"short_introduction": "Test Course",
|
||||
"description": "Test Course"
|
||||
})
|
||||
course.insert()
|
||||
|
||||
self.new_user("mentor@test.com", "Test Mentor")
|
||||
# without this, the creating batch will fail
|
||||
course.add_mentor("mentor@test.com")
|
||||
|
||||
frappe.session.user = "mentor@test.com"
|
||||
|
||||
batch = frappe.get_doc({
|
||||
"doctype": "LMS Batch",
|
||||
"name": "test-batch",
|
||||
"title": "Test Batch",
|
||||
"course": course.name
|
||||
})
|
||||
batch.insert(ignore_permissions=True)
|
||||
|
||||
frappe.session.user = "Administrator"
|
||||
return course, batch
|
||||
|
||||
def new_user(self, email="test@test.com", full_name="Test User"):
|
||||
user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"name": email,
|
||||
"email": email,
|
||||
"first_name": full_name,
|
||||
})
|
||||
user.insert()
|
||||
return user
|
||||
|
||||
def add_membership(self, batch_name, member_name, member_type="Student"):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Batch Membership",
|
||||
"batch": batch_name,
|
||||
"member": member_name,
|
||||
"member_type": member_type
|
||||
})
|
||||
doc.insert()
|
||||
return doc
|
||||
|
||||
def test_membership(self):
|
||||
course, batch = self.new_course_batch()
|
||||
member = self.new_user("test01@test.com")
|
||||
membership = self.add_membership(batch.name, member.name)
|
||||
|
||||
assert membership.course == course.name
|
||||
assert membership.member_name == member.full_name
|
||||
|
||||
def test_membership_change_role(self):
|
||||
course, batch = self.new_course_batch()
|
||||
member = self.new_user("test01@test.com")
|
||||
membership = self.add_membership(batch.name, member.name)
|
||||
|
||||
# it should be possible to change role
|
||||
membership.role = "Admin"
|
||||
membership.save()
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
{
|
||||
"actions": [],
|
||||
"actions": [
|
||||
{
|
||||
"action": "community.lms.doctype.lms_course.lms_course.reindex_lessons",
|
||||
"action_type": "Server Action",
|
||||
"group": "Reindex",
|
||||
"label": "Reindex Lessons"
|
||||
},
|
||||
{
|
||||
"action": "community.lms.doctype.lms_course.lms_course.reindex_exercises",
|
||||
"action_type": "Server Action",
|
||||
"group": "Reindex",
|
||||
"label": "Reindex Exercises"
|
||||
}
|
||||
],
|
||||
"allow_guest_to_view": 1,
|
||||
"allow_rename": 1,
|
||||
"creation": "2021-03-01 16:49:33.622422",
|
||||
@@ -28,7 +41,8 @@
|
||||
{
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Description"
|
||||
"label": "Description",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@@ -57,7 +71,8 @@
|
||||
{
|
||||
"fieldname": "short_introduction",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Short Introduction"
|
||||
"label": "Short Introduction",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
@@ -84,7 +99,7 @@
|
||||
"link_fieldname": "course"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-06 13:37:03.318829",
|
||||
"modified": "2021-06-01 04:36:45.696776",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course",
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from ...utils import slugify
|
||||
from community.query import find, find_all
|
||||
from frappe.utils import flt
|
||||
|
||||
class LMSCourse(Document):
|
||||
@staticmethod
|
||||
@@ -111,7 +113,7 @@ class LMSCourse(Document):
|
||||
"""Returns all chapters of this course.
|
||||
"""
|
||||
# TODO: chapters should have a way to specify the order
|
||||
return find_all("Chapter", course=self.name, order_by="creation")
|
||||
return find_all("Chapter", course=self.name, order_by="index_")
|
||||
|
||||
def get_batch(self, batch_name):
|
||||
return find("LMS Batch", name=batch_name, course=self.name)
|
||||
@@ -150,6 +152,62 @@ class LMSCourse(Document):
|
||||
"name")
|
||||
return lesson_name and frappe.get_doc("Lesson", lesson_name)
|
||||
|
||||
def get_lesson_index(self, lesson_name):
|
||||
"""Returns the {chapter_index}.{lesson_index} for the lesson.
|
||||
"""
|
||||
lesson = frappe.get_doc("Lesson", lesson_name)
|
||||
chapter = frappe.get_doc("Chapter", lesson.chapter)
|
||||
return f"{chapter.index_}.{lesson.index_}"
|
||||
|
||||
def reindex_lessons(self):
|
||||
for i, c in enumerate(self.get_chapters(), start=1):
|
||||
c.index_ = i
|
||||
c.save()
|
||||
self._reindex_lessons_in_chapter(c)
|
||||
|
||||
def _reindex_lessons_in_chapter(self, c):
|
||||
for i, lesson in enumerate(c.get_lessons(), start=1):
|
||||
lesson.index = i
|
||||
lesson.index_label = f"{c.index_}.{i}"
|
||||
lesson.save()
|
||||
|
||||
def reindex_exercises(self):
|
||||
for i, c in enumerate(self.get_chapters(), start=1):
|
||||
if c.index_ != i:
|
||||
c.index_ = i
|
||||
c.save()
|
||||
self._reindex_exercises_in_chapter(c)
|
||||
|
||||
def _reindex_exercises_in_chapter(self, c):
|
||||
i = 1
|
||||
for lesson in c.get_lessons():
|
||||
for exercise in lesson.get_exercises():
|
||||
exercise.index_ = i
|
||||
exercise.index_label = f"{c.index_}.{i}"
|
||||
exercise.save()
|
||||
i += 1
|
||||
|
||||
def get_learn_url(self, lesson_number):
|
||||
if not lesson_number:
|
||||
return
|
||||
return f"/courses/{self.name}/learn/{lesson_number}"
|
||||
|
||||
def get_current_batch(self, member=frappe.session.user):
|
||||
current_membership = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name, "is_current": 1}, pluck="batch")
|
||||
print(current_membership, member, self.name)
|
||||
if len(current_membership):
|
||||
return current_membership[0]
|
||||
print(frappe.db.get_value("LMS Batch Membership", {"member": member, "course": self.name}, "batch"))
|
||||
return frappe.db.get_value("LMS Batch Membership", {"member": member, "course": self.name}, "batch")
|
||||
|
||||
def get_all_memberships(self, member=frappe.session.user):
|
||||
print(member)
|
||||
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch", "is_current"])
|
||||
print(all_memberships)
|
||||
for membership in all_memberships:
|
||||
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
|
||||
return all_memberships
|
||||
|
||||
def get_outline(self):
|
||||
return CourseOutline(self)
|
||||
|
||||
@@ -160,6 +218,7 @@ class CourseOutline:
|
||||
self.lessons = self.get_lessons()
|
||||
|
||||
def get_next(self, current):
|
||||
current = flt(current)
|
||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||
try:
|
||||
index = numbers.index(current)
|
||||
@@ -168,6 +227,7 @@ class CourseOutline:
|
||||
return None
|
||||
|
||||
def get_prev(self, current):
|
||||
current = flt(current)
|
||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||
try:
|
||||
index = numbers.index(current)
|
||||
@@ -180,7 +240,8 @@ class CourseOutline:
|
||||
def get_chapters(self):
|
||||
return frappe.db.get_all("Chapter",
|
||||
filters={"course": self.course.name},
|
||||
fields=["name", "title", "index_"])
|
||||
fields=["name", "title", "index_"],
|
||||
order_by="index_")
|
||||
|
||||
def get_lessons(self):
|
||||
chapters = [c['name'] for c in self.chapters]
|
||||
@@ -190,5 +251,19 @@ class CourseOutline:
|
||||
|
||||
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
|
||||
for lesson in lessons:
|
||||
lesson['number'] = "{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_'])
|
||||
lesson['number'] = flt("{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_']))
|
||||
return lessons
|
||||
|
||||
@frappe.whitelist()
|
||||
def reindex_lessons(doc):
|
||||
course_data = json.loads(doc)
|
||||
course = frappe.get_doc("LMS Course", course_data['name'])
|
||||
course.reindex_lessons()
|
||||
frappe.msgprint("All lessons in this course have been re-indexed.")
|
||||
|
||||
@frappe.whitelist()
|
||||
def reindex_exercises(doc):
|
||||
course_data = json.loads(doc)
|
||||
course = frappe.get_doc("LMS Course", course_data['name'])
|
||||
course.reindex_exercises()
|
||||
frappe.msgprint("All exercises in this course have been re-indexed.")
|
||||
|
||||
@@ -15,7 +15,9 @@ class TestLMSCourse(unittest.TestCase):
|
||||
def new_course(self, title):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Course",
|
||||
"title": title
|
||||
"title": title,
|
||||
"short_introduction": title,
|
||||
"description": title
|
||||
})
|
||||
doc.insert()
|
||||
return doc
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Code Revision', {
|
||||
frappe.ui.form.on('LMS Course Progress', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-31 17:20:13.388453",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"status",
|
||||
"column_break_3",
|
||||
"lesson",
|
||||
"chapter",
|
||||
"course"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fetch_from": "chapter.course",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "lesson.chapter",
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"options": "Complete\nPartially Complete\nIncomplete"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-02 13:05:31.114939",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course Progress",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CodeRevision(Document):
|
||||
class LMSCourseProgress(Document):
|
||||
pass
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCodeRevision(unittest.TestCase):
|
||||
class TestLMSCourseProgress(unittest.TestCase):
|
||||
pass
|
||||
@@ -18,7 +18,7 @@ class LMSMessage(Document):
|
||||
template = self.get_message_template()
|
||||
message = frappe._dict({
|
||||
"author_name": self.author_name,
|
||||
"message_time": frappe.utils.pretty_date(self.creation),
|
||||
"message_time": frappe.utils.format_datetime(self.creation, "dd-mm-yyyy HH:mm"),
|
||||
"message": frappe.utils.md_to_html(self.message)
|
||||
})
|
||||
|
||||
@@ -32,26 +32,28 @@ class LMSMessage(Document):
|
||||
template = frappe.render_template(template, {{
|
||||
"message": message
|
||||
}})
|
||||
$(".message-section").append(template);
|
||||
$(".messages").append(template);
|
||||
var message_element = document.getElementsByClassName("messages")[0]
|
||||
message_element.scrollTo(0, message_element.scrollHeight);
|
||||
""".format(template, message, self.owner)
|
||||
|
||||
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
||||
|
||||
def get_message_template(self):
|
||||
return """
|
||||
<div class="discussion {% if message.is_author %} is-author {% endif %}">
|
||||
<li class="{% if message.is_author %} ours {% endif %}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="font-weight-bold">
|
||||
{{ message.author_name }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
<small class="">
|
||||
{{ message.message_time }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<div class="message-para">
|
||||
{{ message.message }}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
"""
|
||||
|
||||
def send_email(self):
|
||||
@@ -106,4 +108,3 @@ def send_daily_digest():
|
||||
},
|
||||
delayed = False
|
||||
)
|
||||
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-03-05 15:10:53.906006",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"label",
|
||||
"type",
|
||||
"contents",
|
||||
"code",
|
||||
"attrs",
|
||||
"index",
|
||||
"id"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Label"
|
||||
},
|
||||
{
|
||||
"fieldname": "type",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Type"
|
||||
},
|
||||
{
|
||||
"fieldname": "contents",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Contents"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "attrs",
|
||||
"fieldtype": "Long Text",
|
||||
"label": "attrs"
|
||||
},
|
||||
{
|
||||
"fieldname": "index",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index"
|
||||
},
|
||||
{
|
||||
"fieldname": "id",
|
||||
"fieldtype": "Data",
|
||||
"label": "id"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-19 18:55:26.019625",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Section",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSSection(Document):
|
||||
def __repr__(self):
|
||||
return f"<LMSSection {self.label!r}>"
|
||||
|
||||
def get_exercise(self):
|
||||
if self.type == "exercise":
|
||||
return frappe.get_doc("Exercise", self.id)
|
||||
|
||||
def get_latest_code_for_user(self):
|
||||
"""Returns the latest code for the logged in user.
|
||||
"""
|
||||
if not frappe.session.user or frappe.session.user == "Guest":
|
||||
return self.contents
|
||||
result = frappe.get_all('Code Revision',
|
||||
fields=["code"],
|
||||
filters={
|
||||
"author": frappe.session.user,
|
||||
"section": self.name
|
||||
},
|
||||
order_by="creation desc",
|
||||
page_length=1)
|
||||
if result:
|
||||
return result[0]['code']
|
||||
else:
|
||||
return self.contents
|
||||
107
community/lms/md.py
Normal file
107
community/lms/md.py
Normal file
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
The md module extends markdown to add macros.
|
||||
|
||||
Macros can be added to the markdown text in the following format.
|
||||
|
||||
{{ MacroName("macro-argument") }}
|
||||
|
||||
These macros will be rendered using a pluggable mechanism.
|
||||
|
||||
Apps can provide a hook community_markdown_macro_renderers, a
|
||||
dictionary mapping the macro name to the function that to render
|
||||
that macro. The function will get the argument passed to the macro
|
||||
as argument.
|
||||
"""
|
||||
|
||||
import frappe
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
import markdown
|
||||
from markdown import Extension
|
||||
from markdown.inlinepatterns import InlineProcessor
|
||||
import xml.etree.ElementTree as etree
|
||||
|
||||
def markdown_to_html(text):
|
||||
"""Renders markdown text into html.
|
||||
"""
|
||||
return markdown.markdown(text, extensions=['fenced_code', MacroExtension()])
|
||||
|
||||
def find_macros(text):
|
||||
"""Returns all macros in the given text.
|
||||
|
||||
>>> find_macros(text)
|
||||
[
|
||||
('YouTubeVideo': 'abcd1234')
|
||||
('Exercise', 'two-circles'),
|
||||
('Exercise', 'four-circles')
|
||||
]
|
||||
"""
|
||||
macros = re.findall(MACRO_RE, text)
|
||||
# remove the quotes around the argument
|
||||
return [(name, _remove_quotes(arg)) for name, arg in macros]
|
||||
|
||||
def _remove_quotes(value):
|
||||
"""Removes quotes around a value.
|
||||
|
||||
Also strips the whitespace.
|
||||
|
||||
>>> _remove_quotes('"hello"')
|
||||
'hello'
|
||||
>>> _remove_quotes("'hello'")
|
||||
'hello'
|
||||
>>> _remove_quotes("hello")
|
||||
'hello'
|
||||
"""
|
||||
return value.strip(" '\"")
|
||||
|
||||
|
||||
def get_macro_registry():
|
||||
d = frappe.get_hooks("community_markdown_macro_renderers") or {}
|
||||
return {name: frappe.get_attr(klass[0]) for name, klass in d.items()}
|
||||
|
||||
def render_macro(macro_name, macro_argument):
|
||||
# stripping the quotes on either side of the argument
|
||||
macro_argument = _remove_quotes(macro_argument)
|
||||
|
||||
registry = get_macro_registry()
|
||||
if macro_name in registry:
|
||||
return registry[macro_name](macro_argument)
|
||||
else:
|
||||
return f"<p>Unknown macro: {macro_name}</p>"
|
||||
|
||||
MACRO_RE = r'{{ *(\w+)\(([^{}]*)\) *}}'
|
||||
|
||||
class MacroExtension(Extension):
|
||||
"""MacroExtension is a markdown extension to support macro syntax.
|
||||
"""
|
||||
def extendMarkdown(self, md):
|
||||
self.md = md
|
||||
pattern = MacroInlineProcessor(MACRO_RE)
|
||||
pattern.md = md
|
||||
md.inlinePatterns.register(pattern, 'macro', 75)
|
||||
|
||||
class MacroInlineProcessor(InlineProcessor):
|
||||
"""MacroInlineProcessor is class that is handles the logic
|
||||
of how to render each macro occurence in the markdown text.
|
||||
"""
|
||||
def handleMatch(self, m, data):
|
||||
"""Handles each macro match and return rendered contents
|
||||
for that macro as an etree node.
|
||||
"""
|
||||
macro = m.group(1)
|
||||
arg = m.group(2)
|
||||
html = render_macro(macro, arg)
|
||||
html = sanitize_html(str(html))
|
||||
e = etree.fromstring(html)
|
||||
return e, m.start(0), m.end(0)
|
||||
|
||||
def sanitize_html(html):
|
||||
"""Sanotize the html using BeautifulSoup.
|
||||
|
||||
The markdown processor request the correct markup and crashes on
|
||||
any broken tags. This makes sures that all those things are fixed
|
||||
before passing to the etree parser.
|
||||
"""
|
||||
soup = BeautifulSoup(html, features="lxml")
|
||||
nodes = soup.body.children
|
||||
return "<div>" + "\n".join(str(node) for node in nodes) + "</div>"
|
||||
@@ -2,4 +2,4 @@
|
||||
"""
|
||||
from .doctype.lms_course.lms_course import LMSCourse as Course
|
||||
from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch
|
||||
|
||||
from .doctype.lms_batch_membership.lms_batch_membership import LMSBatchMembership as Membership
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
"""Utility to split the text in the topic into multiple sections.
|
||||
|
||||
{{ section(type="example", id="foo") }}
|
||||
circle(100, 100, 50)
|
||||
{{ end }}
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
import re
|
||||
from typing import List, Tuple, Dict, Iterator
|
||||
|
||||
RE_SECTION = re.compile(r"^\{\{\s(\w+)\s*(?:\((.*)\))?\s*\}\}\s*")
|
||||
class SectionParser:
|
||||
def parse(self, text: str) -> Iterator[Section]:
|
||||
"""Parses given text into sections and return an iterator over sections.
|
||||
"""
|
||||
lines = text.splitlines()
|
||||
marked_lines = self.parse_lines(lines)
|
||||
return self.group_sections(marked_lines)
|
||||
|
||||
def parse_lines(self, lines: List[str]) -> List[Tuple[str, str, str]]:
|
||||
for line in lines:
|
||||
m = RE_SECTION.match(line)
|
||||
if m:
|
||||
yield m.group(1), self.parse_attrs(m.group(2)), None
|
||||
else:
|
||||
yield None, None, line
|
||||
|
||||
def parse_attrs(self, attrs_str: str) -> Dict[str, str]:
|
||||
# XXX-Anand: Hack
|
||||
code = "dict({})".format(attrs_str or "")
|
||||
return eval(code)
|
||||
|
||||
def group_sections(self, marked_lines) -> Iterator[Section]:
|
||||
index = 0
|
||||
|
||||
def make_section(type='text', id=None, label=None, **attrs):
|
||||
nonlocal index
|
||||
index += 1
|
||||
|
||||
id = id or f"section-{index}"
|
||||
label = label or id
|
||||
return Section(
|
||||
type=type,
|
||||
id=id,
|
||||
label=label,
|
||||
attrs=attrs)
|
||||
|
||||
section = make_section("text")
|
||||
|
||||
for mark, attrs, line in marked_lines:
|
||||
if not mark:
|
||||
section.append(line)
|
||||
continue
|
||||
|
||||
yield section
|
||||
|
||||
if mark == 'end':
|
||||
section = make_section(type='text')
|
||||
else:
|
||||
section = make_section(**attrs)
|
||||
|
||||
yield section
|
||||
|
||||
@dataclass
|
||||
class Section:
|
||||
"""One section of the Topic.
|
||||
"""
|
||||
type: str
|
||||
id: str
|
||||
label: str
|
||||
contents: str = ""
|
||||
attrs: dict = None
|
||||
|
||||
def append(self, line):
|
||||
if not line.endswith("\n"):
|
||||
line = line + "\n"
|
||||
self.contents += line
|
||||
|
||||
def __repr__(self):
|
||||
attrs = dict(type=self.type, id=self.id, label=self.label, **self.attrs)
|
||||
attrs_str = ", ".join(f'{k}="{v}"' for k, v in attrs.items())
|
||||
return f'<Section({attrs_str})>'
|
||||
@@ -11,7 +11,7 @@
|
||||
"apply_document_permissions": 0,
|
||||
"button_label": "Save",
|
||||
"creation": "2021-04-20 11:37:49.135114",
|
||||
"custom_css": ".datepicker.active {\n background-color: white;\n}",
|
||||
"custom_css": ".datepicker.active {\n background-color: white;\n}\n\n[data-doctype=\"Web Form\"] {\n max-width: 720px;\n margin: 6rem auto;\n}",
|
||||
"doc_type": "LMS Batch",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
@@ -19,7 +19,7 @@
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-04-30 11:22:18.188712",
|
||||
"modified": "2021-06-14 15:28:08.206622",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "add-a-new-batch",
|
||||
@@ -38,13 +38,13 @@
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"label": "Course",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "",
|
||||
"read_only": 1,
|
||||
"options": "LMS Course",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
@@ -111,4 +111,4 @@
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
frappe.ready(function() {
|
||||
// bind events here
|
||||
})
|
||||
@@ -1,48 +0,0 @@
|
||||
{
|
||||
"accept_payment": 0,
|
||||
"allow_comments": 0,
|
||||
"allow_delete": 0,
|
||||
"allow_edit": 0,
|
||||
"allow_incomplete": 0,
|
||||
"allow_multiple": 0,
|
||||
"allow_print": 0,
|
||||
"amount": 0.0,
|
||||
"amount_based_on_field": 0,
|
||||
"apply_document_permissions": 0,
|
||||
"button_label": "Save",
|
||||
"creation": "2021-04-15 13:32:14.171328",
|
||||
"doc_type": "LMS Batch Membership",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-04-15 13:32:14.171328",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "join-a-batch",
|
||||
"owner": "Administrator",
|
||||
"payment_button_label": "Buy Now",
|
||||
"published": 1,
|
||||
"route": "join-a-batch",
|
||||
"route_to_success_link": 0,
|
||||
"show_attachments": 0,
|
||||
"show_in_grid": 0,
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_url": "/join-a-batch",
|
||||
"title": "Join a Batch",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldtype": "Attach",
|
||||
"hidden": 0,
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
# do your magic here
|
||||
pass
|
||||
4
community/lms/widgets/BatchHeader.html
Normal file
4
community/lms/widgets/BatchHeader.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<div class="p-5 batch-header">
|
||||
<h3>{{batch_name}}</h3>
|
||||
<div class="text-muted">{{member_count}} members</div>
|
||||
</div>
|
||||
76
community/lms/widgets/BatchTabs.html
Normal file
76
community/lms/widgets/BatchTabs.html
Normal file
@@ -0,0 +1,76 @@
|
||||
<div class="mt-5">
|
||||
<a class="anchor_style" href="/courses">Courses</a> /{% if course.is_mentor(frappe.session.user) %} <a
|
||||
class="anchor_style" href="/courses/{{ course.name }}"> {{ course.title }}</a> {% else %} <span class="text-muted">
|
||||
{{ course.title }}</span> {% endif %}
|
||||
{% set all_memberships = course.get_all_memberships() %}
|
||||
{% if all_memberships | length > 1 %}
|
||||
<a class="nav-link pull-right" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
Switch Batch
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||
{% for membership in all_memberships %}
|
||||
{% if not membership.is_current %}
|
||||
<a class="dropdown-item switch-batch" href="#" data-batch="{{ membership.batch | urlencode }}" data-course="{{ course.name | urlencode }}">{{ membership.batch_title }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if not batch %}
|
||||
{% set display_class = "hide" %}
|
||||
{% else %}
|
||||
{% set display_class = "" %}
|
||||
{% endif %}
|
||||
<ul class="nav nav-tabs mt-4">
|
||||
<li class="nav-item {{ display_class }}">
|
||||
<a class="nav-link" id="home" href="/courses/{{course.name}}/home">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="learn" href="/courses/{{course.name}}/learn">Lessons</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/schedule">Schedule</a>
|
||||
</li> -->
|
||||
<li class="nav-item {{ display_class }}">
|
||||
<a class="nav-link" id="members" href="/courses/{{course.name}}/members">Members</a>
|
||||
</li>
|
||||
<li class="nav-item {{ display_class }}">
|
||||
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/discuss">Discussion</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a class="nav-link" id="about" href="/courses/{{course.name}}/about">About</a>
|
||||
</li> -->
|
||||
{% if batch and batch.is_member(frappe.session.user, member_type="Mentor") %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress">Progress</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}"]`)
|
||||
if (selector) {
|
||||
selector.classList.add('active');
|
||||
}
|
||||
else {
|
||||
$("#learn").addClass('active')
|
||||
}
|
||||
|
||||
$(".switch-batch").click((e) => {
|
||||
e.preventDefault();
|
||||
var batch = decodeURIComponent($(e.currentTarget).attr("data-batch"));
|
||||
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
|
||||
frappe.call({
|
||||
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
|
||||
args: {
|
||||
batch: batch,
|
||||
course: course
|
||||
},
|
||||
callback: (data) => {
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@@ -1,15 +1,54 @@
|
||||
<div class="chapter-teaser">
|
||||
<div class="teaser-body">
|
||||
<h3 class="chapter-title"><span class="chapter-number">{{index}}</span> {{ chapter.title }}</h3>
|
||||
<div class="chapter-title mb-5 font-weight-bold"><span class="mr-1">{{index}}.</span> {{ chapter.title }}</div>
|
||||
<div class="chapter-description">
|
||||
{{ chapter.description or "" }}
|
||||
</div>
|
||||
<div class="chapter-lessons">
|
||||
{% for lesson in chapter.get_lessons() %}
|
||||
<div class="lesson-teaser">
|
||||
{{lesson.title}}
|
||||
</div>
|
||||
<div class="lesson-teaser">
|
||||
<a {% if show_link or lesson.include_in_preview %}
|
||||
href="{{ course.get_learn_url(course.get_lesson_index(lesson.name)) }}" {% else %} href="" class="no-preview"
|
||||
{% endif %} data-course="{{ course.name }}">{{ lesson.title }}</a>
|
||||
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %}
|
||||
<a class="ml-5 badge p-1 {{ lesson.get_slugified_class() }}"> <img class="progress-image"
|
||||
src="/assets/community/images/Vector.png"> {{ lesson.get_progress() }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
var d;
|
||||
$(".no-preview").click((e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
var message = __("Please enroll for this course to access the lesson.");
|
||||
var label = __("Checkout Upcoming Batches");
|
||||
var action = "checkout_upcoming_batches";
|
||||
d = frappe.msgprint({
|
||||
title: __("This lesson is not available for preview!"),
|
||||
message: message,
|
||||
primary_action: {
|
||||
"label": label,
|
||||
"client_action": action,
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
window.redirect_to_login = () => {
|
||||
window.location.href = `/login?redirect-to=/courses/${$(".no-preview").attr("data-course")}`
|
||||
}
|
||||
|
||||
window.checkout_upcoming_batches = () => {
|
||||
if ($(".upcoming").length > 0) {
|
||||
$('html,body').animate({ scrollTop: $(".upcoming").offset().top }, 300);
|
||||
}
|
||||
frappe.hide_msgprint();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
7
community/lms/widgets/CourseOutline.html
Normal file
7
community/lms/widgets/CourseOutline.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="mt-5">
|
||||
<h3> Course Outline </h3>
|
||||
|
||||
{% for chapter in course.get_chapters() %}
|
||||
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}}
|
||||
{% endfor %}
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||
|
||||
<div class="exercise">
|
||||
<h2>{{ exercise.title }}</h2>
|
||||
<h2>Exercise {{exercise.index_label}}: {{ exercise.title }}</h2>
|
||||
<div class="exercise-description">{{frappe.utils.md_to_html(exercise.description)}}</div>
|
||||
|
||||
{% if exercise.image %}
|
||||
|
||||
6
community/lms/widgets/InstructorSection.html
Normal file
6
community/lms/widgets/InstructorSection.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<div class="instructor">
|
||||
{{ widgets.Avatar(member=instructor, avatar_class="avatar-medium") }}
|
||||
<a class="ml-1 instructor-title" href="/{{instructor.username}}">{{ instructor.full_name }}</a>
|
||||
<div class="instructor-subtitle">Course Creator</div>
|
||||
<!-- <div class="instructor-subtitle">Created {{instructor.get_course_count()}} courses</div> -->
|
||||
</div>
|
||||
30
community/lms/widgets/RenderBatch.html
Normal file
30
community/lms/widgets/RenderBatch.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<div class="batch">
|
||||
<div class="batch-details">
|
||||
<div class="">Session every {{batch.sessions_on}}</div>
|
||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
||||
{{frappe.utils.format_time(batch.end_time, "short")}}
|
||||
</div>
|
||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
||||
|
||||
{% for m in batch.get_mentors() %}
|
||||
<div>
|
||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||
<span class="instructor-title">{{m.full_name}}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if can_manage or can_join %}
|
||||
<div class="cta">
|
||||
<div class="">
|
||||
{% if can_manage %}
|
||||
<a href="" class="btn btn-primary manage-batch" data-batch="{{ batch.name | urlencode }}"
|
||||
data-course="{{ course.name | urlencode }}">Manage</a>
|
||||
{% elif can_join %}
|
||||
<button class="join-batch btn btn-primary" data-batch="{{ batch.name | urlencode }}"
|
||||
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
66
community/plugins.py
Normal file
66
community/plugins.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
The plugins module provides various plugins to change the default
|
||||
behaviour some parts of the community app.
|
||||
|
||||
A site specify what plugins to use using appropriate entries in the frappe
|
||||
hooks, written in the `hooks.py`.
|
||||
|
||||
This module exposes two plugins: ProfileTab and PageExtension.
|
||||
|
||||
The ProfileTab is used to specify any additional tabs to be displayed
|
||||
on the profile page of the user.
|
||||
|
||||
The PageExtension is used to load additinal stylesheets and scripts to
|
||||
be loaded in a webpage.
|
||||
"""
|
||||
|
||||
class PageExtension:
|
||||
"""PageExtension is a plugin to inject custom styles and scripts
|
||||
into a web page.
|
||||
|
||||
The subclasses should overwrite the `render_header()` and
|
||||
`render_footer()` methods to inject whatever styles/scripts into
|
||||
the webpage.
|
||||
"""
|
||||
|
||||
def render_header(self):
|
||||
"""Returns the HTML snippet to be included in the head section
|
||||
of the web page.
|
||||
|
||||
Typically used to include the stylesheets and javascripts to be
|
||||
included in the <head> of the webpage.
|
||||
"""
|
||||
return ""
|
||||
|
||||
def render_footer(self):
|
||||
"""Returns the HTML snippet to be included in the body tag at
|
||||
the end of web page.
|
||||
|
||||
Typically used to include javascripts that need to be executed
|
||||
after the page is loaded.
|
||||
"""
|
||||
return ""
|
||||
|
||||
class ProfileTab:
|
||||
"""Base class for profile tabs.
|
||||
|
||||
Every subclass of ProfileTab must implement two methods:
|
||||
- get_title()
|
||||
- render()
|
||||
"""
|
||||
def __init__(self, user):
|
||||
self.user = user
|
||||
|
||||
def get_title(self):
|
||||
"""Returns the title of the tab.
|
||||
|
||||
Every subclass must implement this.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def render(self):
|
||||
"""Renders the contents of the tab as HTML.
|
||||
|
||||
Every subclass must implement this.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
@@ -82,6 +82,7 @@ body {
|
||||
border-radius: 10px;
|
||||
margin: 10px 0px;
|
||||
background: white;
|
||||
box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);
|
||||
border: 1px solid #ddc;
|
||||
}
|
||||
|
||||
@@ -97,14 +98,6 @@ body {
|
||||
border-top: 1px solid #ddc;
|
||||
}
|
||||
|
||||
.batch .cta button {
|
||||
background: var(--cta-color);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.batch .right {
|
||||
float: right;
|
||||
}
|
||||
@@ -127,44 +120,13 @@ img.profile-photo {
|
||||
max-width: 100%
|
||||
}
|
||||
|
||||
|
||||
/* override style of base */
|
||||
|
||||
.message {
|
||||
border: 1px dashed var(--text-color);
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.dashboard__profile {
|
||||
width: 150px;
|
||||
height: 155px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.dashboard__profileSmall {
|
||||
width: 59px;
|
||||
height: 57px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.dashboard__abbr {
|
||||
font-size: 50px;
|
||||
width: 155px;
|
||||
height: 155px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.dashboard__abbrSmall {
|
||||
font-size: 20px;
|
||||
width: 59px;
|
||||
height: 57px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.msger-inputarea {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
@@ -182,37 +144,6 @@ img.profile-photo {
|
||||
flex: 1;
|
||||
background: #ddd;
|
||||
}
|
||||
.msger-send-btn {
|
||||
margin-left: 10px;
|
||||
background: var(--cta-color);
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
transition: background 0.23s;
|
||||
}
|
||||
|
||||
.discussion {
|
||||
border: 1px solid var(--text-color);
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 10px;
|
||||
background: var(--received-message);
|
||||
width: 50%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.is-author {
|
||||
float: right;
|
||||
background: var(--send-message);
|
||||
}
|
||||
|
||||
.batch-header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
background: var(--bg);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.message-section {
|
||||
margin-left: 3%;
|
||||
@@ -226,7 +157,105 @@ img.profile-photo {
|
||||
line-height: 51px;
|
||||
}
|
||||
|
||||
.anchor_style {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
section {
|
||||
padding: 5rem 0 5rem 0;
|
||||
}
|
||||
|
||||
.messages-container {
|
||||
margin: 0 auto;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.messages {
|
||||
overflow: auto;
|
||||
height: 450px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
padding: 8px;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
.messages li {
|
||||
background: #F7F5F5;
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
margin: 2px 8px 2px 0;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.messages li.ours {
|
||||
align-self: flex-end;
|
||||
margin: 2px 0 2px 8px;
|
||||
background: var(--primary-color);
|
||||
color: #fff
|
||||
}
|
||||
|
||||
.message-para {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.batch-header {
|
||||
background: #eee;
|
||||
border: 2px solid #ddd;
|
||||
}
|
||||
|
||||
|
||||
.page-card {
|
||||
max-width: 360px;
|
||||
padding: 15px;
|
||||
margin: 70px auto;
|
||||
border: 1px solid #d1d8dd;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.page-card .page-card-head {
|
||||
padding: 10px 15px;
|
||||
margin: -15px;
|
||||
margin-bottom: 15px;
|
||||
border-bottom: 1px solid #d1d8dd;
|
||||
}
|
||||
.page-card .page-card-head .indicator {
|
||||
color: #36414C;
|
||||
font-size: 14px;
|
||||
}
|
||||
.page-card .page-card-head .indicator::before {
|
||||
margin: 0 6px 0.5px 0px;
|
||||
}
|
||||
.page-card .btn {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.partiallycomplete {
|
||||
background: #FEF4E2;
|
||||
color: #976417;
|
||||
}
|
||||
|
||||
.partiallycomplete img {
|
||||
background: #976417;
|
||||
}
|
||||
|
||||
.complete {
|
||||
background: #EAF5EE;
|
||||
color: #38A160;
|
||||
}
|
||||
|
||||
.complete img {
|
||||
background: #38A160;
|
||||
}
|
||||
|
||||
.incomplete {
|
||||
background: #FEECEC;
|
||||
color: #E24C4C;
|
||||
}
|
||||
|
||||
.incomplete img {
|
||||
background: #E24C4C;
|
||||
}
|
||||
|
||||
.progress-image {
|
||||
margin-right: 3px;
|
||||
border-radius: 50px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ h2 {
|
||||
|
||||
.teaser-body {
|
||||
padding: 20px;
|
||||
box-shadow: 0px 5px 10px rgb(0 0 0 / 10%)
|
||||
}
|
||||
.teaser-footer {
|
||||
padding: 20px;
|
||||
@@ -66,6 +67,20 @@ h2 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.anchor_style {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.anchor_style:hover {
|
||||
text-decoration: none
|
||||
}
|
||||
|
||||
.no-preview:hover {
|
||||
cursor: pointer;
|
||||
color: #2490ef;
|
||||
}
|
||||
|
||||
section {
|
||||
padding: 60px 0px;
|
||||
}
|
||||
@@ -162,7 +177,6 @@ section.lightgray {
|
||||
// }
|
||||
|
||||
.instructor-title {
|
||||
font-weight: bold;
|
||||
color: black;
|
||||
}
|
||||
|
||||
@@ -179,11 +193,8 @@ section.lightgray {
|
||||
.chapter-number {
|
||||
background: var(--text-color);
|
||||
color: white;
|
||||
border-radius: 50%;
|
||||
height: 24px;
|
||||
min-width: 24px;
|
||||
align-items: center;
|
||||
padding: 5px 8px 2px 8px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@@ -257,6 +268,7 @@ section.lightgray {
|
||||
background-color: rgba(255, 255, 255, 0);
|
||||
max-height: 300px;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
margin: 0px;
|
||||
margin-left: 20px;
|
||||
padding: 4px;
|
||||
@@ -287,9 +299,7 @@ section.lightgray {
|
||||
}
|
||||
|
||||
.lesson-teaser {
|
||||
font-weight: bold;
|
||||
color: black;
|
||||
padding-left: 20px;
|
||||
line-height: 40px;
|
||||
}
|
||||
|
||||
#hero h1 {
|
||||
@@ -335,3 +345,9 @@ section.lightgray {
|
||||
margin: 40px 0px 0px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.no-preview-message {
|
||||
width: fit-content;
|
||||
margin: 50px 0px 50px;
|
||||
color: black;
|
||||
}
|
||||
|
||||
BIN
community/public/images/Vector.png
Normal file
BIN
community/public/images/Vector.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 B |
BIN
community/public/images/wallpaper.png
Normal file
BIN
community/public/images/wallpaper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 922 B |
@@ -1,7 +1,4 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% from "www/macros/common_macro.html" import InstructorsSection, MentorsSection %}
|
||||
|
||||
{% block title %}About{% endblock %}
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Courses" />
|
||||
@@ -11,48 +8,33 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ CourseBasicDetail(course)}}
|
||||
{{ InstructorsSection(course.get_instructor()) }}
|
||||
{{ BatchDetails(batch)}}
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<div class="tab-content" id="about">
|
||||
{{ CourseBasicDetail(course)}}
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="col-lg-4 col-md-12">
|
||||
<div class="sidebar">
|
||||
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% macro CourseBasicDetail(course) %}
|
||||
<h2>{{course.title}}</h2>
|
||||
<div class="course-description">
|
||||
{{course.short_introduction}}
|
||||
{{course.short_introduction}}
|
||||
</div>
|
||||
{% if course.video_link %}
|
||||
<div class="preview-video">
|
||||
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen></iframe>
|
||||
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen></iframe>
|
||||
</div>
|
||||
{% endif %}
|
||||
<h2>About the Course</h2>
|
||||
<div>{{frappe.utils.md_to_html(course.description)}}</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro BatchDetails(batch) %}
|
||||
<h2>About the Batch</h2>
|
||||
|
||||
<div class="batch">
|
||||
<div class="batch-details">
|
||||
<div>Session every {{batch.sessions_on}}</div>
|
||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
||||
{{frappe.utils.format_time(batch.end_time, "short")}}</div>
|
||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
||||
|
||||
{% for m in batch.get_mentors() %}
|
||||
<div>
|
||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||
<span class="instructor-title">{{m.full_name}}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -3,5 +3,3 @@ from . import utils
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
|
||||
print("context", context)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% from "www/macros/common_macro.html" import BatchHearder %}
|
||||
|
||||
{% block title %}Discuss{% endblock %}
|
||||
{% block head_include %}
|
||||
@@ -11,16 +9,14 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="">
|
||||
<div class="batch-header">
|
||||
{{ BatchHearder(course.title, member_count) }}
|
||||
</div>
|
||||
<div class="messages">
|
||||
<div class="message-section">
|
||||
<div class="container">
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<div class="messages-container mt-5">
|
||||
{{ widgets.BatchHeader(batch_name=batch.title, member_count=member_count)}}
|
||||
<ol class="messages">
|
||||
{{ Messages(messages) }}
|
||||
</div>
|
||||
</ol>
|
||||
{{ TextArea() }}
|
||||
</div>
|
||||
</div>
|
||||
@@ -28,25 +24,25 @@
|
||||
|
||||
{% macro Messages(messages) %}
|
||||
{% for message in messages %}
|
||||
<div class="discussion {% if message.is_author %} is-author {% endif %}">
|
||||
<li class="{% if message.is_author %} ours {% endif %}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="font-weight-bold">
|
||||
{{ message.author_name }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ frappe.utils.pretty_date(message.creation) }}
|
||||
</div>
|
||||
<small class="">
|
||||
{{ frappe.utils.format_datetime(message.creation, "dd-mm-yyyy HH:mm") }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<div class="message-para">
|
||||
{{ message.message }}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro TextArea() %}
|
||||
<form class="msger-inputarea">
|
||||
<form class="msger-inputarea mb-1">
|
||||
<input type="text" class="msger-input" placeholder="Write your message...">
|
||||
<button type="submit" class="msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
||||
<button type="submit" class="btn btn-primary msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
||||
</form>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -11,7 +11,9 @@ frappe.ready(() => {
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
var message_element = document.getElementsByClassName("messages")[0]
|
||||
message_element.scrollTo(0, message_element.scrollHeight);
|
||||
document.getElementsByClassName("messages-container")[0].scrollIntoView({block: "center"})
|
||||
}, 300);
|
||||
|
||||
$(".msger-send-btn").click((e) => {
|
||||
|
||||
@@ -4,3 +4,5 @@ from . import utils
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
context.messages = context.batch.get_messages()
|
||||
if not context.batch:
|
||||
utils.redirect_to_lesson(context.course)
|
||||
|
||||
62
community/www/batch/home.html
Normal file
62
community/www/batch/home.html
Normal file
@@ -0,0 +1,62 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% block title %} Batch {% endblock %}
|
||||
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Courses" />
|
||||
<meta name="keywords" content="" />
|
||||
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/join?batch=" + batch.name %}
|
||||
<div class="container mt-5">
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<!-- <div>
|
||||
<h1 class="mt-5">{{ batch.title }}</h1>
|
||||
</div> -->
|
||||
<div class="course-details mt-5">
|
||||
{{ widgets.CourseOutline(course=course, batch=batch, show_link=True, show_progress=True) }}
|
||||
</div>
|
||||
<div class="w-25">
|
||||
<h3>Batch Schedule</h3>
|
||||
{{ widgets.RenderBatch(course=course, batch=batch) }}
|
||||
</div>
|
||||
|
||||
{% if batch.description %}
|
||||
<div class="mt-5">
|
||||
<h3>Batch Details</h3>
|
||||
{{ frappe.utils.md_to_html(batch.description) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if course.is_mentor(frappe.session.user) %}
|
||||
<div class="">
|
||||
<h3> Invite Members </h3>
|
||||
<a href="" class="" id="invite-link" data-link="{{ invite_link }}">Get Batch Invitation
|
||||
Link</a>
|
||||
<small id="copy-message" class="text-muted" style="display: none;">Copied to Clipboard.</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
$("#invite-link").click((e) => {
|
||||
e.preventDefault();
|
||||
var link_element = $("#invite-link");
|
||||
var input_element = document.createElement("input");
|
||||
input_element.value = link_element.attr("data-link")
|
||||
document.body.appendChild(input_element);
|
||||
input_element.select();
|
||||
document.execCommand("copy");
|
||||
input_element.remove();
|
||||
$("#copy-message").slideDown(function () {
|
||||
setTimeout(function () {
|
||||
$("#copy-message").slideUp();
|
||||
}, 2000);
|
||||
});
|
||||
})
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
7
community/www/batch/home.py
Normal file
7
community/www/batch/home.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import frappe
|
||||
from . import utils
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
if not context.batch:
|
||||
utils.redirect_to_lesson(context.course)
|
||||
84
community/www/batch/join.html
Normal file
84
community/www/batch/join.html
Normal file
@@ -0,0 +1,84 @@
|
||||
% extends "templates/base.html" %}
|
||||
{% block title %}Join a Course{% endblock %}
|
||||
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Join a Course"/>
|
||||
<meta name="keywords" content="" />
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if frappe.session.user == "Guest" %}
|
||||
|
||||
<div class="page-card">
|
||||
<div class='page-card-head'>
|
||||
<span class='indicator blue password-box'>Login Required</span>
|
||||
</div>
|
||||
<div class=''>Please log in to confirm joining the course {{ batch.course_title }}.</div>
|
||||
<a type="submit" id="login" class="btn btn-primary w-100"
|
||||
href="/login?redirect-to=/courses/{{ batch.course }}/join?batch={{ batch.name }}">{{_("Login")}}</a>
|
||||
</div>
|
||||
|
||||
{% elif already_a_member %}
|
||||
|
||||
<div class="page-card">
|
||||
<div class='page-card-head'>
|
||||
<span class='indicator blue password-box'>Already a member</span>
|
||||
</div>
|
||||
<div class=''>You are already a member of the batch {{ batch.title }} for the course {{ batch.course_title }}.
|
||||
</div>
|
||||
<a type="submit" id="batch-home" class="btn btn-primary w-100" href="">{{_("Go to Batch Home")}}</a>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
|
||||
<div class="page-card">
|
||||
<div class='page-card-head'>
|
||||
<span class='indicator blue password-box'>Confirm your membership</span>
|
||||
</div>
|
||||
<div>Please provide your confirmation to be a part of the batch {{ batch.title }} for the course
|
||||
{{ batch.course_title }}.
|
||||
</div>
|
||||
<a type="submit" id="confirm" class="btn btn-primary w-100">{{_("Confirm")}}</a>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
$("#confirm").click((e) => {
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||
"args": {
|
||||
"batch": "{{ batch.name }}"
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
frappe.msgprint({
|
||||
message: __("You are now a member of this batch!"),
|
||||
clear: true
|
||||
});
|
||||
setTimeout(function () {
|
||||
window.location.href = "/courses/{{ batch.course }}/home";
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$("#batch-home").click((e) => {
|
||||
frappe.call({
|
||||
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
|
||||
args: {
|
||||
"batch": "{{ batch.name }}",
|
||||
"course": "{{ batch.course}}"
|
||||
},
|
||||
callback: (data) => {
|
||||
window.location.href = "/courses/{{ batch.course }}/home"
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
8
community/www/batch/join.py
Normal file
8
community/www/batch/join.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
batch_name = frappe.form_dict["batch"]
|
||||
context.batch = frappe.get_doc("LMS Batch", batch_name)
|
||||
context.already_a_member = context.batch.is_member(frappe.session.user)
|
||||
context.batch.course_title = frappe.db.get_value("LMS Course", context.batch.course, "title")
|
||||
@@ -1,132 +1,67 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||
{% block title %}{{ lesson.title }}{% endblock %}
|
||||
|
||||
{% block head_include %}
|
||||
<meta name="description" content="{{lesson.title}} - {{course.title}}" />
|
||||
<meta name="keywords" content="{{lesson.title}} - {{course.title}}" />
|
||||
<style>
|
||||
</style>
|
||||
<meta name="description" content="{{lesson.title}} - {{course.title}}" />
|
||||
<meta name="keywords" content="{{lesson.title}} - {{course.title}}" />
|
||||
<style>
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
||||
<link rel="stylesheet" href="/assets/css/lms.css">
|
||||
<link rel="stylesheet" href="/assets/frappe/css/hljs-night-owl.css">
|
||||
|
||||
<script src="{{ livecode_url }}/static/codemirror/lib/codemirror.js"></script>
|
||||
<script src="{{ livecode_url }}/static/codemirror/mode/python/python.js"></script>
|
||||
<script src="{{ livecode_url }}/static/codemirror/keymap/sublime.js"></script>
|
||||
{% for ext in page_extensions %}
|
||||
{{ ext.render_header() }}
|
||||
{% endfor %}
|
||||
|
||||
<script src="{{ livecode_url }}/static/codemirror/addon/edit/matchbrackets.js"></script>
|
||||
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<div class="lesson-page">
|
||||
{{ pagination(prev_url, next_url) }}
|
||||
|
||||
<h2>{{ lesson.title }}</h2>
|
||||
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" {% if batch %} data-batch="{{ batch.name }}" {% endif %}>{{ lesson.title }}</h2>
|
||||
|
||||
{% for s in lesson.get_sections() %}
|
||||
<div class="section section-{{ s.type }}">
|
||||
{{ render_section(s) }}
|
||||
{% if batch or lesson.include_in_preview %}
|
||||
{{ lesson.render_html() }}
|
||||
{% else %}
|
||||
<div class="no-preview-message">
|
||||
<span>This lesson is not available for Preview. Please join a batch to access the complete course.</span>
|
||||
<a href="/courses/{{ course.name }}">Checkout Upcoming Batches</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{{ pagination(prev_url, next_url) }}
|
||||
{% endif %}
|
||||
|
||||
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% macro render_section(s) %}
|
||||
{% if s.type == "text" %}
|
||||
{{ render_section_text(s) }}
|
||||
{% elif s.type == "example" or s.type == "code" %}
|
||||
{{ LiveCodeEditor(s.name,
|
||||
code=s.get_latest_code_for_user(),
|
||||
reset_code=s.contents,
|
||||
is_exercise=False)
|
||||
}}
|
||||
{% elif s.type == "exercise" %}
|
||||
{{ widgets.Exercise(exercise=s.get_exercise())}}
|
||||
{% else %}
|
||||
<div>Unknown section type: {{s.type}}</div>
|
||||
{% macro pagination(prev_chap, prev_url, next_chap, next_url) %}
|
||||
<div class="lesson-pagination">
|
||||
{% if prev_url %}
|
||||
<span>
|
||||
Prev: <a href="{{prev_url}}">{{prev_chap}}</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_section_text(s) %}
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
{{ frappe.utils.md_to_html(s.contents) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro pagination(prev_url, next_url) %}
|
||||
<div class="lesson-pagination">
|
||||
{% if prev_url %}
|
||||
<a href="{{prev_url}}" class="btn">← Prev</a>
|
||||
{% endif %}
|
||||
{% if next_url %}
|
||||
<a href="{{next_url}}" class="btn pull-right">Next →</a>
|
||||
{% endif %}
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
{% if next_url %}
|
||||
<span class="pull-right">
|
||||
Next: <a href="{{next_url}}">{{next_chap}}</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
<div style="clear: both;"></div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{%- block script %}
|
||||
{{ super() }}
|
||||
{{ LiveCodeEditorJS() }}
|
||||
{{ super() }}
|
||||
{% for ext in page_extensions %}
|
||||
{{ ext.render_footer() }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<!-- <script type="text/javascript">
|
||||
$(function() {
|
||||
var editorLookup = {};
|
||||
|
||||
$(".canvas-editor").each((i, e) => {
|
||||
var data = $(e).data();
|
||||
var editor = new LiveCodeEditor(e, {
|
||||
runtime: "python-canvas",
|
||||
base_url: "{{ livecode_url }}",
|
||||
codemirror: true,
|
||||
userdata: data,
|
||||
autosave: function(editor, code) {
|
||||
// can't autosave when user is Guest
|
||||
if (frappe.session.user == "Guest") {
|
||||
return;
|
||||
}
|
||||
var data = editor.options.userdata;
|
||||
var code = editor.codemirror.doc.getValue();
|
||||
// console.log("autosaving...")
|
||||
frappe.call("community.lms.api.autosave_section", {
|
||||
section: data.section,
|
||||
code: code
|
||||
}).then((r) => {
|
||||
// TODO: verify
|
||||
})
|
||||
}
|
||||
})
|
||||
editorLookup[data.section] = editor;
|
||||
})
|
||||
|
||||
$(".canvas-editor .reset").each((i, e) => {
|
||||
$(e).on("click", function(event) {
|
||||
var data = $(this).parents(".canvas-editor").data();
|
||||
var section = data.section;
|
||||
frappe.call("community.lms.api.get_section", {
|
||||
name: section
|
||||
}).then(r => {
|
||||
var editor = editorLookup[data.section];
|
||||
editor.codemirror.doc.setValue(r.message.contents);
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
</script> -->
|
||||
{%- endblock %}
|
||||
|
||||
17
community/www/batch/learn.js
Normal file
17
community/www/batch/learn.js
Normal file
@@ -0,0 +1,17 @@
|
||||
frappe.ready(() => {
|
||||
if ($(".title").attr("data-batch") && !$(".title").hasClass("is_mentor")) {
|
||||
frappe.call({
|
||||
method: "community.lms.doctype.lesson.lesson.save_progress",
|
||||
args: {
|
||||
lesson: $(".title").attr("data-name"),
|
||||
batch: $(".title").attr("data-batch")
|
||||
}
|
||||
})
|
||||
}
|
||||
if ($(".title").attr("data-batch")) {
|
||||
frappe.call("community.lms.api.save_current_lesson", {
|
||||
"batch_name": $(".title").attr("data-batch"),
|
||||
"lesson_name": $(".title").attr("data-name")
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -1,5 +1,9 @@
|
||||
from re import I
|
||||
import frappe
|
||||
from . import utils
|
||||
from frappe.utils import cstr
|
||||
|
||||
from community.www import batch
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
@@ -9,23 +13,43 @@ def get_context(context):
|
||||
lesson_number = f"{chapter_index}.{lesson_index}"
|
||||
|
||||
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"
|
||||
if context.batch:
|
||||
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
|
||||
else:
|
||||
index_ = "1.1"
|
||||
frappe.local.flags.redirect_location = context.course.get_learn_url(index_)
|
||||
raise frappe.Redirect
|
||||
|
||||
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
|
||||
context.lesson_index = lesson_index
|
||||
context.chapter_index = chapter_index
|
||||
print(context.lesson)
|
||||
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_)
|
||||
context.prev_url = get_learn_url(course_name, batch_name, prev_)
|
||||
|
||||
def get_learn_url(course_name, batch_name, lesson_number):
|
||||
outline = context.course.get_outline()
|
||||
prev_ = outline.get_prev(lesson_number)
|
||||
next_ = outline.get_next(lesson_number)
|
||||
context.prev_chap = get_chapter_title(course_name, prev_)
|
||||
context.next_chap = get_chapter_title(course_name, next_)
|
||||
context.next_url = context.course.get_learn_url(next_)
|
||||
context.prev_url = context.course.get_learn_url(prev_)
|
||||
|
||||
context.page_extensions = get_page_extensions()
|
||||
|
||||
def get_chapter_title(course_name, lesson_number):
|
||||
if not lesson_number:
|
||||
return
|
||||
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
|
||||
lesson_split = cstr(lesson_number).split(".")
|
||||
chapter_index = lesson_split[0]
|
||||
lesson_index = lesson_split[1]
|
||||
chapter_name = frappe.db.get_value("Chapter", {"course": course_name, "index_": chapter_index}, "name")
|
||||
return frappe.db.get_value("Lesson", {"chapter": chapter_name, "index_": lesson_index}, "title")
|
||||
|
||||
def get_lesson_index(course, batch, user):
|
||||
lesson = batch.get_current_lesson(user)
|
||||
return lesson and course.get_lesson_index(lesson)
|
||||
|
||||
def get_page_extensions():
|
||||
default_value = ["community.community.plugins.PageExtension"]
|
||||
classnames = frappe.get_hooks("community_lesson_page_extensions") or default_value
|
||||
extensions = [frappe.get_attr(name)() for name in classnames]
|
||||
return extensions
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% from "www/macros/common_macro.html" import BatchHearder %}
|
||||
|
||||
{% block title %}Members{% endblock %}
|
||||
{% block head_include %}
|
||||
@@ -10,10 +8,9 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ BatchHearder(course.title, member_count)}}
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
{{ MembersList(members)}}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -23,17 +20,24 @@
|
||||
<div class="mt-5">
|
||||
{% for member in members %}
|
||||
<div class="d-flex align-items-center">
|
||||
<div>
|
||||
{{ widgets.Avatar(member=member, avatar_class="avatar-medium") }}
|
||||
{{ widgets.Avatar(member=member, avatar_class="avatar-large") }}
|
||||
<div class="d-flex flex-column ml-2">
|
||||
<div class="d-flex">
|
||||
<a class="anchor_style ml-2" href="/{{member.username}}">
|
||||
<h3>{{ member.full_name }}</h3>
|
||||
</a>
|
||||
{% if course.is_mentor(member.name) %}
|
||||
<div class="badge badge-success ml-2 align-self-start">Mentor</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if member.bio %}
|
||||
<i class="ml-2">{{member.bio}}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="ml-5 mr-5">
|
||||
<a href="/{{member.username}}">{{ member.full_name }}</a>
|
||||
</div>
|
||||
{% if course.is_mentor(member.name) %}
|
||||
<div class="badge badge-success">Mentor</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if loop.index != member_count %}
|
||||
<hr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -3,3 +3,5 @@ from . import utils
|
||||
|
||||
def get_context(context):
|
||||
utils.get_common_context(context)
|
||||
if not context.batch:
|
||||
utils.redirect_to_lesson(context.course)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||
{% block title %}{{ course.title }} - Batch Dashboard{% endblock %}
|
||||
{% block title %}{{ course.title }} - Batch Dashboard{% endblock %}
|
||||
|
||||
{% block head_include %}
|
||||
<meta name="description" content="{{course.title}} - Batch Dashboard" />
|
||||
<meta name="keywords" content="{{course.title}} - Batch Dashboard" />
|
||||
<style>
|
||||
</style>
|
||||
<meta name="description" content="{{course.title}} - Batch Dashboard" />
|
||||
<meta name="keywords" content="{{course.title}} - Batch Dashboard" />
|
||||
<style>
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
||||
@@ -23,23 +22,23 @@
|
||||
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
|
||||
<div class="container">
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<div class="mentor-dashboard">
|
||||
<h1>Batch Progress</h1>
|
||||
<h3>Batch Progress</h3>
|
||||
{% for exercise in report.exercises %}
|
||||
<div class="exercise-submissions">
|
||||
<h2>{{exercise.title}}</h2>
|
||||
{% for s in report.get_submissions_of_exercise(exercise.name) %}
|
||||
<div class="submission">
|
||||
<h4><a href="/{{s.owner.username}}">{{s.owner.full_name}}</a></h4>
|
||||
<div class="livecode-editor-small">
|
||||
{{ LiveCodeEditor(name=s.name, code=s.solution, reset_code=s.solution) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="exercise-submissions">
|
||||
<h2>Exercise {{exercise.index_label}}: {{exercise.title}}</h2>
|
||||
{% for s in report.get_submissions_of_exercise(exercise.name) %}
|
||||
<div class="submission">
|
||||
<h4><a href="/{{s.owner.username}}">{{s.owner.full_name}}</a></h4>
|
||||
<div class="livecode-editor-small">
|
||||
{{ LiveCodeEditor(name=s.name, code=s.solution, reset_code=s.solution) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -47,6 +46,6 @@
|
||||
|
||||
|
||||
{%- block script %}
|
||||
{{ super() }}
|
||||
{{ LiveCodeEditorJS() }}
|
||||
{{ super() }}
|
||||
{{ LiveCodeEditorJS() }}
|
||||
{% endblock %}
|
||||
|
||||
@@ -19,23 +19,20 @@ class BatchReport:
|
||||
def __init__(self, course, batch):
|
||||
self.submissions = get_submissions(batch)
|
||||
self.exercises = self.get_exercises(course.name)
|
||||
|
||||
self.submissions_by_exercise = defaultdict(list)
|
||||
for s in self.submissions:
|
||||
self.submissions_by_exercise[s.exercise].append(s)
|
||||
|
||||
def get_exercises(self, course_name):
|
||||
return frappe.get_all("Exercise", {"course": course_name}, ["name", "title"])
|
||||
return frappe.get_all("Exercise", {"course": course_name, "lesson": ["!=", ""]}, ["name", "title", "index_label"], order_by="index_label")
|
||||
|
||||
def get_submissions_of_exercise(self, exercise_name):
|
||||
return self.submissions_by_exercise[exercise_name]
|
||||
|
||||
def get_submissions(batch):
|
||||
students = batch.get_students()
|
||||
students_map = {s['email']: s for s in students}
|
||||
|
||||
students_map = {s.email: s for s in students}
|
||||
names, values = nparams("s", students_map.keys())
|
||||
|
||||
sql = """
|
||||
select owner, exercise, name, solution, creation, image
|
||||
from (
|
||||
@@ -46,7 +43,6 @@ def get_submissions(batch):
|
||||
""".format(names)
|
||||
|
||||
data = frappe.db.sql(sql, values=values, as_dict=True)
|
||||
|
||||
for row in data:
|
||||
row['owner'] = students_map[row['owner']]
|
||||
return data
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||
{% block title %}Schedule{% endblock %}
|
||||
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Courses" />
|
||||
<meta name="keywords" content="" />
|
||||
@@ -8,7 +8,10 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{{ Sidebar(course, batch) }}
|
||||
<div class="container">
|
||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||
<h3>
|
||||
Schedule
|
||||
</h3>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,24 +5,26 @@ 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_name = course.get_current_batch()
|
||||
batch = course.get_batch(batch_name)
|
||||
if not batch:
|
||||
frappe.local.flags.redirect_location = "/courses/" + course_name
|
||||
raise frappe.Redirect
|
||||
context.batch = batch
|
||||
if batch_name:
|
||||
context.members = batch.get_mentors() + batch.get_students()
|
||||
context.member_count = len(context.members)
|
||||
|
||||
|
||||
context.course = course
|
||||
context.batch = batch
|
||||
context.members = batch.get_mentors() + batch.get_students()
|
||||
context.member_count = len(context.members)
|
||||
context.livecode_url = get_livecode_url()
|
||||
|
||||
def get_livecode_url():
|
||||
return frappe.db.get_single_value("LMS Settings", "livecode_url")
|
||||
|
||||
def redirect_to_lesson(course, index_="1.1"):
|
||||
frappe.local.flags.redirect_location = course.get_learn_url(index_)
|
||||
raise frappe.Redirect
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/macros/common_macro.html" import InstructorsSection, MentorsSection %}
|
||||
{% from "www/macros/common_macro.html" import MentorsSection %}
|
||||
{% block title %}{{ course.title }}{% endblock %}
|
||||
{% block head_include %}
|
||||
<meta name="description" content="Courses" />
|
||||
@@ -9,27 +9,21 @@
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="course-header">
|
||||
<div class="course-type">course</div>
|
||||
<h1 id="course-title" data-course="{{course.name}}">{{course.title}}</h1>
|
||||
<div class="mb-5">
|
||||
<a class="anchor_style" href="/courses">Courses</a> / <span class="text-muted">{{ course.title }}</span>
|
||||
</div>
|
||||
<h2 id="course-title" data-course="{{course.name}}">{{course.title}}</h2>
|
||||
<div class="course-short-intro">{{ course.short_introduction }}</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-12">
|
||||
<div class="course-details">
|
||||
<div class="">
|
||||
<div class="">
|
||||
<div class="course-details">
|
||||
{{ CourseVideo(course) }}
|
||||
|
||||
{{ CourseDescription(course) }}
|
||||
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
||||
{{ BatchSection(course) }}
|
||||
{{ CourseOutline(course) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-12">
|
||||
<div class="sidebar">
|
||||
{{ InstructorsSection(course.get_instructor()) }}
|
||||
</div>
|
||||
<div class="sidebar">
|
||||
{{ MentorsSection(course.get_mentors(), course.is_mentor(frappe.session.user), course.name) }}
|
||||
{{ widgets.CourseOutline(course=course, show_link=False) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -37,106 +31,73 @@
|
||||
{% endblock %}
|
||||
|
||||
{% macro CourseVideo(course) %}
|
||||
{% if course.video_link %}
|
||||
<div class="preview-video">
|
||||
<iframe
|
||||
width="560"
|
||||
height="315"
|
||||
src="{{course.video_link}}"
|
||||
title="YouTube video player"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen></iframe>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if course.video_link %}
|
||||
<div class="preview-video">
|
||||
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||
allowfullscreen></iframe>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro CourseDescription(course) %}
|
||||
<h2>Course Description</h2>
|
||||
<div class="mt-5">
|
||||
<h3>Course Description</h3>
|
||||
|
||||
<div class="course-description">
|
||||
<div class="course-description text-justify">
|
||||
{{ frappe.utils.md_to_html(course.description) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro BatchSection(course) %}
|
||||
{% if course.is_mentor(frappe.session.user) %}
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-12">
|
||||
{% if course.is_mentor(frappe.session.user) %}
|
||||
{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }}
|
||||
{% else %}
|
||||
{% else %}
|
||||
{{ BatchSectionForStudents(course, course.get_upcoming_batches()) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro RenderBatch(batch, can_manage=False) %}
|
||||
<div class="batch">
|
||||
<div class="batch-details">
|
||||
<div>Session every {{batch.sessions_on}}</div>
|
||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
||||
{{frappe.utils.format_time(batch.end_time, "short")}}</div>
|
||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
||||
|
||||
{% for m in batch.get_mentors() %}
|
||||
<div>
|
||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||
<span class="instructor-title">{{m.full_name}}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="cta">
|
||||
<div class="">
|
||||
{% if can_manage %}
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
|
||||
{% else %}
|
||||
<button class="join-batch" data-batch="{{ batch.name | urlencode }}"
|
||||
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro BatchSectionForMentors(course, mentor_batches) %}
|
||||
<h2>Your Batches</h2>
|
||||
<h2>Your Batches</h2>
|
||||
|
||||
{% if mentor_batches %}
|
||||
<div class="alert alert-secondary">
|
||||
You are a mentor for this course. Manage your batches or create a new batch from here.
|
||||
</div>
|
||||
{% if mentor_batches %}
|
||||
|
||||
<div class="row">
|
||||
{% for batch in mentor_batches %}
|
||||
<div class="col-lg-4 col-md-6">
|
||||
{{ RenderBatch(batch, can_manage=True) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="row">
|
||||
{% for batch in mentor_batches %}
|
||||
<div class="col-lg-4 col-md-6">
|
||||
{{ widgets.RenderBatch(course=course, batch=batch, can_manage=True) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new batch</a>
|
||||
{% else %}
|
||||
<div class="mentor_message">
|
||||
<p> You are a mentor for this course. </p>
|
||||
<a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}" >Create your first batch</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new
|
||||
batch</a>
|
||||
{% else %}
|
||||
<div class="mentor_message">
|
||||
<p> You are a mentor for this course. </p>
|
||||
<a class="" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Create your first batch</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro BatchSectionForStudents(course, upcoming_batches) %}
|
||||
<h2>Upcoming Batches</h2>
|
||||
|
||||
{% if upcoming_batches %}
|
||||
<div class="mt-5">
|
||||
<h3 class="upcoming">Upcoming Batches</h3>
|
||||
<div class="row">
|
||||
{% for batch in upcoming_batches %}
|
||||
<div class="col-lg-4 col-md-6">
|
||||
{{ RenderBatch(batch, can_manage=False) }}
|
||||
{{ widgets.RenderBatch(course=course, batch=batch, can_join=True) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro CourseOutline(course) %}
|
||||
<h2>Course Outline</h2>
|
||||
|
||||
{% for chapter in course.get_chapters() %}
|
||||
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter)}}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="mt-5 upcoming">There are no Upcoming Batches for this course currently.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1,72 +1,92 @@
|
||||
frappe.ready(() => {
|
||||
if (frappe.session.user != "Guest") {
|
||||
frappe.call({
|
||||
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
|
||||
'args': {
|
||||
course: decodeURIComponent($("#course-title").attr("data-course")),
|
||||
},
|
||||
'callback': (data) => {
|
||||
if (data.message > 0) {
|
||||
$("#mentor-request").addClass("hide");
|
||||
$("#already-applied").removeClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if (frappe.session.user != "Guest") {
|
||||
frappe.call({
|
||||
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
|
||||
'args': {
|
||||
course: decodeURIComponent($("#course-title").attr("data-course")),
|
||||
},
|
||||
'callback': (data) => {
|
||||
if (data.message > 0) {
|
||||
$("#mentor-request").addClass("hide");
|
||||
$("#already-applied").removeClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$("#apply-now").click((e) => {
|
||||
$("#apply-now").click((e) => {
|
||||
e.preventDefault();
|
||||
if (frappe.session.user == "Guest") {
|
||||
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
||||
return;
|
||||
}
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
|
||||
"args": {
|
||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
$("#mentor-request").addClass("hide");
|
||||
$("#already-applied").removeClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
if (frappe.session.user == "Guest") {
|
||||
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
||||
return;
|
||||
}
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
|
||||
"args": {
|
||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
$("#mentor-request").addClass("hide");
|
||||
$("#already-applied").removeClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$("#cancel-request").click((e) => {
|
||||
$("#cancel-request").click((e) => {
|
||||
e.preventDefault()
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
|
||||
"args": {
|
||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
$("#mentor-request").removeClass("hide");
|
||||
$("#already-applied").addClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
|
||||
"args": {
|
||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
$("#mentor-request").removeClass("hide");
|
||||
$("#already-applied").addClass("hide")
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$(".join-batch").click((e) => {
|
||||
e.preventDefault()
|
||||
if (frappe.session.user == "Guest") {
|
||||
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
||||
return;
|
||||
}
|
||||
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||
"args": {
|
||||
"batch": batch
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
frappe.msgprint(__("You are now a student of this course."))
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
$(".join-batch").click((e) => {
|
||||
e.preventDefault();
|
||||
var course = $(e.currentTarget).attr("data-course")
|
||||
if (frappe.session.user == "Guest") {
|
||||
window.location.href = `/login?redirect-to=/courses/${course}`;
|
||||
return;
|
||||
}
|
||||
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
||||
frappe.call({
|
||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||
"args": {
|
||||
"batch": batch
|
||||
},
|
||||
"callback": (data) => {
|
||||
if (data.message == "OK") {
|
||||
frappe.msgprint(__("You are now a student of this course."));
|
||||
setTimeout(function () {
|
||||
window.location.href = `/courses/${course}/home`;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$(".manage-batch").click((e) => {
|
||||
e.preventDefault();
|
||||
var batch = decodeURIComponent($(e.currentTarget).attr("data-batch"));
|
||||
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
|
||||
frappe.call({
|
||||
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
|
||||
args: {
|
||||
batch: batch,
|
||||
course: course
|
||||
},
|
||||
callback: (data) => {
|
||||
window.location.href = `/courses/${course}/home`;
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,6 +19,6 @@ def get_context(context):
|
||||
|
||||
batch = course.get_student_batch(frappe.session.user)
|
||||
if batch:
|
||||
frappe.local.flags.redirect_location = f"/courses/{course.name}/{batch.name}/learn"
|
||||
frappe.local.flags.redirect_location = f"/courses/{course.name}/learn"
|
||||
raise frappe.Redirect
|
||||
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
{% extends "templates/base.html" %}
|
||||
{% from "www/hackathons/macros/card.html" import null_card %}
|
||||
{% block title %}{{ 'Courses' }}{% endblock %}
|
||||
{% block head_include %}
|
||||
<meta name="description" content="{{ 'Courses' }}" />
|
||||
<meta name="keywords" content="Courses" />
|
||||
<style>
|
||||
</style>
|
||||
<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'>
|
||||
<h4 class="mt-5">{{ 'All Courses' }}</h4>
|
||||
<div class="row mt-5">
|
||||
{% for course in courses %}
|
||||
{{ course_card(course) }}
|
||||
{{ course_card(course) }}
|
||||
{% endfor %}
|
||||
<!-- {% if courses %}
|
||||
{% for n in range( (3 - (courses|length)) %3) %}
|
||||
{{ null_card() }}
|
||||
{% endfor %}
|
||||
{% endif %} -->
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -24,13 +28,18 @@
|
||||
|
||||
|
||||
{% macro course_card(course) %}
|
||||
<div class="card mb-5 w-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><a href="/courses/{{course.name}}">{{course.title}}</a></h5>
|
||||
{% if course.description %}
|
||||
<p class="card-text">{{ frappe.utils.md_to_html(course.description[:250]) }}</p>
|
||||
{% endif %}
|
||||
<a href="/courses/{{course.name}}" class="card-link">See more →</a>
|
||||
</div>
|
||||
<div class="col-sm-4 mb-4 text-left">
|
||||
<a class="anchor_style" style="color: inherit;" href="/courses/{{course.name}}">
|
||||
<div class="card h-100" style="box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);">
|
||||
<div class='card-body'>
|
||||
<h5 class='card-title'>{{ course.title }}</h5>
|
||||
{% if course.description %}
|
||||
<div class="mt-4">
|
||||
{{ frappe.utils.md_to_html(course.description[:200]) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
frappe.ready(() => {
|
||||
|
||||
})
|
||||
@@ -126,4 +126,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% macro hackathon_card(hackathon) %}
|
||||
<div class="col-sm-4 mb-4 text-left">
|
||||
<a href="/hackathons/{{ hackathon.name }}" class="no-decoration no-underline">
|
||||
<div class="card h-100">
|
||||
<div class="card h-100" style="box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);">
|
||||
<div class='card-body'>
|
||||
<h5 class='card-title'>{{ hackathon.name }}</h5>
|
||||
</div>
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
{% macro null_card() %}
|
||||
<div class="col-sm-4 mb-4 text-left">
|
||||
<div class="h-100 d-none d-sm-block" style="border: 1px solid rgba(209,216,221,0.5);border-radius: 0.25rem;background-color: rgb(250, 251, 252);">
|
||||
<div class="h-100 d-none d-sm-block" style="box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);border-radius: 0.25rem;background-color: rgb(250, 251, 252);">
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
<section id="hero">
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">Guided online courses, with a <br />mentor at your back.</h1>
|
||||
<p class="lead">Hands-on online courses designed by experts, delivered by passionate mentors.</p>
|
||||
<h1 class="display-4">Guided online programming courses, with a <br />mentor at your back.</h1>
|
||||
<p class="lead">Hands-on programming courses designed by experts, delivered by passionate mentors.</p>
|
||||
{{ widgets.RequestInvite() }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
{% macro InstructorsSection(instructor) %}
|
||||
<h3>Instructor</h3>
|
||||
<div class="instructor">
|
||||
<div class="instructor-title">{{instructor.full_name}}</div>
|
||||
<div class="instructor-subtitle">Created {{instructor.get_course_count()}} courses</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro MentorsSection(mentors, is_mentor, course_name) %}
|
||||
<h3>Mentors</h3>
|
||||
{% for m in mentors %}
|
||||
@@ -27,11 +19,3 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro BatchHearder(course_name, member_count) %}
|
||||
<div class="border p-3">
|
||||
<h3>{{course_name}}</h3>
|
||||
<div class="text-muted">{{member_count}} members</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{% 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.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>
|
||||
{% if batch.is_member(frappe.session.user, member_type="Mentor") %}
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/progress"><i class="fa fa-flag-checkered fa-lg"></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@@ -72,29 +72,26 @@
|
||||
</div>
|
||||
<div>
|
||||
<ul class="nav nav-tabs mt-4" id="myTab" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home"
|
||||
aria-selected="true">Sketches</a>
|
||||
</li>
|
||||
{% for tab in profile_tabs %}
|
||||
<li class="nav-item">
|
||||
{% set slug = title.lower().replace(" ", "-") %}
|
||||
{% set selected = loop.index == 1 %}
|
||||
{% set active = 'active' if loop.index == 1 else '' %}
|
||||
<a class="nav-link {{ active }}" id="{{ slug }}-tab" data-toggle="tab" href="#{{ slug }}" role="tab" aria-controls="{{ slug }}"
|
||||
aria-selected="{{ selected }}">Sketches</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade py-4 show active" role="tabpanel" id="home">
|
||||
<div class="row">
|
||||
{% if sketches %}
|
||||
{% for sketch in sketches %}
|
||||
<div class="col-md-4 col-sm-6">
|
||||
{{ widgets.SketchTeaser(sketch=sketch) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for tab in profile_tabs %}
|
||||
{% set slug = title.lower().replace(" ", "-") %}
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade py-4 show active" role="tabpanel" id="slug">
|
||||
{{ tab.render() }}
|
||||
</div>
|
||||
{% if not sketches %}
|
||||
<p class="text-center">{{member.full_name}} has not created any skecth yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,9 +3,20 @@ from community.lms.models import Sketch
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
try:
|
||||
context.member = frappe.get_doc("User", {"username": frappe.form_dict["username"]})
|
||||
except:
|
||||
context.template = "www/404.html"
|
||||
else:
|
||||
context.sketches = Sketch.get_recent_sketches(owner=context.member.email)
|
||||
return
|
||||
|
||||
context.profile_tabs = get_profile_tabs(context.member)
|
||||
|
||||
def get_profile_tabs(user):
|
||||
"""Returns the enabled ProfileTab objects.
|
||||
|
||||
Each ProfileTab is rendered as a tab on the profile page and the
|
||||
they are specified as profile_tabs hook.
|
||||
"""
|
||||
tabs = frappe.get_hooks("profile_tabs") or []
|
||||
return [frappe.get_attr(tab)(user) for tab in tabs]
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
frappe
|
||||
websocket_client
|
||||
markdown
|
||||
beautifulsoup4
|
||||
lxml
|
||||
|
||||
Reference in New Issue
Block a user