Compare commits
42 Commits
lesson-pro
...
quiz
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6c11ce52f | ||
|
|
0284c9305c | ||
|
|
d785fb7562 | ||
|
|
9f50af4ebd | ||
|
|
4c3645f0d4 | ||
|
|
20b3ae7d76 | ||
|
|
f303be4db5 | ||
|
|
fc1c393f15 | ||
|
|
5d96bf544d | ||
|
|
5abfa35095 | ||
|
|
6c751cdf39 | ||
|
|
2c570ea214 | ||
|
|
ecfcc8a2f7 | ||
|
|
3384f974e5 | ||
|
|
eb435261fe | ||
|
|
dc7eabefb9 | ||
|
|
fed4b5568b | ||
|
|
aa77c60abd | ||
|
|
9c1506d3c8 | ||
|
|
e94c3f27ab | ||
|
|
5fa8bdd40c | ||
|
|
17f03aeee7 | ||
|
|
7840512a13 | ||
|
|
526ded784b | ||
|
|
6b5ddcd54a | ||
|
|
c42247db42 | ||
|
|
8f8d4901ff | ||
|
|
f5f3c808d4 | ||
|
|
1e3152e303 | ||
|
|
344661cf83 | ||
|
|
d9185c0b6b | ||
|
|
5363fb7eb3 | ||
|
|
1cb81de5c0 | ||
|
|
d90a1247f1 | ||
|
|
ef0c3e4a24 | ||
|
|
3619b136f8 | ||
|
|
586b39c0fd | ||
|
|
0dc4743556 | ||
|
|
c96a14c972 | ||
|
|
400e706be1 | ||
|
|
a12a52747e | ||
|
|
b9a93bb160 |
@@ -3,8 +3,9 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
class CommunityProjectMember(Document):
|
class CommunityProjectMember(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
|||||||
@@ -136,15 +136,15 @@ primary_rules = [
|
|||||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||||
{"from_route": "/dashboard", "to_route": ""},
|
{"from_route": "/dashboard", "to_route": ""},
|
||||||
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
||||||
{"from_route": "/courses/<course>/<batch>/home", "to_route": "batch/home"},
|
{"from_route": "/courses/<course>/home", "to_route": "batch/home"},
|
||||||
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "batch/learn"},
|
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
{"from_route": "/courses/<course>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
|
{"from_route": "/courses/<course>/schedule", "to_route": "batch/schedule"},
|
||||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
|
{"from_route": "/courses/<course>/members", "to_route": "batch/members"},
|
||||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
|
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
|
||||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
|
{"from_route": "/courses/<course>/about", "to_route": "batch/about"},
|
||||||
{"from_route": "/courses/<course>/<batch>/progress", "to_route": "batch/progress"},
|
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
|
||||||
{"from_route": "/courses/<course>/<batch>/join", "to_route": "batch/join"}
|
{"from_route": "/courses/<course>/join", "to_route": "batch/join"}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||||
@@ -161,10 +161,11 @@ whitelist = [
|
|||||||
"/socket.io",
|
"/socket.io",
|
||||||
"/hackathons",
|
"/hackathons",
|
||||||
"/dashboard",
|
"/dashboard",
|
||||||
"/join-request"
|
"/join-request",
|
||||||
"/add-a-new-batch",
|
"/add-a-new-batch",
|
||||||
"/new-sign-up",
|
"/new-sign-up",
|
||||||
"/message"
|
"/message",
|
||||||
|
"/about"
|
||||||
]
|
]
|
||||||
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
|
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
|
||||||
|
|
||||||
@@ -176,3 +177,19 @@ profile_rules = [
|
|||||||
website_route_rules = primary_rules + whitelist_rules + profile_rules
|
website_route_rules = primary_rules + whitelist_rules + profile_rules
|
||||||
|
|
||||||
update_website_context = 'community.widgets.update_website_context'
|
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": "community.plugins.exercise_renderer",
|
||||||
|
"Quiz": "community.plugins.quiz_renderer",
|
||||||
|
"YouTubeVideo": "community.plugins.youtube_video_renderer",
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,13 +15,6 @@ def autosave_section(section, code):
|
|||||||
doc.insert()
|
doc.insert()
|
||||||
return {"name": doc.name}
|
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()
|
@frappe.whitelist()
|
||||||
def submit_solution(exercise, code):
|
def submit_solution(exercise, code):
|
||||||
"""Submits a solution.
|
"""Submits a solution.
|
||||||
@@ -36,13 +29,13 @@ def submit_solution(exercise, code):
|
|||||||
return {"name": doc.name, "creation": doc.creation}
|
return {"name": doc.name, "creation": doc.creation}
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def save_current_lesson(batch_name, lesson_name):
|
def save_current_lesson(course_name, lesson_name):
|
||||||
"""Saves the current lesson for a student/mentor.
|
"""Saves the current lesson for a student/mentor.
|
||||||
"""
|
"""
|
||||||
name = frappe.get_value(
|
name = frappe.get_value(
|
||||||
doctype="LMS Batch Membership",
|
doctype="LMS Batch Membership",
|
||||||
filters={
|
filters={
|
||||||
"batch": batch_name,
|
"course": course_name,
|
||||||
"member": frappe.session.user
|
"member": frappe.session.user
|
||||||
},
|
},
|
||||||
fieldname="name")
|
fieldname="name")
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ class Chapter(Document):
|
|||||||
def get_lessons(self):
|
def get_lessons(self):
|
||||||
rows = frappe.db.get_all("Lesson",
|
rows = frappe.db.get_all("Lesson",
|
||||||
filters={"chapter": self.name},
|
filters={"chapter": self.name},
|
||||||
fields='*',
|
fields='name',
|
||||||
order_by="index_")
|
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]
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
"hints",
|
"hints",
|
||||||
"tests",
|
"tests",
|
||||||
"image",
|
"image",
|
||||||
"lesson"
|
"lesson",
|
||||||
|
"index_",
|
||||||
|
"index_label"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -27,6 +29,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "course",
|
"fieldname": "course",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Course",
|
"label": "Course",
|
||||||
"options": "LMS Course"
|
"options": "LMS Course"
|
||||||
},
|
},
|
||||||
@@ -73,13 +76,27 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "lesson",
|
"fieldname": "lesson",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Lesson",
|
"label": "Lesson",
|
||||||
"options": "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,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-20 13:23:12.340928",
|
"modified": "2021-06-01 05:22:15.656013",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Exercise",
|
"name": "Exercise",
|
||||||
@@ -99,8 +116,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"search_fields": "title",
|
"search_fields": "title",
|
||||||
"sort_field": "modified",
|
"sort_field": "index_label",
|
||||||
"sort_order": "DESC",
|
"sort_order": "ASC",
|
||||||
"title_field": "title",
|
"title_field": "title",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,9 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from ..lms_sketch.livecode import livecode_to_svg
|
# from ..lms_sketch.livecode import livecode_to_svg
|
||||||
|
|
||||||
class Exercise(Document):
|
class Exercise(Document):
|
||||||
def before_save(self):
|
|
||||||
self.image = livecode_to_svg(None, self.answer)
|
|
||||||
|
|
||||||
def get_user_submission(self):
|
def get_user_submission(self):
|
||||||
"""Returns the latest submission for this user.
|
"""Returns the latest submission for this user.
|
||||||
"""
|
"""
|
||||||
@@ -25,7 +22,6 @@ class Exercise(Document):
|
|||||||
order_by="creation desc",
|
order_by="creation desc",
|
||||||
page_length=1)
|
page_length=1)
|
||||||
|
|
||||||
print("get_user_submission", result)
|
|
||||||
if result:
|
if result:
|
||||||
return result[0]
|
return result[0]
|
||||||
|
|
||||||
@@ -43,8 +39,6 @@ class Exercise(Document):
|
|||||||
course = frappe.get_doc("LMS Course", self.course)
|
course = frappe.get_doc("LMS Course", self.course)
|
||||||
batch = course.get_student_batch(user)
|
batch = course.get_student_batch(user)
|
||||||
|
|
||||||
image = livecode_to_svg(None, code)
|
|
||||||
|
|
||||||
doc = frappe.get_doc(
|
doc = frappe.get_doc(
|
||||||
doctype="Exercise Submission",
|
doctype="Exercise Submission",
|
||||||
exercise=self.name,
|
exercise=self.name,
|
||||||
@@ -52,7 +46,6 @@ class Exercise(Document):
|
|||||||
course=self.course,
|
course=self.course,
|
||||||
lesson=self.lesson,
|
lesson=self.lesson,
|
||||||
batch=batch and batch.name,
|
batch=batch and batch.name,
|
||||||
image=image,
|
|
||||||
solution=code)
|
solution=code)
|
||||||
doc.insert(ignore_permissions=True)
|
doc.insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ def create_invite_request(invite_email):
|
|||||||
|
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
"doctype": "Invite Request",
|
"doctype": "Invite Request",
|
||||||
"invite_email": invite_email
|
"invite_email": invite_email,
|
||||||
|
"status": "Approved"
|
||||||
}).save(ignore_permissions=True)
|
}).save(ignore_permissions=True)
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class TestInviteRequest(unittest.TestCase):
|
|||||||
filters={"invite_email": "test_invite@example.com"},
|
filters={"invite_email": "test_invite@example.com"},
|
||||||
fieldname=["invite_email", "status", "signup_email"],
|
fieldname=["invite_email", "status", "signup_email"],
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
self.assertEqual(invite.status, "Pending")
|
self.assertEqual(invite.status, "Approved")
|
||||||
self.assertEqual(invite.signup_email, None)
|
self.assertEqual(invite.signup_email, None)
|
||||||
|
|
||||||
def test_create_invite_request_update(self):
|
def test_create_invite_request_update(self):
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"chapter",
|
"chapter",
|
||||||
"lesson_type",
|
"include_in_preview",
|
||||||
|
"column_break_4",
|
||||||
"title",
|
"title",
|
||||||
"index_",
|
"index_",
|
||||||
"body",
|
"index_label",
|
||||||
"sections"
|
"section_break_6",
|
||||||
|
"body"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -21,14 +23,6 @@
|
|||||||
"label": "Chapter",
|
"label": "Chapter",
|
||||||
"options": "Chapter"
|
"options": "Chapter"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"default": "Video",
|
|
||||||
"fieldname": "lesson_type",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Lesson Type",
|
|
||||||
"options": "Video\nText\nQuiz"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "title",
|
"fieldname": "title",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
@@ -39,6 +33,7 @@
|
|||||||
"default": "1",
|
"default": "1",
|
||||||
"fieldname": "index_",
|
"fieldname": "index_",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Index"
|
"label": "Index"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -47,15 +42,29 @@
|
|||||||
"label": "Body"
|
"label": "Body"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "sections",
|
"fieldname": "index_label",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Data",
|
||||||
"label": "Sections",
|
"label": "Index Label",
|
||||||
"options": "LMS Section"
|
"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,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-13 20:03:51.510605",
|
"modified": "2021-06-23 17:59:52.946515",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Lesson",
|
"name": "Lesson",
|
||||||
|
|||||||
@@ -5,44 +5,54 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from ...section_parser import SectionParser
|
from ...md import markdown_to_html, find_macros
|
||||||
|
|
||||||
class Lesson(Document):
|
class Lesson(Document):
|
||||||
def before_save(self):
|
def before_save(self):
|
||||||
sections = SectionParser().parse(self.body or "")
|
dynamic_documents = ["Exercise", "Quiz"]
|
||||||
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
|
for section in dynamic_documents:
|
||||||
for s in self.sections:
|
self.update_lesson_name_in_document(section)
|
||||||
if s.type == "exercise":
|
|
||||||
e = s.get_exercise()
|
def update_lesson_name_in_document(self, section):
|
||||||
|
doctype_map= {
|
||||||
|
"Exercise": "Exercise",
|
||||||
|
"Quiz": "LMS Quiz"
|
||||||
|
}
|
||||||
|
macros = find_macros(self.body)
|
||||||
|
documents = [value for name, value in macros if name == section]
|
||||||
|
index = 1
|
||||||
|
for name in documents:
|
||||||
|
e = frappe.get_doc(doctype_map[section], name)
|
||||||
e.lesson = self.name
|
e.lesson = self.name
|
||||||
|
e.index_ = index
|
||||||
e.save()
|
e.save()
|
||||||
|
index += 1
|
||||||
|
self.update_orphan_documents(doctype_map[section], documents)
|
||||||
|
|
||||||
def get_sections(self):
|
def update_orphan_documents(self, doctype, documents):
|
||||||
return sorted(self.get('sections'), key=lambda s: s.index)
|
"""Updates the documents that were previously part of this lesson,
|
||||||
|
but not any more.
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
|
linked_documents = {row['name'] for row in frappe.get_all(doctype, {"lesson": self.name})}
|
||||||
|
active_documents = set(documents)
|
||||||
|
orphan_documents = linked_documents - active_documents
|
||||||
|
for name in orphan_documents:
|
||||||
|
ex = frappe.get_doc(doctype, 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):
|
def get_exercises(self):
|
||||||
"""Returns the number for the prev lesson.
|
if not self.body:
|
||||||
|
return []
|
||||||
|
|
||||||
The return value would be like 1.2, 2.1 etc.
|
macros = find_macros(self.body)
|
||||||
It will be None if there is no next lesson.
|
exercises = [value for name, value in macros if name == "Exercise"]
|
||||||
"""
|
return [frappe.get_doc("Exercise", name) for name in exercises]
|
||||||
|
|
||||||
def get_progress(self):
|
def get_progress(self):
|
||||||
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
||||||
@@ -53,11 +63,11 @@ class Lesson(Document):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def save_progress(lesson, batch):
|
def save_progress(lesson, course):
|
||||||
if not frappe.db.exists("LMS Batch Membership",
|
if not frappe.db.exists("LMS Batch Membership",
|
||||||
{
|
{
|
||||||
"member": frappe.session.user,
|
"member": frappe.session.user,
|
||||||
"batch": batch
|
"course": course
|
||||||
}):
|
}):
|
||||||
return
|
return
|
||||||
if frappe.db.exists("LMS Course Progress",
|
if frappe.db.exists("LMS Course Progress",
|
||||||
@@ -68,11 +78,7 @@ def save_progress(lesson, batch):
|
|||||||
return
|
return
|
||||||
|
|
||||||
lesson_details = frappe.get_doc("Lesson", lesson)
|
lesson_details = frappe.get_doc("Lesson", lesson)
|
||||||
dynamic_content = frappe.db.count("LMS Section",
|
dynamic_content = find_macros(lesson_details.body)
|
||||||
filters={
|
|
||||||
"type": ["not in", ["example", "text"]],
|
|
||||||
"parent": lesson_details.name
|
|
||||||
})
|
|
||||||
|
|
||||||
status = "Complete"
|
status = "Complete"
|
||||||
if dynamic_content:
|
if dynamic_content:
|
||||||
@@ -91,17 +97,33 @@ def update_progress(lesson):
|
|||||||
if frappe.db.exists("LMS Course Progress", {"lesson": lesson, "owner": user}):
|
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 = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
|
||||||
course_progress.status = "Complete"
|
course_progress.status = "Complete"
|
||||||
course_progress.save()
|
course_progress.save(ignore_permissions=True)
|
||||||
|
|
||||||
def all_dynamic_content_submitted(lesson, user):
|
def all_dynamic_content_submitted(lesson, user):
|
||||||
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, ["name"], pluck="name")
|
all_exercises_submitted = check_all_exercise_submission(lesson, user)
|
||||||
all_exercises_submitted = False
|
all_quiz_submitted = check_all_quiz_submitted(lesson, user)
|
||||||
print(exercise_names)
|
return all_exercises_submitted and all_quiz_submitted
|
||||||
|
|
||||||
|
def check_all_exercise_submission(lesson, user):
|
||||||
|
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, pluck="name", ignore_permissions=True)
|
||||||
|
if not len(exercise_names):
|
||||||
|
return True
|
||||||
query = {
|
query = {
|
||||||
"exercise": ["in", exercise_names],
|
"exercise": ["in", exercise_names],
|
||||||
"owner": user
|
"owner": user
|
||||||
}
|
}
|
||||||
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
|
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
|
||||||
all_exercises_submitted = True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
return all_exercises_submitted
|
def check_all_quiz_submitted(lesson, user):
|
||||||
|
quizzes = frappe.get_list("LMS Quiz", {"lesson": lesson}, pluck="name", ignore_permissions=True)
|
||||||
|
if not len(quizzes):
|
||||||
|
return True
|
||||||
|
query = {
|
||||||
|
"quiz": ["in", quizzes],
|
||||||
|
"owner": user
|
||||||
|
}
|
||||||
|
if frappe.db.count("LMS Quiz Submission", query) == len(quizzes):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|||||||
@@ -33,8 +33,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "title",
|
"fieldname": "title",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Title",
|
"label": "Title"
|
||||||
"unique": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
@@ -120,7 +119,7 @@
|
|||||||
"link_fieldname": "batch"
|
"link_fieldname": "batch"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-26 16:43:57.399747",
|
"modified": "2021-06-16 10:51:05.403726",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Batch",
|
"name": "LMS Batch",
|
||||||
|
|||||||
@@ -19,15 +19,7 @@ class LMSBatch(Document):
|
|||||||
frappe.throw(_("You are not a mentor of the course {0}").format(course.title))
|
frappe.throw(_("You are not a mentor of the course {0}").format(course.title))
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
create_membership(batch=self.name, member_type="Mentor")
|
create_membership(batch=self.name, course=self.course, member_type="Mentor")
|
||||||
|
|
||||||
def get_mentors(self):
|
|
||||||
memberships = frappe.get_all(
|
|
||||||
"LMS Batch Membership",
|
|
||||||
{"batch": self.name, "member_type": "Mentor"},
|
|
||||||
["member"])
|
|
||||||
member_names = [m['member'] for m in memberships]
|
|
||||||
return find_all("User", name=["IN", member_names])
|
|
||||||
|
|
||||||
def is_member(self, email, member_type=None):
|
def is_member(self, email, member_type=None):
|
||||||
"""Checks if a person is part of a batch.
|
"""Checks if a person is part of a batch.
|
||||||
@@ -43,16 +35,6 @@ class LMSBatch(Document):
|
|||||||
filters['member_type'] = member_type
|
filters['member_type'] = member_type
|
||||||
return frappe.db.exists("LMS Batch Membership", filters)
|
return frappe.db.exists("LMS Batch Membership", filters)
|
||||||
|
|
||||||
def get_students(self):
|
|
||||||
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
|
|
||||||
"""
|
|
||||||
memberships = frappe.get_all(
|
|
||||||
"LMS Batch Membership",
|
|
||||||
{"batch": self.name, "member_type": "Student"},
|
|
||||||
["member"])
|
|
||||||
member_names = [m['member'] for m in memberships]
|
|
||||||
return find_all("User", name=["IN", member_names])
|
|
||||||
|
|
||||||
def get_messages(self):
|
def get_messages(self):
|
||||||
messages = frappe.get_all("LMS Message", {"batch": self.name}, ["*"], order_by="creation")
|
messages = frappe.get_all("LMS Message", {"batch": self.name}, ["*"], order_by="creation")
|
||||||
for message in messages:
|
for message in messages:
|
||||||
@@ -80,11 +62,6 @@ class LMSBatch(Document):
|
|||||||
membership = self.get_membership(user)
|
membership = self.get_membership(user)
|
||||||
return membership and membership.current_lesson
|
return membership and membership.current_lesson
|
||||||
|
|
||||||
def get_learn_url(self, lesson_number):
|
|
||||||
if not lesson_number:
|
|
||||||
return
|
|
||||||
return f"/courses/{self.course}/{self.name}/learn/{lesson_number}"
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def save_message(message, batch):
|
def save_message(message, batch):
|
||||||
doc = frappe.get_doc({
|
doc = frappe.get_doc({
|
||||||
|
|||||||
@@ -84,7 +84,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-24 12:40:57.125694",
|
"modified": "2021-06-21 12:10:28.808803",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Batch Membership",
|
"name": "LMS Batch Membership",
|
||||||
|
|||||||
@@ -14,42 +14,65 @@ class LMSBatchMembership(Document):
|
|||||||
self.validate_membership_in_different_batch_same_course()
|
self.validate_membership_in_different_batch_same_course()
|
||||||
|
|
||||||
def validate_membership_in_same_batch(self):
|
def validate_membership_in_same_batch(self):
|
||||||
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
|
||||||
filters={
|
filters={
|
||||||
"member": self.member,
|
"member": self.member,
|
||||||
"batch": self.batch,
|
"course": self.course,
|
||||||
"name": ["!=", self.name]
|
"name": ["!=", self.name]
|
||||||
},
|
}
|
||||||
|
if self.batch:
|
||||||
|
filters["batch"] = self.batch
|
||||||
|
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
||||||
|
filters,
|
||||||
fieldname=["member_type","member"],
|
fieldname=["member_type","member"],
|
||||||
as_dict=1)
|
as_dict=1)
|
||||||
|
|
||||||
if previous_membership:
|
if previous_membership:
|
||||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||||
frappe.throw(_("{0} is already a {1} of {2}").format(member_name, previous_membership.member_type, self.batch))
|
course_title = frappe.db.get_value("LMS Course", self.course, "title")
|
||||||
|
frappe.throw(_("{0} is already a {1} of the course {2}").format(member_name, previous_membership.member_type, course_title))
|
||||||
|
|
||||||
def validate_membership_in_different_batch_same_course(self):
|
def validate_membership_in_different_batch_same_course(self):
|
||||||
|
"""Ensures that a studnet is only part of one batch.
|
||||||
|
"""
|
||||||
|
# nothing to worry if the member is not a student
|
||||||
|
if self.member_type != "Student":
|
||||||
|
return
|
||||||
|
|
||||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||||
previous_membership = frappe.get_all("LMS Batch Membership",
|
memberships = frappe.get_all(
|
||||||
|
"LMS Batch Membership",
|
||||||
filters={
|
filters={
|
||||||
"member": self.member,
|
"member": self.member,
|
||||||
"name": ["!=", self.name]
|
"name": ["!=", self.name],
|
||||||
|
"member_type": "Student",
|
||||||
|
"course": self.course
|
||||||
},
|
},
|
||||||
fields=["batch", "member_type", "name"]
|
fields=["batch", "member_type", "name"]
|
||||||
)
|
)
|
||||||
|
|
||||||
for membership in previous_membership:
|
if memberships:
|
||||||
batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course")
|
membership = memberships[0]
|
||||||
if batch_course == course and (membership.member_type == "Student" or self.member_type == "Student"):
|
|
||||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||||
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
|
frappe.throw(_("{0} is already a Student of {1} course through {2} batch").format(member_name, course, membership.batch))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_membership(batch, member=None, member_type="Student", role="Member"):
|
def create_membership(course, batch=None, member=None, member_type="Student", role="Member"):
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
"doctype": "LMS Batch Membership",
|
"doctype": "LMS Batch Membership",
|
||||||
"batch": batch,
|
"batch": batch,
|
||||||
|
"course": course,
|
||||||
"role": role,
|
"role": role,
|
||||||
"member_type": member_type,
|
"member_type": member_type,
|
||||||
"member": member or frappe.session.user
|
"member": member or frappe.session.user
|
||||||
}).save(ignore_permissions=True)
|
}).save(ignore_permissions=True)
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def update_current_membership(batch, course, member):
|
||||||
|
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)
|
||||||
|
|||||||
@@ -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_guest_to_view": 1,
|
||||||
"allow_rename": 1,
|
"allow_rename": 1,
|
||||||
"creation": "2021-03-01 16:49:33.622422",
|
"creation": "2021-03-01 16:49:33.622422",
|
||||||
@@ -9,6 +22,7 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"title",
|
"title",
|
||||||
"is_published",
|
"is_published",
|
||||||
|
"disable_self_learning",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"short_code",
|
"short_code",
|
||||||
"video_link",
|
"video_link",
|
||||||
@@ -60,6 +74,12 @@
|
|||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Short Introduction",
|
"label": "Short Introduction",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "disable_self_learning",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Disable Self Learning"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
@@ -86,7 +106,7 @@
|
|||||||
"link_fieldname": "course"
|
"link_fieldname": "course"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-23 18:14:32.602647",
|
"modified": "2021-06-21 11:34:04.552376",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Course",
|
"name": "LMS Course",
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
import json
|
||||||
from ...utils import slugify
|
from ...utils import slugify
|
||||||
from community.query import find, find_all
|
from community.query import find, find_all
|
||||||
|
from frappe.utils import flt
|
||||||
|
|
||||||
class LMSCourse(Document):
|
class LMSCourse(Document):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -80,8 +82,8 @@ class LMSCourse(Document):
|
|||||||
"""
|
"""
|
||||||
if not email:
|
if not email:
|
||||||
return False
|
return False
|
||||||
return frappe.db.exists({
|
return frappe.db.count("LMS Course Mentor Mapping",
|
||||||
"doctype": "LMS Course Mentor Mapping",
|
{
|
||||||
"course": self.name,
|
"course": self.name,
|
||||||
"mentor": email
|
"mentor": email
|
||||||
})
|
})
|
||||||
@@ -111,7 +113,7 @@ class LMSCourse(Document):
|
|||||||
"""Returns all chapters of this course.
|
"""Returns all chapters of this course.
|
||||||
"""
|
"""
|
||||||
# TODO: chapters should have a way to specify the order
|
# 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):
|
def get_batch(self, batch_name):
|
||||||
return find("LMS Batch", name=batch_name, course=self.name)
|
return find("LMS Batch", name=batch_name, course=self.name)
|
||||||
@@ -157,6 +159,88 @@ class LMSCourse(Document):
|
|||||||
chapter = frappe.get_doc("Chapter", lesson.chapter)
|
chapter = frappe.get_doc("Chapter", lesson.chapter)
|
||||||
return f"{chapter.index_}.{lesson.index_}"
|
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_membership(self, member, batch=None):
|
||||||
|
filters = {
|
||||||
|
"member": member,
|
||||||
|
"course": self.name
|
||||||
|
}
|
||||||
|
if batch:
|
||||||
|
filters["batch"] = batch
|
||||||
|
membership = frappe.db.get_value("LMS Batch Membership", filters, ["name","batch", "current_lesson"], as_dict=True)
|
||||||
|
if membership and membership.batch:
|
||||||
|
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
|
||||||
|
return membership
|
||||||
|
|
||||||
|
def get_all_memberships(self, member):
|
||||||
|
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch"])
|
||||||
|
for membership in all_memberships:
|
||||||
|
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
|
||||||
|
return all_memberships
|
||||||
|
|
||||||
|
def get_mentors(self, batch=None):
|
||||||
|
filters = {
|
||||||
|
"course": self.name,
|
||||||
|
"member_type": "Mentor"
|
||||||
|
}
|
||||||
|
if batch:
|
||||||
|
filters["batch"] = batch
|
||||||
|
|
||||||
|
memberships = frappe.get_all(
|
||||||
|
"LMS Batch Membership",
|
||||||
|
filters,
|
||||||
|
["member"])
|
||||||
|
member_names = [m['member'] for m in memberships]
|
||||||
|
return find_all("User", name=["IN", member_names])
|
||||||
|
|
||||||
|
def get_students(self, batch=None):
|
||||||
|
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
|
||||||
|
"""
|
||||||
|
filters = {
|
||||||
|
"course": self.name,
|
||||||
|
"member_type": "Student"
|
||||||
|
}
|
||||||
|
if batch:
|
||||||
|
filters["batch"] = batch
|
||||||
|
memberships = frappe.get_all(
|
||||||
|
"LMS Batch Membership",
|
||||||
|
filters,
|
||||||
|
["member"])
|
||||||
|
member_names = [m['member'] for m in memberships]
|
||||||
|
return find_all("User", name=["IN", member_names])
|
||||||
|
|
||||||
def get_outline(self):
|
def get_outline(self):
|
||||||
return CourseOutline(self)
|
return CourseOutline(self)
|
||||||
|
|
||||||
@@ -167,6 +251,7 @@ class CourseOutline:
|
|||||||
self.lessons = self.get_lessons()
|
self.lessons = self.get_lessons()
|
||||||
|
|
||||||
def get_next(self, current):
|
def get_next(self, current):
|
||||||
|
current = flt(current)
|
||||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||||
try:
|
try:
|
||||||
index = numbers.index(current)
|
index = numbers.index(current)
|
||||||
@@ -175,6 +260,7 @@ class CourseOutline:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_prev(self, current):
|
def get_prev(self, current):
|
||||||
|
current = flt(current)
|
||||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||||
try:
|
try:
|
||||||
index = numbers.index(current)
|
index = numbers.index(current)
|
||||||
@@ -187,7 +273,8 @@ class CourseOutline:
|
|||||||
def get_chapters(self):
|
def get_chapters(self):
|
||||||
return frappe.db.get_all("Chapter",
|
return frappe.db.get_all("Chapter",
|
||||||
filters={"course": self.course.name},
|
filters={"course": self.course.name},
|
||||||
fields=["name", "title", "index_"])
|
fields=["name", "title", "index_"],
|
||||||
|
order_by="index_")
|
||||||
|
|
||||||
def get_lessons(self):
|
def get_lessons(self):
|
||||||
chapters = [c['name'] for c in self.chapters]
|
chapters = [c['name'] for c in self.chapters]
|
||||||
@@ -197,5 +284,19 @@ class CourseOutline:
|
|||||||
|
|
||||||
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
|
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
|
||||||
for lesson in lessons:
|
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
|
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.")
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class TestLMSCourse(unittest.TestCase):
|
|||||||
course = self.new_course("Test Course")
|
course = self.new_course("Test Course")
|
||||||
assert course.title == "Test Course"
|
assert course.title == "Test Course"
|
||||||
assert course.name == "test-course"
|
assert course.name == "test-course"
|
||||||
assert course.get_mentors() == []
|
|
||||||
|
|
||||||
def test_find_all(self):
|
def test_find_all(self):
|
||||||
courses = LMSCourse.find_all()
|
courses = LMSCourse.find_all()
|
||||||
|
|||||||
36
community/lms/doctype/lms_option/lms_option.json
Normal file
36
community/lms/doctype/lms_option/lms_option.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-06-07 10:46:10.402684",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"option",
|
||||||
|
"is_correct"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "option",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Option"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "is_correct",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Correct"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"istable": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-06-07 10:48:45.290227",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS Option",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [],
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (c) 2021, FOSS United and contributors
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
# import frappe
|
# import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class CodeRevision(Document):
|
class LMSOption(Document):
|
||||||
pass
|
pass
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) 2021, FOSS United and contributors
|
// Copyright (c) 2021, FOSS United and contributors
|
||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Code Revision', {
|
frappe.ui.form.on('LMS Quiz', {
|
||||||
// refresh: function(frm) {
|
// refresh: function(frm) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"creation": "2021-04-07 00:26:28.806520",
|
"autoname": "field:title",
|
||||||
|
"creation": "2021-06-07 10:50:17.893625",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"section",
|
"title",
|
||||||
"code",
|
"questions",
|
||||||
"author"
|
"lesson"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldname": "section",
|
"fieldname": "title",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"label": "Title",
|
||||||
"label": "Section",
|
"unique": 1
|
||||||
"options": "LMS Section"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "code",
|
"fieldname": "questions",
|
||||||
"fieldtype": "Code",
|
"fieldtype": "Table",
|
||||||
"label": "Code"
|
"label": "Questions",
|
||||||
|
"options": "LMS Quiz Question"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "author",
|
"fieldname": "lesson",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"label": "Lesson",
|
||||||
"label": "Author",
|
"options": "Lesson"
|
||||||
"options": "User"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-04-14 11:26:19.628317",
|
"modified": "2021-06-23 17:58:57.642873",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Code Revision",
|
"name": "LMS Quiz",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -53,6 +53,5 @@
|
|||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"title_field": "section",
|
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
79
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
79
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
from community.lms.doctype.lesson.lesson import update_progress
|
||||||
|
import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
import json
|
||||||
|
from frappe import _
|
||||||
|
from ..lesson.lesson import update_progress
|
||||||
|
|
||||||
|
class LMSQuiz(Document):
|
||||||
|
def validate(self):
|
||||||
|
self.validate_correct_answers()
|
||||||
|
|
||||||
|
def validate_correct_answers(self):
|
||||||
|
for question in self.questions:
|
||||||
|
correct_options = self.get_correct_options(question)
|
||||||
|
|
||||||
|
if len(correct_options) > 1:
|
||||||
|
question.multiple = 1
|
||||||
|
|
||||||
|
if not len(correct_options):
|
||||||
|
frappe.throw(_("At least one answer must be correct for this question: {0}").format(frappe.bold(question.question)))
|
||||||
|
|
||||||
|
def get_correct_options(self, question):
|
||||||
|
correct_option_fields = ["is_correct_1", "is_correct_2", "is_correct_3", "is_correct_4"]
|
||||||
|
return list(filter(lambda x: question.get(x) == 1, correct_option_fields))
|
||||||
|
|
||||||
|
def get_last_submission_details(self):
|
||||||
|
"""Returns the latest submission for this user.
|
||||||
|
"""
|
||||||
|
user = frappe.session.user
|
||||||
|
if not user or user == "Guest":
|
||||||
|
return
|
||||||
|
|
||||||
|
result = frappe.get_all('LMS Quiz Submission',
|
||||||
|
fields="*",
|
||||||
|
filters={
|
||||||
|
"owner": user,
|
||||||
|
"quiz": self.name
|
||||||
|
},
|
||||||
|
order_by="creation desc",
|
||||||
|
page_length=1)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def submit(quiz, result):
|
||||||
|
score = 0
|
||||||
|
answer_map = {
|
||||||
|
"is_correct_1": "option_1",
|
||||||
|
"is_correct_2": "option_2",
|
||||||
|
"is_correct_3": "option_3",
|
||||||
|
"is_correct_4": "option_4"
|
||||||
|
}
|
||||||
|
result = json.loads(result)
|
||||||
|
quiz_details = frappe.get_doc("LMS Quiz", quiz)
|
||||||
|
|
||||||
|
for response in result:
|
||||||
|
match = list(filter(lambda x: x.question == response.get("question"), quiz_details.questions))[0]
|
||||||
|
correct_options = quiz_details.get_correct_options(match)
|
||||||
|
correct_answers = [ match.get(answer_map[option]) for option in correct_options ]
|
||||||
|
|
||||||
|
if response.get("answer") == correct_answers:
|
||||||
|
response["result"] = "Right"
|
||||||
|
score += 1
|
||||||
|
else:
|
||||||
|
response["result"] = "Wrong"
|
||||||
|
response["answer"] = ("").join([ ans if idx == len(response.get("answer")) -1 else ans + ", " for idx, ans in enumerate(response.get("answer")) ])
|
||||||
|
|
||||||
|
frappe.get_doc({
|
||||||
|
"doctype": "LMS Quiz Submission",
|
||||||
|
"quiz": quiz,
|
||||||
|
"result": result,
|
||||||
|
"score": score
|
||||||
|
}).save(ignore_permissions=True)
|
||||||
|
update_progress(quiz_details.lesson)
|
||||||
|
return score
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (c) 2021, FOSS United and Contributors
|
# Copyright (c) 2021, FOSS United and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestCodeRevision(unittest.TestCase):
|
class TestLMSQuiz(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
118
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
118
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-06-07 10:48:57.994714",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"question",
|
||||||
|
"options_section",
|
||||||
|
"option_1",
|
||||||
|
"is_correct_1",
|
||||||
|
"section_break_5",
|
||||||
|
"option_2",
|
||||||
|
"is_correct_2",
|
||||||
|
"column_break_4",
|
||||||
|
"option_3",
|
||||||
|
"is_correct_3",
|
||||||
|
"section_break_11",
|
||||||
|
"option_4",
|
||||||
|
"is_correct_4",
|
||||||
|
"multiple"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "question",
|
||||||
|
"fieldtype": "Text",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Question",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "option_1",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Option 1",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "option_2",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Option 2",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "option_3",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Option 3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "option_4",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Option 4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "option_1",
|
||||||
|
"fieldname": "is_correct_1",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Correct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "option_2",
|
||||||
|
"fieldname": "is_correct_2",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Correct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "option_3",
|
||||||
|
"fieldname": "is_correct_3",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Correct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "option_4",
|
||||||
|
"fieldname": "is_correct_4",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Correct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "multiple",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"hidden": 1,
|
||||||
|
"label": "Multiple Correct Answers",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "options_section",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_4",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_5",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_11",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"istable": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-06-22 16:54:13.133859",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS Quiz Question",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [],
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class LMSQuizQuestion(Document):
|
||||||
|
pass
|
||||||
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-06-07 14:19:23.683323",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"question",
|
||||||
|
"answer",
|
||||||
|
"result"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "question",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Question"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "result",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Result",
|
||||||
|
"options": "Right\nWrong"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "answer",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Users Response"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"istable": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-06-22 18:32:28.813159",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS Quiz Result",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [],
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class LMSQuizResult(Document):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (c) 2021, FOSS United and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.ui.form.on('LMS Quiz Submission', {
|
||||||
|
// refresh: function(frm) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
});
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-06-07 14:19:54.958989",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"quiz",
|
||||||
|
"result",
|
||||||
|
"score"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "quiz",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Quiz",
|
||||||
|
"options": "LMS Quiz"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "result",
|
||||||
|
"fieldtype": "Table",
|
||||||
|
"label": "Result",
|
||||||
|
"options": "LMS Quiz Result"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "score",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Score"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-06-07 14:19:54.958989",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS Quiz Submission",
|
||||||
|
"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
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class LMSQuizSubmission(Document):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and Contributors
|
||||||
|
# See license.txt
|
||||||
|
|
||||||
|
# import frappe
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestLMSQuizSubmission(unittest.TestCase):
|
||||||
|
pass
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,10 @@ class LMSSection(Document):
|
|||||||
if self.type == "exercise":
|
if self.type == "exercise":
|
||||||
return frappe.get_doc("Exercise", self.id)
|
return frappe.get_doc("Exercise", self.id)
|
||||||
|
|
||||||
|
def get_quiz(self):
|
||||||
|
if self.type == "quiz":
|
||||||
|
return frappe.get_doc("LMS Quiz", self.id)
|
||||||
|
|
||||||
def get_latest_code_for_user(self):
|
def get_latest_code_for_user(self):
|
||||||
"""Returns the latest code for the logged in user.
|
"""Returns the latest code for the logged in user.
|
||||||
"""
|
"""
|
||||||
|
|||||||
109
community/lms/md.py
Normal file
109
community/lms/md.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
"""
|
||||||
|
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')
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
if not text:
|
||||||
|
return []
|
||||||
|
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_course.lms_course import LMSCourse as Course
|
||||||
from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch
|
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,
|
"apply_document_permissions": 0,
|
||||||
"button_label": "Save",
|
"button_label": "Save",
|
||||||
"creation": "2021-04-20 11:37:49.135114",
|
"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",
|
"doc_type": "LMS Batch",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Web Form",
|
"doctype": "Web Form",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"is_standard": 1,
|
"is_standard": 1,
|
||||||
"login_required": 1,
|
"login_required": 1,
|
||||||
"max_attachment_size": 0,
|
"max_attachment_size": 0,
|
||||||
"modified": "2021-06-02 15:52:06.383260",
|
"modified": "2021-06-15 18:49:50.530001",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "add-a-new-batch",
|
"name": "add-a-new-batch",
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
{
|
{
|
||||||
"allow_read_on_all_link_options": 0,
|
"allow_read_on_all_link_options": 0,
|
||||||
"fieldname": "course",
|
"fieldname": "course",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Course",
|
"label": "Course",
|
||||||
"max_length": 0,
|
"max_length": 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
|
|
||||||
@@ -1,34 +1,61 @@
|
|||||||
<div class="mt-5">
|
<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 %}
|
<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(frappe.session.user) %}
|
||||||
|
{% if membership and membership.batch and all_memberships | length > 1 %}
|
||||||
|
<a class="pull-right dropdown-item border rounded" style="width: 10rem;" href="#" id="navbarDropdown" role="button"
|
||||||
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
{{ membership.batch_title }}
|
||||||
|
</a>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
||||||
|
{% for data in all_memberships %}
|
||||||
|
{% if data.batch != membership.batch %}
|
||||||
|
<a class="dropdown-item switch-batch"
|
||||||
|
href="/courses/{{ course.name }}/home?batch={{ data.batch }}">{{ data.batch_title }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if not membership %}
|
||||||
|
{% set display_class = "hide" %}
|
||||||
|
{% else %}
|
||||||
|
{% set display_class = "" %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="nav nav-tabs mt-4">
|
<ul class="nav nav-tabs mt-4">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="home" href="/courses/{{course.name}}/{{batch.name}}/home">Home</a>
|
<a class="nav-link" id="home" href="/courses/{{course.name}}/home{{ course.query_parameter }}">Home</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="learn" href="/courses/{{course.name}}/{{batch.name}}/learn">Learn</a>
|
{% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and membership.current_lesson
|
||||||
|
else '1.1' %}
|
||||||
|
<a class="nav-link" id="learn"
|
||||||
|
href="{{ course.get_learn_url(lesson_index) }}{{ course.query_parameter }}">Lessons</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- <li class="nav-item">
|
<!-- <li class="nav-item">
|
||||||
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/{{batch.name}}/schedule">Schedule</a>
|
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/schedule">Schedule</a>
|
||||||
</li> -->
|
</li> -->
|
||||||
<li class="nav-item">
|
<li class="nav-item {{ display_class }}">
|
||||||
<a class="nav-link" id="members" href="/courses/{{course.name}}/{{batch.name}}/members">Members</a>
|
<a class="nav-link" id="members" href="/courses/{{course.name}}/members{{ course.query_parameter }}">Members</a>
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/{{batch.name}}/discuss">Discussion</a>
|
|
||||||
</li>
|
</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">
|
<!-- <li class="nav-item">
|
||||||
<a class="nav-link" id="about" href="/courses/{{course.name}}/{{batch.name}}/about">About</a>
|
<a class="nav-link" id="about" href="/courses/{{course.name}}/about">About</a>
|
||||||
</li> -->
|
</li> -->
|
||||||
{% if batch.is_member(frappe.session.user, member_type="Mentor") %}
|
{% if membership and membership.batch and course.is_mentor(frappe.session.user) %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" id="progress" href="/courses/{{course.name}}/{{batch.name}}/progress">Progress</a>
|
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress{{ course.query_parameter }}">Progress</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}"]`)
|
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}{{ course.query_parameter }}"]`)
|
||||||
if (selector) {
|
if (selector) {
|
||||||
selector.classList.add('active');
|
selector.classList.add('active');
|
||||||
}
|
}
|
||||||
@@ -37,3 +64,4 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
<div class="chapter-teaser">
|
<div class="chapter-teaser">
|
||||||
<div class="teaser-body">
|
<div class="teaser-body">
|
||||||
<h3 class="chapter-title"><span class="mr-1">{{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">
|
<div class="chapter-description">
|
||||||
{{ chapter.description or "" }}
|
{{ chapter.description or "" }}
|
||||||
</div>
|
</div>
|
||||||
<div class="chapter-lessons">
|
<div class="chapter-lessons">
|
||||||
{% for lesson in chapter.get_lessons() %}
|
{% for lesson in chapter.get_lessons() %}
|
||||||
<div class="lesson-teaser">
|
<div class="lesson-teaser">
|
||||||
<a {% if show_link %} class="anchor_style" href="{{ batch.get_learn_url(course.get_lesson_index(lesson.name)) }}" {% endif %}>{{ lesson.title }}</a>
|
{% if show_link or lesson.include_in_preview %}
|
||||||
|
<a class="" href="{{ course.get_learn_url(course.get_lesson_index(lesson.name)) }}{{course.query_parameter}}"
|
||||||
|
data-course="{{ course.name }}">{{ lesson.title }}</a>
|
||||||
|
{% else %}
|
||||||
|
<div class="no-preview" title="This lesson is not available for preview">
|
||||||
|
<span style="color: #2490ef;">
|
||||||
|
{{ lesson.title }}
|
||||||
|
</span>
|
||||||
|
<i class="fa fa-lock ml-2"></i>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %}
|
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %}
|
||||||
<a class="pull-right badge p-1 {{ lesson.get_slugified_class() }}"> <img class="progress-image" src="/assets/community/images/Vector.png"> {{ lesson.get_progress() }}</a>
|
<span class="ml-5 badge p-2 {{ lesson.get_slugified_class() }}"> {{ lesson.get_progress() }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<h2>Course Outline</h2>
|
<div class="mt-5">
|
||||||
|
<h3> Course Outline </h3>
|
||||||
|
|
||||||
{% for chapter in course.get_chapters() %}
|
{% 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)}}
|
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
|
|
||||||
<div class="exercise">
|
<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>
|
<div class="exercise-description">{{frappe.utils.md_to_html(exercise.description)}}</div>
|
||||||
|
|
||||||
{% if exercise.image %}
|
{% if exercise.image %}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<h3>Instructor</h3>
|
|
||||||
<div class="instructor">
|
<div class="instructor">
|
||||||
<div class="instructor-title">{{instructor.full_name}}</div>
|
{{ widgets.Avatar(member=instructor, avatar_class="avatar-medium") }}
|
||||||
<div class="instructor-subtitle">Created {{instructor.get_course_count()}} courses</div>
|
<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>
|
</div>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<div class="batch">
|
<div class="batch">
|
||||||
<div class="batch-details">
|
<div class="batch-details">
|
||||||
<div>Session every {{batch.sessions_on}}</div>
|
<div class="">Session every {{batch.sessions_on}}</div>
|
||||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
||||||
{{frappe.utils.format_time(batch.end_time, "short")}}
|
{{frappe.utils.format_time(batch.end_time, "short")}}
|
||||||
</div>
|
</div>
|
||||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
||||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
||||||
|
|
||||||
{% for m in batch.get_mentors() %}
|
{% for m in course.get_mentors(batch.name) %}
|
||||||
<div>
|
<div>
|
||||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||||
<span class="instructor-title">{{m.full_name}}</span>
|
<span class="instructor-title">{{m.full_name}}</span>
|
||||||
@@ -18,9 +18,10 @@
|
|||||||
<div class="cta">
|
<div class="cta">
|
||||||
<div class="">
|
<div class="">
|
||||||
{% if can_manage %}
|
{% if can_manage %}
|
||||||
<a href="/courses/{{course.name}}/{{batch.name}}/home" class="btn btn-primary">Manage</a>
|
<a href="/courses/{{ course.name }}/home?batch={{ batch.name }}" class="btn btn-primary manage-batch" data-batch="{{ batch.name | urlencode }}"
|
||||||
|
data-course="{{ course.name | urlencode }}">Manage</a>
|
||||||
{% elif can_join %}
|
{% elif can_join %}
|
||||||
<button class="join-batch btn btn-primary" data-batch="{{ batch.name | urlencode }}"
|
<button class="join-batch btn btn-secondary" data-batch="{{ batch.name | urlencode }}"
|
||||||
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
89
community/plugins.py
Normal file
89
community/plugins.py
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
def quiz_renderer(quiz_name):
|
||||||
|
quiz = frappe.get_doc("LMS Quiz", quiz_name)
|
||||||
|
context = dict(quiz=quiz)
|
||||||
|
return frappe.render_template("templates/quiz.html", context)
|
||||||
|
|
||||||
|
def exercise_renderer(argument):
|
||||||
|
exercise = frappe.get_doc("Exercise", argument)
|
||||||
|
context = dict(exercise=exercise)
|
||||||
|
return frappe.render_template("templates/exercise.html", context)
|
||||||
|
|
||||||
|
def youtube_video_renderer(video_id):
|
||||||
|
return f"""
|
||||||
|
<iframe width="560" height="315"
|
||||||
|
src="https://www.youtube.com/embed/{video_id}"
|
||||||
|
title="YouTube video player"
|
||||||
|
frameborder="0"
|
||||||
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||||
|
allowfullscreen>
|
||||||
|
</iframe>
|
||||||
|
"""
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
--cta-color: var(--c4);
|
--cta-color: var(--c4);
|
||||||
--send-message: var(--c7);
|
--send-message: var(--c7);
|
||||||
--received-message: var(--c8);
|
--received-message: var(--c8);
|
||||||
|
--checkbox-size: 14px;
|
||||||
|
--control-bg: var(--gray-100);
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -82,6 +84,7 @@ body {
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
margin: 10px 0px;
|
margin: 10px 0px;
|
||||||
background: white;
|
background: white;
|
||||||
|
box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);
|
||||||
border: 1px solid #ddc;
|
border: 1px solid #ddc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,19 +159,6 @@ img.profile-photo {
|
|||||||
line-height: 51px;
|
line-height: 51px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.anchor_style {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.anchor_style:hover {
|
|
||||||
text-decoration: underline
|
|
||||||
}
|
|
||||||
|
|
||||||
section {
|
section {
|
||||||
padding: 5rem 0 5rem 0;
|
padding: 5rem 0 5rem 0;
|
||||||
}
|
}
|
||||||
@@ -239,6 +229,10 @@ section {
|
|||||||
margin-top: 30px;
|
margin-top: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
appearance: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.partiallycomplete {
|
.partiallycomplete {
|
||||||
background: #FEF4E2;
|
background: #FEF4E2;
|
||||||
color: #976417;
|
color: #976417;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ h2 {
|
|||||||
|
|
||||||
.teaser-body {
|
.teaser-body {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
box-shadow: 0px 5px 10px rgb(0 0 0 / 10%)
|
||||||
}
|
}
|
||||||
.teaser-footer {
|
.teaser-footer {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
@@ -66,6 +67,15 @@ h2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.anchor_style {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.anchor_style:hover {
|
||||||
|
text-decoration: none
|
||||||
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
padding: 60px 0px;
|
padding: 60px 0px;
|
||||||
}
|
}
|
||||||
@@ -162,7 +172,6 @@ section.lightgray {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
.instructor-title {
|
.instructor-title {
|
||||||
font-weight: bold;
|
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,3 +340,9 @@ section.lightgray {
|
|||||||
margin: 40px 0px 0px 20px;
|
margin: 40px 0px 0px 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-preview-message {
|
||||||
|
width: fit-content;
|
||||||
|
margin: 50px 0px 50px;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|||||||
10
community/templates/exercise.html
Normal file
10
community/templates/exercise.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<div class="exercise">
|
||||||
|
<h3>Exercise {{exercise.index_label}}: {{ exercise.title }}</h3>
|
||||||
|
<div class="exercise-description">{{frappe.utils.md_to_html(exercise.description)}}</div>
|
||||||
|
|
||||||
|
{% set submission = exercise.get_user_submission() %}
|
||||||
|
|
||||||
|
<pre class="exercise" id="exercise-{{exercise.name}}"
|
||||||
|
data-last-submitted="{{ submission and submission.creation or '' }}" data-name="{{ exercise.name }}"
|
||||||
|
data-image='{{ (submission and submission.image or "") | tojson }}'><code class="language-joy">{{ submission.solution if submission else exercise.code }}</code></pre>
|
||||||
|
</div>
|
||||||
30
community/templates/quiz.html
Normal file
30
community/templates/quiz.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{% set last_submission = quiz.get_last_submission_details() %}
|
||||||
|
{% if last_submission %}
|
||||||
|
<div class="mb-5 pull-right">
|
||||||
|
<div class="text-muted">Last Submitted On: {{ frappe.utils.pretty_date(last_submission.creation) }}</div>
|
||||||
|
<div class="text-muted">Last Submission Score: {{ last_submission.score }}</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<h3 id="title" class="mb-5">{{ quiz.title }}</h3>
|
||||||
|
<form id="quiz-form">
|
||||||
|
{% for question in quiz.questions %}
|
||||||
|
<div class="question mb-5" data-question="{{ question.question }}"
|
||||||
|
data-multi="{{ question.multiple_correct_answers}}">
|
||||||
|
<p> {{ loop.index }}. {{ question.question }}</p>
|
||||||
|
{% set options = [question.option_1, question.option_2, question.option_3, question.option_4] %}
|
||||||
|
{% for option in options %}
|
||||||
|
{% if option %}
|
||||||
|
<div class="checkbox mb-2">
|
||||||
|
<input {% if question.multiple %} type="checkbox" {% else %} type="radio"
|
||||||
|
name="{{ question.question | urlencode }}" {% endif %} class="option" value="{{ option | urlencode }}">
|
||||||
|
<span class="label-area">{{ option }}</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<button class="btn btn-secondary hide mb-5" id="try-again">Try Again</button>
|
||||||
|
<button class="btn btn-primary" id="submit-quiz">Submit</button>
|
||||||
|
<h4 class="success-message"></h4>
|
||||||
|
<h5 class="score text-muted"></h5>
|
||||||
|
</form>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
<div class="messages-container mt-5">
|
<div class="messages-container mt-5">
|
||||||
{{ widgets.BatchHeader(batch_name=batch.title, member_count=member_count)}}
|
{{ widgets.BatchHeader(batch_name=batch.title, member_count=member_count)}}
|
||||||
<ol class="messages">
|
<ol class="messages">
|
||||||
|
|||||||
@@ -4,3 +4,5 @@ from . import utils
|
|||||||
def get_context(context):
|
def get_context(context):
|
||||||
utils.get_common_context(context)
|
utils.get_common_context(context)
|
||||||
context.messages = context.batch.get_messages()
|
context.messages = context.batch.get_messages()
|
||||||
|
if not context.membership:
|
||||||
|
utils.redirect_to_lesson(context.course)
|
||||||
|
|||||||
@@ -8,31 +8,32 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/" + batch.name + "/join" %}
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
<div>
|
<div class="course-details mt-5">
|
||||||
<h1 class="mt-5">{{ batch.title }}</h1>
|
{{ widgets.CourseOutline(course=course, batch=batch, show_link=membership, show_progress=True) }}
|
||||||
</div>
|
|
||||||
<div class="course-details">
|
|
||||||
{{ widgets.CourseOutline(course=course, batch=batch, show_link=True, show_progress=True) }}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if batch %}
|
||||||
<div class="w-25">
|
<div class="w-25">
|
||||||
<h2>Batch Schedule</h2>
|
<h3>Batch Schedule</h3>
|
||||||
{{ widgets.RenderBatch(course=course, batch=batch) }}
|
{{ widgets.RenderBatch(course=course, batch=batch) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if batch.description %}
|
{% if batch.description %}
|
||||||
<h2>Batch Details</h2>
|
<div class="mt-5">
|
||||||
|
<h3>Batch Details</h3>
|
||||||
{{ frappe.utils.md_to_html(batch.description) }}
|
{{ frappe.utils.md_to_html(batch.description) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if course.is_mentor(frappe.session.user) %}
|
{% if course.is_mentor(frappe.session.user) %}
|
||||||
|
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/join?batch=" + batch.name %}
|
||||||
<div class="">
|
<div class="">
|
||||||
<h2> Invite Members </h2>
|
<h3> Invite Members </h3>
|
||||||
<a href="" class="anchor_style mr-5" id="invite-link" data-link="{{ invite_link }}">Get Batch Invitation
|
<a href="" class="" id="invite-link" data-link="{{ invite_link }}">Get Batch Invitation
|
||||||
Link</a>
|
Link</a>
|
||||||
<small id="copy-message" class="text-muted pull-right" style="display: none;">Copied to Clipboard.</small>
|
<small id="copy-message" class="text-muted" style="display: none;">Copied to Clipboard.</small>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@
|
|||||||
$("#copy-message").slideDown(function () {
|
$("#copy-message").slideDown(function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$("#copy-message").slideUp();
|
$("#copy-message").slideUp();
|
||||||
}, 5000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
<div class='page-card-head'>
|
<div class='page-card-head'>
|
||||||
<span class='indicator blue password-box'>Login Required</span>
|
<span class='indicator blue password-box'>Login Required</span>
|
||||||
</div>
|
</div>
|
||||||
<div class=''>Please log in to confirm to join the course {{ batch.course_title }}.</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"
|
<a type="submit" id="login" class="btn btn-primary w-100"
|
||||||
href="/login?redirect-to=/courses/{{ batch.course }}/{{ batch.name }}/join">{{_("Login")}}</a>
|
href="/login?redirect-to=/courses/{{ batch.course }}/join?batch={{ batch.name }}">{{_("Login")}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% elif already_a_member %}
|
{% elif already_a_member %}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class=''>You are already a member of the batch {{ batch.title }} for the course {{ batch.course_title }}.
|
<div class=''>You are already a member of the batch {{ batch.title }} for the course {{ batch.course_title }}.
|
||||||
</div>
|
</div>
|
||||||
<a type="submit" id="batch-home" class="btn btn-primary w-100" href="/courses/{{batch.course}}/{{batch.name}}/home">{{_("Go to Batch Home")}}</a>
|
<a type="submit" id="batch-home" class="btn btn-primary w-100" href="">{{_("Go to Batch Home")}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -38,23 +38,21 @@
|
|||||||
<div>Please provide your confirmation to be a part of the batch {{ batch.title }} for the course
|
<div>Please provide your confirmation to be a part of the batch {{ batch.title }} for the course
|
||||||
{{ batch.course_title }}.
|
{{ batch.course_title }}.
|
||||||
</div>
|
</div>
|
||||||
<a type="submit" id="confirm" class="btn btn-primary w-100" data-batch="{{ batch.name | urlencode }}"
|
<a type="submit" id="confirm" class="btn btn-primary w-100">{{_("Confirm")}}</a>
|
||||||
data-course="{{ batch.course | urlencode }}">{{_("Confirm")}}</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
var confirm_element = $("#confirm");
|
$("#confirm").click((e) => {
|
||||||
var batch = decodeURIComponent(confirm_element.attr("data-batch"));
|
|
||||||
var course = decodeURIComponent(confirm_element.attr("data-course"));
|
|
||||||
|
|
||||||
confirm_element.click((e) => {
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||||
"args": {
|
"args": {
|
||||||
"batch": batch
|
"batch": {{ batch.name }},
|
||||||
|
"course": {{ batch.course }}
|
||||||
},
|
},
|
||||||
"callback": (data) => {
|
"callback": (data) => {
|
||||||
if (data.message == "OK") {
|
if (data.message == "OK") {
|
||||||
@@ -63,7 +61,7 @@
|
|||||||
clear: true
|
clear: true
|
||||||
});
|
});
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
window.location.href = "/courses/" + course + "/" + batch + "/home";
|
window.location.href = "/courses/{{ batch.course }}/home";
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,63 +9,40 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
<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/css/lms.css">
|
||||||
<link rel="stylesheet" href="/assets/frappe/css/hljs-night-owl.css">
|
<link rel="stylesheet" href="/assets/frappe/css/hljs-night-owl.css">
|
||||||
|
|
||||||
<script src="{{ livecode_url }}/static/codemirror/lib/codemirror.js"></script>
|
{% for ext in page_extensions %}
|
||||||
<script src="{{ livecode_url }}/static/codemirror/mode/python/python.js"></script>
|
{{ ext.render_header() }}
|
||||||
<script src="{{ livecode_url }}/static/codemirror/keymap/sublime.js"></script>
|
{% endfor %}
|
||||||
|
|
||||||
<script src="{{ livecode_url }}/static/codemirror/addon/edit/matchbrackets.js"></script>
|
|
||||||
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
<div class="lesson-page">
|
<div class="lesson-page">
|
||||||
|
|
||||||
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" data-batch="{{ batch.name }}">{{ lesson.title }}</h2>
|
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-lesson="{{ lesson.name }}"
|
||||||
|
data-course="{{ course.name }}" {% if membership%} data-membership="{{membership.name}}" {% endif %}>{{ lesson.title }}</h2>
|
||||||
|
|
||||||
{% for s in lesson.get_sections() %}
|
{% if membership or lesson.include_in_preview %}
|
||||||
<div class="section section-{{ s.type }}">
|
{{ lesson.render_html() }}
|
||||||
{{ render_section(s) }}
|
{% else %}
|
||||||
|
<div class="no-preview-message">
|
||||||
|
<span>This lesson is not available for Preview. Please join the course to access this lesson.</span>
|
||||||
|
<a href="/courses/{{ course.name }}">Checkout Course Details.</a>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
|
{% if membership %}
|
||||||
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
|
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% 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>
|
|
||||||
{% 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_chap, prev_url, next_chap, next_url) %}
|
{% macro pagination(prev_chap, prev_url, next_chap, next_url) %}
|
||||||
<div class="lesson-pagination">
|
<div class="lesson-pagination">
|
||||||
{% if prev_url %}
|
{% if prev_url %}
|
||||||
@@ -84,18 +61,7 @@
|
|||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{{ LiveCodeEditorJS() }}
|
{% for ext in page_extensions %}
|
||||||
|
{{ ext.render_footer() }}
|
||||||
<script type="text/javascript">
|
{% endfor %}
|
||||||
$(function() {
|
|
||||||
var batch_name = "{{ batch.name }}";
|
|
||||||
var lesson_name = "{{ lesson.name }}";
|
|
||||||
|
|
||||||
frappe.call("community.lms.api.save_current_lesson", {
|
|
||||||
"batch_name": batch_name,
|
|
||||||
"lesson_name": lesson_name
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|||||||
@@ -1,11 +1,69 @@
|
|||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
if (!$(".title").hasClass("is_mentor")) {
|
|
||||||
|
/* Save Lesson Progress */
|
||||||
|
if ($(".title").attr("data-membership") && !$(".title").hasClass("is_mentor")) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "community.lms.doctype.lesson.lesson.save_progress",
|
method: "community.lms.doctype.lesson.lesson.save_progress",
|
||||||
args: {
|
args: {
|
||||||
lesson: $(".title").attr("data-name"),
|
lesson: $(".title").attr("data-lesson"),
|
||||||
batch: $(".title").attr("data-batch")
|
course: $(".title").attr("data-course")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save Current Lesson */
|
||||||
|
if ($(".title").attr("data-membership")) {
|
||||||
|
frappe.call("community.lms.api.save_current_lesson", {
|
||||||
|
course_name: $(".title").attr("data-course"),
|
||||||
|
lesson_name: $(".title").attr("data-lesson")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Submit Quiz */
|
||||||
|
$("#submit-quiz").click((e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log("click")
|
||||||
|
var result = [];
|
||||||
|
$('.question').each((i, element) => {
|
||||||
|
var options = $(element).find(".option");
|
||||||
|
var answers = [];
|
||||||
|
options.filter((i, op) => $(op).prop("checked")).each((i, elem) => answers.push(decodeURIComponent(elem.value)));
|
||||||
|
result.push({
|
||||||
|
"question": element.dataset.question,
|
||||||
|
"answer": answers
|
||||||
|
});
|
||||||
|
});
|
||||||
|
frappe.call({
|
||||||
|
method: "community.lms.doctype.lms_quiz.lms_quiz.submit",
|
||||||
|
args: {
|
||||||
|
quiz: $("#title").text(),
|
||||||
|
result: result
|
||||||
|
},
|
||||||
|
callback: (data) => {
|
||||||
|
$("#submit-quiz").addClass("hide");
|
||||||
|
$("#try-again").removeClass("hide");
|
||||||
|
$(":input[type='checkbox']").prop("disabled", true);
|
||||||
|
$(":input[type='radio']").prop("disabled", true);
|
||||||
|
if (data.message == result.length) {
|
||||||
|
$(".success-message").text("Congratulations, you cleared the quiz!");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(".success-message").text("Some of your answers weren't correct. You can give it another shot.");
|
||||||
|
}
|
||||||
|
$(".score").text(`Score: ${data.message}/${result.length}`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/* Try the quiz again */
|
||||||
|
$("#try-again").click((e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
$(":input[type='checkbox']").prop("disabled", false);
|
||||||
|
$(":input[type='radio']").prop("disabled", false);
|
||||||
|
$("#quiz-form").trigger("reset");
|
||||||
|
$(".success-message").text("");
|
||||||
|
$(".score").text("");
|
||||||
|
$("#submit-quiz").removeClass("hide");
|
||||||
|
$("#try-again").addClass("hide");
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
from re import I
|
from re import I
|
||||||
import frappe
|
import frappe
|
||||||
from . import utils
|
from . import utils
|
||||||
|
from frappe.utils import cstr
|
||||||
|
|
||||||
|
from community.www import batch
|
||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
utils.get_common_context(context)
|
utils.get_common_context(context)
|
||||||
@@ -10,10 +13,12 @@ def get_context(context):
|
|||||||
lesson_number = f"{chapter_index}.{lesson_index}"
|
lesson_number = f"{chapter_index}.{lesson_index}"
|
||||||
|
|
||||||
course_name = context.course.name
|
course_name = context.course.name
|
||||||
|
|
||||||
if not chapter_index or not lesson_index:
|
if not chapter_index or not lesson_index:
|
||||||
|
if context.batch:
|
||||||
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
|
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
|
||||||
frappe.local.flags.redirect_location = context.batch.get_learn_url(index_)
|
else:
|
||||||
|
index_ = "1.1"
|
||||||
|
frappe.local.flags.redirect_location = context.course.get_learn_url(index_) + context.course.query_parameter
|
||||||
raise frappe.Redirect
|
raise frappe.Redirect
|
||||||
|
|
||||||
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
|
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
|
||||||
@@ -25,16 +30,17 @@ def get_context(context):
|
|||||||
next_ = outline.get_next(lesson_number)
|
next_ = outline.get_next(lesson_number)
|
||||||
context.prev_chap = get_chapter_title(course_name, prev_)
|
context.prev_chap = get_chapter_title(course_name, prev_)
|
||||||
context.next_chap = get_chapter_title(course_name, next_)
|
context.next_chap = get_chapter_title(course_name, next_)
|
||||||
context.next_url = context.batch.get_learn_url(next_)
|
context.next_url = context.course.get_learn_url(next_) + context.course.query_parameter
|
||||||
context.prev_url = context.batch.get_learn_url(prev_)
|
context.prev_url = context.course.get_learn_url(prev_) + context.course.query_parameter
|
||||||
|
|
||||||
|
|
||||||
|
context.page_extensions = get_page_extensions()
|
||||||
|
|
||||||
def get_chapter_title(course_name, lesson_number):
|
def get_chapter_title(course_name, lesson_number):
|
||||||
if not lesson_number:
|
if not lesson_number:
|
||||||
return
|
return
|
||||||
chapter_index = lesson_number.split(".")[0]
|
lesson_split = cstr(lesson_number).split(".")
|
||||||
lesson_index = lesson_number.split(".")[1]
|
chapter_index = lesson_split[0]
|
||||||
|
lesson_index = lesson_split[1]
|
||||||
chapter_name = frappe.db.get_value("Chapter", {"course": course_name, "index_": chapter_index}, "name")
|
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")
|
return frappe.db.get_value("Lesson", {"chapter": chapter_name, "index_": lesson_index}, "title")
|
||||||
|
|
||||||
@@ -42,4 +48,8 @@ def get_lesson_index(course, batch, user):
|
|||||||
lesson = batch.get_current_lesson(user)
|
lesson = batch.get_current_lesson(user)
|
||||||
return lesson and course.get_lesson_index(lesson)
|
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
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
{{ MembersList(members)}}
|
{{ MembersList(members)}}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -19,23 +19,19 @@
|
|||||||
{% macro MembersList(members) %}
|
{% macro MembersList(members) %}
|
||||||
<div class="mt-5">
|
<div class="mt-5">
|
||||||
{% for member in members %}
|
{% for member in members %}
|
||||||
<div class="row mb-5">
|
<div class="d-flex align-items-center">
|
||||||
<div>
|
|
||||||
{{ widgets.Avatar(member=member, avatar_class="avatar-large") }}
|
{{ widgets.Avatar(member=member, avatar_class="avatar-large") }}
|
||||||
</div>
|
<div class="d-flex flex-column ml-2">
|
||||||
<div class="col">
|
<div class="d-flex">
|
||||||
<div class="row ml-1">
|
<a class="anchor_style ml-2" href="/{{member.username}}">
|
||||||
<a class="anchor_style" href="/{{member.username}}">
|
|
||||||
<h3>{{ member.full_name }}</h3>
|
<h3>{{ member.full_name }}</h3>
|
||||||
</a>
|
</a>
|
||||||
{% if course.is_mentor(member.name) %}
|
{% if course.is_mentor(member.name) %}
|
||||||
<div class="ml-2">
|
<div class="badge badge-success ml-2 align-self-start">Mentor</div>
|
||||||
<div class="badge badge-success">Mentor</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if member.bio %}
|
{% if member.bio %}
|
||||||
<i>{{member.bio}}</i>
|
<i class="ml-2">{{member.bio}}</i>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ from . import utils
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
utils.get_common_context(context)
|
utils.get_common_context(context)
|
||||||
print(context.members[0].bio)
|
if not context.membership:
|
||||||
|
utils.redirect_to_lesson(context.course)
|
||||||
|
|||||||
@@ -24,12 +24,12 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
<div class="mentor-dashboard">
|
<div class="mentor-dashboard">
|
||||||
<h1>Batch Progress</h1>
|
<h3>Batch Progress</h3>
|
||||||
{% for exercise in report.exercises %}
|
{% for exercise in report.exercises %}
|
||||||
<div class="exercise-submissions">
|
<div class="exercise-submissions">
|
||||||
<h2>{{exercise.title}}</h2>
|
<h2>Exercise {{exercise.index_label}}: {{exercise.title}}</h2>
|
||||||
{% for s in report.get_submissions_of_exercise(exercise.name) %}
|
{% for s in report.get_submissions_of_exercise(exercise.name) %}
|
||||||
<div class="submission">
|
<div class="submission">
|
||||||
<h4><a href="/{{s.owner.username}}">{{s.owner.full_name}}</a></h4>
|
<h4><a href="/{{s.owner.username}}">{{s.owner.full_name}}</a></h4>
|
||||||
|
|||||||
@@ -17,24 +17,24 @@ def get_context(context):
|
|||||||
|
|
||||||
class BatchReport:
|
class BatchReport:
|
||||||
def __init__(self, course, batch):
|
def __init__(self, course, batch):
|
||||||
self.submissions = get_submissions(batch)
|
self.submissions = get_submissions(course, batch)
|
||||||
self.exercises = self.get_exercises(course.name)
|
self.exercises = self.get_exercises(course.name)
|
||||||
|
|
||||||
self.submissions_by_exercise = defaultdict(list)
|
self.submissions_by_exercise = defaultdict(list)
|
||||||
for s in self.submissions:
|
for s in self.submissions:
|
||||||
self.submissions_by_exercise[s.exercise].append(s)
|
self.submissions_by_exercise[s.exercise].append(s)
|
||||||
|
|
||||||
def get_exercises(self, course_name):
|
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):
|
def get_submissions_of_exercise(self, exercise_name):
|
||||||
return self.submissions_by_exercise[exercise_name]
|
return self.submissions_by_exercise[exercise_name]
|
||||||
|
|
||||||
def get_submissions(batch):
|
def get_submissions(course, batch):
|
||||||
students = batch.get_students()
|
students = course.get_students(batch.name)
|
||||||
|
if not len(students):
|
||||||
|
return []
|
||||||
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())
|
names, values = nparams("s", students_map.keys())
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
select owner, exercise, name, solution, creation, image
|
select owner, exercise, name, solution, creation, image
|
||||||
from (
|
from (
|
||||||
@@ -45,7 +45,6 @@ def get_submissions(batch):
|
|||||||
""".format(names)
|
""".format(names)
|
||||||
|
|
||||||
data = frappe.db.sql(sql, values=values, as_dict=True)
|
data = frappe.db.sql(sql, values=values, as_dict=True)
|
||||||
|
|
||||||
for row in data:
|
for row in data:
|
||||||
row['owner'] = students_map[row['owner']]
|
row['owner'] = students_map[row['owner']]
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -5,24 +5,34 @@ def get_common_context(context):
|
|||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
|
|
||||||
course_name = frappe.form_dict["course"]
|
course_name = frappe.form_dict["course"]
|
||||||
|
try:
|
||||||
batch_name = frappe.form_dict["batch"]
|
batch_name = frappe.form_dict["batch"]
|
||||||
|
except KeyError:
|
||||||
|
batch_name = None
|
||||||
|
|
||||||
course = Course.find(course_name)
|
course = Course.find(course_name)
|
||||||
if not course:
|
if not course:
|
||||||
context.template = "www/404.html"
|
context.template = "www/404.html"
|
||||||
return
|
return
|
||||||
|
|
||||||
batch = course.get_batch(batch_name)
|
|
||||||
if not batch or not batch.is_member(frappe.session.user):
|
|
||||||
frappe.local.flags.redirect_location = "/courses/" + course_name
|
|
||||||
raise frappe.Redirect
|
|
||||||
|
|
||||||
context.course = course
|
context.course = course
|
||||||
|
|
||||||
|
membership = course.get_membership(frappe.session.user, batch_name)
|
||||||
|
if membership:
|
||||||
|
context.membership = membership
|
||||||
|
batch = course.get_batch(membership.batch)
|
||||||
|
|
||||||
|
if batch:
|
||||||
context.batch = batch
|
context.batch = batch
|
||||||
context.members = batch.get_mentors() + batch.get_students()
|
|
||||||
|
context.members = course.get_mentors(membership.batch) + course.get_students(membership.batch)
|
||||||
context.member_count = len(context.members)
|
context.member_count = len(context.members)
|
||||||
|
|
||||||
|
context.course.query_parameter = "?batch=" + membership.batch if membership and membership.batch else " "
|
||||||
context.livecode_url = get_livecode_url()
|
context.livecode_url = get_livecode_url()
|
||||||
|
|
||||||
def get_livecode_url():
|
def get_livecode_url():
|
||||||
return frappe.db.get_single_value("LMS Settings", "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_) + course.query_parameter
|
||||||
|
raise frappe.Redirect
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="Courses {{course.title}}" />
|
<meta name="keywords" content="Courses {{course.title}}" />
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@@ -12,26 +13,25 @@
|
|||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<a class="anchor_style" href="/courses">Courses</a> / <span class="text-muted">{{ course.title }}</span>
|
<a class="anchor_style" href="/courses">Courses</a> / <span class="text-muted">{{ course.title }}</span>
|
||||||
</div>
|
</div>
|
||||||
<h1 id="course-title" data-course="{{course.name}}">{{course.title}}</h1>
|
<div class="d-flex justify-content-between align-items-end">
|
||||||
|
<h2 id="course-title" data-course="{{course.name}}">{{course.title}}</h2>
|
||||||
|
{% if not course.disable_self_learning and not course.is_mentor(frappe.session.user) %}
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-primary join-batch" data-course="{{ course.name | urlencode }}"> Start Learning </button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
<div class="course-short-intro">{{ course.short_introduction }}</div>
|
<div class="course-short-intro">{{ course.short_introduction }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="">
|
||||||
<div class="col-lg-8 col-md-12">
|
<div class="">
|
||||||
<div class="course-details">
|
<div class="course-details">
|
||||||
{{ CourseVideo(course) }}
|
{{ CourseVideo(course) }}
|
||||||
|
|
||||||
{{ CourseDescription(course) }}
|
{{ CourseDescription(course) }}
|
||||||
{{ BatchSection(course) }}
|
|
||||||
{{ widgets.CourseOutline(course=course, show_link=False) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-4 col-md-12">
|
|
||||||
<div class="sidebar">
|
|
||||||
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
||||||
</div>
|
{{ BatchSection(course) }}
|
||||||
<div class="sidebar">
|
{{ widgets.CourseOutline(course=course, show_link=membership) }}
|
||||||
{{ MentorsSection(course.get_mentors(), course.is_mentor(frappe.session.user), course.name) }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -49,28 +49,31 @@
|
|||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro CourseDescription(course) %}
|
{% 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) }}
|
{{ frappe.utils.md_to_html(course.description) }}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro BatchSection(course) %}
|
{% macro BatchSection(course) %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-md-12">
|
||||||
{% if course.is_mentor(frappe.session.user) %}
|
{% if course.is_mentor(frappe.session.user) %}
|
||||||
{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }}
|
{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ BatchSectionForStudents(course, course.get_upcoming_batches()) }}
|
{{ BatchSectionForStudents(course, course.get_upcoming_batches()) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro BatchSectionForMentors(course, mentor_batches) %}
|
{% macro BatchSectionForMentors(course, mentor_batches) %}
|
||||||
<h2>Your Batches</h2>
|
<h2>Your Batches</h2>
|
||||||
|
|
||||||
{% if mentor_batches %}
|
{% 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> -->
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for batch in mentor_batches %}
|
{% for batch in mentor_batches %}
|
||||||
@@ -80,20 +83,20 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new
|
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.name}}">Add a new
|
||||||
batch</a>
|
batch</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="mentor_message">
|
<div class="mentor_message">
|
||||||
<p> You are a mentor for this course. </p>
|
<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>
|
<a class="" href="/add-a-new-batch?new=1&course={{course.name}}">Create your first batch</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro BatchSectionForStudents(course, upcoming_batches) %}
|
{% macro BatchSectionForStudents(course, upcoming_batches) %}
|
||||||
{% if upcoming_batches %}
|
{% if upcoming_batches %}
|
||||||
<h2>Upcoming Batches</h2>
|
<div class="mt-5">
|
||||||
|
<h3 class="upcoming">Upcoming Batches</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for batch in upcoming_batches %}
|
{% for batch in upcoming_batches %}
|
||||||
<div class="col-lg-4 col-md-6">
|
<div class="col-lg-4 col-md-6">
|
||||||
@@ -101,5 +104,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="mt-5 upcoming">There are no Upcoming Batches for this course currently.</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -51,20 +51,26 @@ frappe.ready(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
$(".join-batch").click((e) => {
|
$(".join-batch").click((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault();
|
||||||
|
var course = $(e.currentTarget).attr("data-course")
|
||||||
if (frappe.session.user == "Guest") {
|
if (frappe.session.user == "Guest") {
|
||||||
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
window.location.href = `/login?redirect-to=/courses/${course}`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
var batch = $(e.currentTarget).attr("data-batch");
|
||||||
|
batch = batch ? decodeURIComponent(batch) : "";
|
||||||
frappe.call({
|
frappe.call({
|
||||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||||
"args": {
|
"args": {
|
||||||
"batch": batch
|
"batch": batch ? batch : "",
|
||||||
|
"course": course
|
||||||
},
|
},
|
||||||
"callback": (data) => {
|
"callback": (data) => {
|
||||||
if (data.message == "OK") {
|
if (data.message == "OK") {
|
||||||
frappe.msgprint(__("You are now a student of this course."))
|
frappe.msgprint(__("You are now a student of this course."));
|
||||||
|
setTimeout(function () {
|
||||||
|
window.location.href = `/courses/${course}/home`;
|
||||||
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ def get_context(context):
|
|||||||
raise frappe.Redirect
|
raise frappe.Redirect
|
||||||
|
|
||||||
context.course = course
|
context.course = course
|
||||||
|
membership = course.get_membership(frappe.session.user)
|
||||||
batch = course.get_student_batch(frappe.session.user)
|
context.course.query_parameter = "?batch=" + membership.batch if membership and membership.batch else ""
|
||||||
if batch:
|
context.membership = membership
|
||||||
frappe.local.flags.redirect_location = f"/courses/{course.name}/{batch.name}/learn"
|
if not course.is_mentor(frappe.session.user) and membership:
|
||||||
|
frappe.local.flags.redirect_location = f"/courses/{course.name}/learn"
|
||||||
raise frappe.Redirect
|
raise frappe.Redirect
|
||||||
|
|
||||||
|
|||||||
@@ -10,19 +10,17 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="top-section" style="padding: 1rem 0rem;">
|
<section class="top-section" style="padding: 1rem 0rem;">
|
||||||
<div class='container pb-5'>
|
|
||||||
<h1>{{ 'Courses' }}</h1>
|
|
||||||
</div>
|
|
||||||
<div class='container'>
|
<div class='container'>
|
||||||
|
<h4 class="mt-5">{{ 'All Courses' }}</h4>
|
||||||
<div class="row mt-5">
|
<div class="row mt-5">
|
||||||
{% for course in courses %}
|
{% for course in courses %}
|
||||||
{{ course_card(course) }}
|
{{ course_card(course) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if courses %}
|
<!-- {% if courses %}
|
||||||
{% for n in range( (3 - (courses|length)) %3) %}
|
{% for n in range( (3 - (courses|length)) %3) %}
|
||||||
{{ null_card() }}
|
{{ null_card() }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %} -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -31,8 +29,8 @@
|
|||||||
|
|
||||||
{% macro course_card(course) %}
|
{% macro course_card(course) %}
|
||||||
<div class="col-sm-4 mb-4 text-left">
|
<div class="col-sm-4 mb-4 text-left">
|
||||||
<a class="card-links" style="color: inherit;" href="/courses/{{course.name}}">
|
<a class="anchor_style" style="color: inherit;" href="/courses/{{course.name}}">
|
||||||
<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'>
|
<div class='card-body'>
|
||||||
<h5 class='card-title'>{{ course.title }}</h5>
|
<h5 class='card-title'>{{ course.title }}</h5>
|
||||||
{% if course.description %}
|
{% if course.description %}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{% macro hackathon_card(hackathon) %}
|
{% macro hackathon_card(hackathon) %}
|
||||||
<div class="col-sm-4 mb-4 text-left">
|
<div class="col-sm-4 mb-4 text-left">
|
||||||
<a href="/hackathons/{{ hackathon.name }}" class="no-decoration no-underline">
|
<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'>
|
<div class='card-body'>
|
||||||
<h5 class='card-title'>{{ hackathon.name }}</h5>
|
<h5 class='card-title'>{{ hackathon.name }}</h5>
|
||||||
</div>
|
</div>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
{% macro null_card() %}
|
{% macro null_card() %}
|
||||||
<div class="col-sm-4 mb-4 text-left">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
@@ -72,29 +72,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<ul class="nav nav-tabs mt-4" id="myTab" role="tablist">
|
<ul class="nav nav-tabs mt-4" id="myTab" role="tablist">
|
||||||
|
{% for tab in profile_tabs %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home"
|
{% set slug = title.lower().replace(" ", "-") %}
|
||||||
aria-selected="true">Sketches</a>
|
{% 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>
|
</li>
|
||||||
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
{% for tab in profile_tabs %}
|
||||||
|
{% set slug = title.lower().replace(" ", "-") %}
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane fade py-4 show active" role="tabpanel" id="home">
|
<div class="tab-pane fade py-4 show active" role="tabpanel" id="slug">
|
||||||
<div class="row">
|
{{ tab.render() }}
|
||||||
{% if sketches %}
|
</div>
|
||||||
{% for sketch in sketches %}
|
|
||||||
<div class="col-md-4 col-sm-6">
|
|
||||||
{{ widgets.SketchTeaser(sketch=sketch) }}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% if not sketches %}
|
|
||||||
<p class="text-center">{{member.full_name}} has not created any skecth yet.</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,9 +3,20 @@ from community.lms.models import Sketch
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
context.member = frappe.get_doc("User", {"username": frappe.form_dict["username"]})
|
context.member = frappe.get_doc("User", {"username": frappe.form_dict["username"]})
|
||||||
except:
|
except:
|
||||||
context.template = "www/404.html"
|
context.template = "www/404.html"
|
||||||
else:
|
return
|
||||||
context.sketches = Sketch.get_recent_sketches(owner=context.member.email)
|
|
||||||
|
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,28 +0,0 @@
|
|||||||
{% extends "templates/base.html" %}
|
|
||||||
{% from "www/macros/livecode.html" import LiveCodeEditor, LiveCodeEditorJS %}
|
|
||||||
|
|
||||||
{% block title %}Sketches{% endblock %}
|
|
||||||
{% block head_include %}
|
|
||||||
<meta name="description" content="Sketches" />
|
|
||||||
<meta name="keywords" content="sketches" />
|
|
||||||
<link rel="stylesheet" href="/assets/css/lms.css">
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<section class="top-section" style="padding: 1rem 0rem;">
|
|
||||||
<div class='container pb-5'>
|
|
||||||
<h1>Recent Sketches</h1>
|
|
||||||
|
|
||||||
<a href="/sketches/new" class="btn btn-primary">Create a New Sketch</a>
|
|
||||||
</div>
|
|
||||||
<div class='container'>
|
|
||||||
<div class="row">
|
|
||||||
{% for sketch in sketches %}
|
|
||||||
<div class="col-md-3">
|
|
||||||
{{ widgets.SketchTeaser(sketch=sketch) }}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import frappe
|
|
||||||
from community.lms.models import Sketch
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
context.sketches = Sketch.get_recent_sketches()
|
|
||||||
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
{% extends "templates/base.html" %}
|
|
||||||
{% from "www/macros/livecode.html" import LiveCodeEditorLarge, LiveCodeEditorJS with context %}
|
|
||||||
|
|
||||||
{% block title %}{{sketch.title}}{% endblock %}
|
|
||||||
{% block head_include %}
|
|
||||||
<meta name="description" content="Sketch {{sketch.title}}" />
|
|
||||||
<meta name="keywords" content="sketch {{sketch.title}}" />
|
|
||||||
<style>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
|
||||||
<link rel="stylesheet" href="/assets/css/lms.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>
|
|
||||||
|
|
||||||
<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 %}
|
|
||||||
<section class="top-section" style="padding: 1rem 0rem;">
|
|
||||||
<div class='container pb-5'>
|
|
||||||
<nav aria-label="breadcrumb">
|
|
||||||
<ol class="breadcrumb">
|
|
||||||
<li class="breadcrumb-item" aria-current="page"><a href="/sketches">Sketches</a></li>
|
|
||||||
</ol>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div class="sketch-header">
|
|
||||||
{% if editable %}
|
|
||||||
<div class="form-row">
|
|
||||||
<div class="col-lg-8 col-md-6">
|
|
||||||
<input type="text" id="sketch-title" name="title" class="form-control" value="{{ sketch.title }}">
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-4 col-md-6">
|
|
||||||
<button type="submit" id="sketch-save" class="btn-save btn btn-primary">Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
<h1 class="sketch-title">{{sketch.title}}</h1>
|
|
||||||
<div class="sketch-owner-wrapper">By <span class="sketch-owner">{{sketch.get_owner_name()}}</span></div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if sketch.is_new() and not editable %}
|
|
||||||
<div class="alert alert-warning">
|
|
||||||
Please login to save this sketch.
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class="sketch-editor">
|
|
||||||
{{LiveCodeEditorLarge(sketch.name, sketch.code) }}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{%- block script %}
|
|
||||||
{{ super() }}
|
|
||||||
{{ LiveCodeEditorJS() }}
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
var sketch_name = {{ sketch.name | tojson }};
|
|
||||||
|
|
||||||
function saveSketch() {
|
|
||||||
var title = $("#sketch-title").val()
|
|
||||||
var code = livecodeEditors[0].codemirror.doc.getValue()
|
|
||||||
frappe.call('community.lms.doctype.lms_sketch.lms_sketch.save_sketch', {
|
|
||||||
name: sketch_name,
|
|
||||||
title: title,
|
|
||||||
code: code
|
|
||||||
})
|
|
||||||
.then(r => {
|
|
||||||
var msg = r.message;
|
|
||||||
if (!msg.ok) {
|
|
||||||
var error = msg.error || "Save failed."
|
|
||||||
frappe.msgprint({
|
|
||||||
"title": "Error",
|
|
||||||
"indicator": "red",
|
|
||||||
"message": error
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (msg.status == "created") {
|
|
||||||
var path = "/sketches/sketch?sketch=" + msg.name;
|
|
||||||
var url = window.location.protocol + "//" + window.location.host + path
|
|
||||||
window.history.pushState({path: url}, '', url);
|
|
||||||
sketch_name = name;
|
|
||||||
|
|
||||||
frappe.msgprint({
|
|
||||||
"title": "Notification",
|
|
||||||
"indicator": "green",
|
|
||||||
"message": "New sketch has been saved!"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (msg.status == "updated") {
|
|
||||||
frappe.msgprint({
|
|
||||||
"title": "Notification",
|
|
||||||
"indicator": "green",
|
|
||||||
"message": "The sketch has been saved!"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
$("#sketch-save").click(function() {
|
|
||||||
saveSketch();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
{%- endblock %}
|
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import frappe
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
|
|
||||||
try:
|
|
||||||
sketch_id = frappe.form_dict["sketch"]
|
|
||||||
except KeyError:
|
|
||||||
context.template = "www/404.html"
|
|
||||||
return
|
|
||||||
|
|
||||||
sketch = get_sketch(sketch_id)
|
|
||||||
if not sketch:
|
|
||||||
context.template = "www/404.html"
|
|
||||||
return
|
|
||||||
|
|
||||||
context.sketch = sketch
|
|
||||||
context.livecode_url = get_livecode_url()
|
|
||||||
context.editable = is_editable(context.sketch, frappe.session.user)
|
|
||||||
|
|
||||||
def is_editable(sketch, user):
|
|
||||||
if sketch.is_new():
|
|
||||||
# new sketches can be editable by any logged in user
|
|
||||||
return user != "Guest"
|
|
||||||
else:
|
|
||||||
# existing sketches are editable by the owner
|
|
||||||
return sketch.owner == user
|
|
||||||
|
|
||||||
def get_livecode_url():
|
|
||||||
doc = frappe.get_doc("LMS Settings")
|
|
||||||
return doc.livecode_url
|
|
||||||
|
|
||||||
def get_sketch(sketch_id):
|
|
||||||
if sketch_id == 'new':
|
|
||||||
sketch = frappe.new_doc('LMS Sketch')
|
|
||||||
sketch.name = "new"
|
|
||||||
sketch.title = "New Sketch"
|
|
||||||
sketch.code = "circle(100, 100, 50)"
|
|
||||||
return sketch
|
|
||||||
|
|
||||||
try:
|
|
||||||
name = "SKETCH-" + sketch_id
|
|
||||||
return frappe.get_doc('LMS Sketch', name)
|
|
||||||
except frappe.exceptions.DoesNotExistError:
|
|
||||||
return
|
|
||||||
|
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
frappe
|
frappe
|
||||||
websocket_client
|
websocket_client
|
||||||
|
markdown
|
||||||
|
beautifulsoup4
|
||||||
|
lxml
|
||||||
|
|||||||
Reference in New Issue
Block a user