Compare commits
80 Commits
issue-103
...
sketch-cle
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c24412633 | ||
|
|
1b8a45ba4a | ||
|
|
3dd4adbc1f | ||
|
|
0c52c9c4bc | ||
|
|
9caf44cdbd | ||
|
|
94b3ccd3d9 | ||
|
|
67708325ae | ||
|
|
3e99577401 | ||
|
|
621d01d502 | ||
|
|
aa20136223 | ||
|
|
5a7afb3092 | ||
|
|
f8948ac2ef | ||
|
|
8b1576a028 | ||
|
|
56d8a72a7d | ||
|
|
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 | ||
|
|
671b4a0650 | ||
|
|
586b39c0fd | ||
|
|
4fd7af053b | ||
|
|
5fd1143f76 | ||
|
|
0dc4743556 | ||
|
|
c96a14c972 | ||
|
|
400e706be1 | ||
|
|
a12a52747e | ||
|
|
b9a93bb160 | ||
|
|
9c65ff8ae6 | ||
|
|
bb0aa09b4e | ||
|
|
a8752afb3b | ||
|
|
327bde870b | ||
|
|
640ead4922 | ||
|
|
687f7f7f7b | ||
|
|
527a563e4a | ||
|
|
5bc9a7fe37 | ||
|
|
24835acd9c | ||
|
|
3648b3ab47 | ||
|
|
914f8504a0 | ||
|
|
ab8546a121 | ||
|
|
f327c6fb10 | ||
|
|
c7ccefa632 | ||
|
|
823cf4e431 | ||
|
|
18f074d8ac | ||
|
|
c9185ae68c | ||
|
|
82fa0fa4d7 | ||
|
|
64752433d2 | ||
|
|
ca42c32f54 | ||
|
|
631275e9a8 |
@@ -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,13 +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>/learn", "to_route": "batch/learn"},
|
{"from_route": "/courses/<course>/home", "to_route": "batch/home"},
|
||||||
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
|
{"from_route": "/courses/<course>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
|
{"from_route": "/courses/<course>/schedule", "to_route": "batch/schedule"},
|
||||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
|
{"from_route": "/courses/<course>/members", "to_route": "batch/members"},
|
||||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
|
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
|
||||||
{"from_route": "/courses/<course>/<batch>/progress", "to_route": "batch/progress"}
|
{"from_route": "/courses/<course>/about", "to_route": "batch/about"},
|
||||||
|
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
|
||||||
|
{"from_route": "/courses/<course>/join", "to_route": "batch/join"}
|
||||||
]
|
]
|
||||||
|
|
||||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||||
@@ -159,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]
|
||||||
|
|
||||||
@@ -174,3 +177,23 @@ 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
|
||||||
|
|
||||||
|
community_lesson_page_extensions = [
|
||||||
|
"community.plugins.LiveCodeExtension"
|
||||||
|
]
|
||||||
|
|
||||||
|
## 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,14 +29,14 @@ 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_email": frappe.session.user
|
"member": frappe.session.user
|
||||||
},
|
},
|
||||||
fieldname="name")
|
fieldname="name")
|
||||||
if not name:
|
if not 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,8 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
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 +21,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 +38,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,8 +45,8 @@ 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)
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ class TestExercise(unittest.TestCase):
|
|||||||
course = frappe.get_doc({
|
course = frappe.get_doc({
|
||||||
"doctype": "LMS Course",
|
"doctype": "LMS Course",
|
||||||
"name": "test-course",
|
"name": "test-course",
|
||||||
"title": "Test Course"
|
"title": "Test Course",
|
||||||
|
"short_introduction": "Test Course",
|
||||||
|
"description": "Test Course"
|
||||||
})
|
})
|
||||||
course.insert()
|
course.insert()
|
||||||
e = frappe.get_doc({
|
e = frappe.get_doc({
|
||||||
|
|||||||
@@ -6,12 +6,17 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"exercise",
|
"exercise",
|
||||||
"solution",
|
"status",
|
||||||
|
"batch",
|
||||||
|
"column_break_4",
|
||||||
"exercise_title",
|
"exercise_title",
|
||||||
"course",
|
"course",
|
||||||
"batch",
|
|
||||||
"lesson",
|
"lesson",
|
||||||
"image"
|
"section_break_8",
|
||||||
|
"solution",
|
||||||
|
"image",
|
||||||
|
"test_results",
|
||||||
|
"comments"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -21,12 +26,6 @@
|
|||||||
"label": "Exercise",
|
"label": "Exercise",
|
||||||
"options": "Exercise"
|
"options": "Exercise"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "solution",
|
|
||||||
"fieldtype": "Code",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Solution"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fetch_from": "exercise.title",
|
"fetch_from": "exercise.title",
|
||||||
"fieldname": "exercise_title",
|
"fieldname": "exercise_title",
|
||||||
@@ -61,11 +60,41 @@
|
|||||||
"fieldtype": "Code",
|
"fieldtype": "Code",
|
||||||
"label": "Image",
|
"label": "Image",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "status",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Status",
|
||||||
|
"options": "Correct\nIncorrect"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "test_results",
|
||||||
|
"fieldtype": "Small Text",
|
||||||
|
"label": "Test Results"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "comments",
|
||||||
|
"fieldtype": "Small Text",
|
||||||
|
"label": "Comments"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "solution",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Solution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_4",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_8",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-21 11:28:45.833018",
|
"modified": "2021-06-24 16:22:50.570845",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Exercise Submission",
|
"name": "Exercise Submission",
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
# 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
|
||||||
|
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from ..lesson.lesson import update_progress
|
||||||
|
|
||||||
class ExerciseSubmission(Document):
|
class ExerciseSubmission(Document):
|
||||||
pass
|
|
||||||
|
def after_insert(self):
|
||||||
|
course_details = frappe.get_doc("LMS Course", self.course)
|
||||||
|
if not (course_details.is_mentor(frappe.session.user) or frappe.flags.in_test):
|
||||||
|
update_progress(self.lesson)
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ def create_invite_request(invite_email):
|
|||||||
|
|
||||||
frappe.get_doc({
|
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):
|
||||||
|
|||||||
@@ -2,7 +2,47 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('Lesson', {
|
frappe.ui.form.on('Lesson', {
|
||||||
// refresh: function(frm) {
|
setup: function (frm) {
|
||||||
|
frm.trigger('setup_help');
|
||||||
|
},
|
||||||
|
setup_help(frm) {
|
||||||
|
frm.get_field('help').html(`
|
||||||
|
<p>You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p>
|
||||||
|
<div class="row font-weight-bold mb-3">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
Content Type
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
Syntax
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
// }
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
YouTube Video
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{{ YouTubeVideo("unique_embed_id") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
Exercise
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{{ Exercise("exercise_name") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-sm-4">
|
||||||
|
Quiz
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{{ Quiz("lms_quiz_name") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,11 +7,15 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"chapter",
|
"chapter",
|
||||||
"lesson_type",
|
"include_in_preview",
|
||||||
|
"column_break_4",
|
||||||
"title",
|
"title",
|
||||||
"index_",
|
"index_",
|
||||||
|
"index_label",
|
||||||
|
"section_break_6",
|
||||||
"body",
|
"body",
|
||||||
"sections"
|
"help_section",
|
||||||
|
"help"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -21,14 +25,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 +35,7 @@
|
|||||||
"default": "1",
|
"default": "1",
|
||||||
"fieldname": "index_",
|
"fieldname": "index_",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Index"
|
"label": "Index"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -47,15 +44,38 @@
|
|||||||
"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"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "help_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Help"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "help",
|
||||||
|
"fieldtype": "HTML"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"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-29 13:34:49.077363",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Lesson",
|
"name": "Lesson",
|
||||||
|
|||||||
@@ -5,41 +5,125 @@
|
|||||||
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()
|
|
||||||
e.lesson = self.name
|
|
||||||
e.save()
|
|
||||||
|
|
||||||
def get_sections(self):
|
def update_lesson_name_in_document(self, section):
|
||||||
return sorted(self.get('sections'), key=lambda s: s.index)
|
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.index_ = index
|
||||||
|
e.save()
|
||||||
|
index += 1
|
||||||
|
self.update_orphan_documents(doctype_map[section], documents)
|
||||||
|
|
||||||
def make_lms_section(self, index, section):
|
def update_orphan_documents(self, doctype, documents):
|
||||||
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
|
"""Updates the documents that were previously part of this lesson,
|
||||||
s.type = section.type
|
but not any more.
|
||||||
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):
|
||||||
|
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
||||||
|
|
||||||
|
def get_slugified_class(self):
|
||||||
|
if self.get_progress():
|
||||||
|
return ("").join([ s for s in self.get_progress().lower().split() ])
|
||||||
|
return
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def save_progress(lesson, course):
|
||||||
|
if not frappe.db.exists("LMS Batch Membership",
|
||||||
|
{
|
||||||
|
"member": frappe.session.user,
|
||||||
|
"course": course
|
||||||
|
}):
|
||||||
|
return
|
||||||
|
if frappe.db.exists("LMS Course Progress",
|
||||||
|
{
|
||||||
|
"lesson": lesson,
|
||||||
|
"owner": frappe.session.user
|
||||||
|
}):
|
||||||
|
return
|
||||||
|
|
||||||
|
lesson_details = frappe.get_doc("Lesson", lesson)
|
||||||
|
dynamic_content = find_macros(lesson_details.body)
|
||||||
|
|
||||||
|
status = "Complete"
|
||||||
|
if dynamic_content:
|
||||||
|
status = "Partially Complete"
|
||||||
|
|
||||||
|
frappe.get_doc({
|
||||||
|
"doctype": "LMS Course Progress",
|
||||||
|
"lesson": lesson_details.name,
|
||||||
|
"status": status
|
||||||
|
}).save(ignore_permissions=True)
|
||||||
|
|
||||||
|
def update_progress(lesson):
|
||||||
|
user = frappe.session.user
|
||||||
|
if not all_dynamic_content_submitted(lesson, user):
|
||||||
|
return
|
||||||
|
if frappe.db.exists("LMS Course Progress", {"lesson": lesson, "owner": user}):
|
||||||
|
course_progress = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
|
||||||
|
course_progress.status = "Complete"
|
||||||
|
course_progress.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
def all_dynamic_content_submitted(lesson, user):
|
||||||
|
all_exercises_submitted = check_all_exercise_submission(lesson, user)
|
||||||
|
all_quiz_submitted = check_all_quiz_submitted(lesson, user)
|
||||||
|
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 = {
|
||||||
|
"exercise": ["in", exercise_names],
|
||||||
|
"owner": user
|
||||||
|
}
|
||||||
|
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -6,11 +6,10 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"course",
|
"course",
|
||||||
"title",
|
|
||||||
"start_date",
|
"start_date",
|
||||||
"start_time",
|
"start_time",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"code",
|
"title",
|
||||||
"sessions_on",
|
"sessions_on",
|
||||||
"end_time",
|
"end_time",
|
||||||
"section_break_5",
|
"section_break_5",
|
||||||
@@ -31,18 +30,10 @@
|
|||||||
"label": "Course",
|
"label": "Course",
|
||||||
"options": "LMS Course"
|
"options": "LMS Course"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"fieldname": "code",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"label": "Code",
|
|
||||||
"read_only": 1,
|
|
||||||
"unique": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "title",
|
"fieldname": "title",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Title",
|
"label": "Title"
|
||||||
"unique": 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
@@ -84,7 +75,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "section_break_5",
|
"fieldname": "section_break_5",
|
||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Batch Description"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_9",
|
"fieldname": "column_break_9",
|
||||||
@@ -92,7 +84,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "section_break_7",
|
"fieldname": "section_break_7",
|
||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Batch Settings"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "start_date",
|
"fieldname": "start_date",
|
||||||
@@ -126,7 +119,7 @@
|
|||||||
"link_fieldname": "batch"
|
"link_fieldname": "batch"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-06 05:46:38.469120",
|
"modified": "2021-06-16 10:51:05.403726",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Batch",
|
"name": "LMS Batch",
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ from community.query import find, find_all
|
|||||||
class LMSBatch(Document):
|
class LMSBatch(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_if_mentor()
|
self.validate_if_mentor()
|
||||||
if not self.code:
|
|
||||||
self.generate_code()
|
|
||||||
|
|
||||||
def validate_if_mentor(self):
|
def validate_if_mentor(self):
|
||||||
course = frappe.get_doc("LMS Course", self.course)
|
course = frappe.get_doc("LMS Course", self.course)
|
||||||
@@ -21,20 +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 generate_code(self):
|
|
||||||
short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
|
|
||||||
course_batches = frappe.get_all("LMS Batch",{"course":self.course})
|
|
||||||
self.code = short_code + str(len(course_batches) + 1)
|
|
||||||
|
|
||||||
def get_mentors(self):
|
|
||||||
memberships = frappe.get_all(
|
|
||||||
"LMS Batch Membership",
|
|
||||||
{"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.
|
||||||
@@ -50,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:
|
||||||
@@ -96,3 +71,38 @@ def save_message(message, batch):
|
|||||||
"message": message
|
"message": message
|
||||||
})
|
})
|
||||||
doc.save(ignore_permissions=True)
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
def switch_batch(course_name, email, batch_name):
|
||||||
|
"""Switches the user from the current batch of the course to a new batch.
|
||||||
|
"""
|
||||||
|
membership = frappe.get_last_doc(
|
||||||
|
"LMS Batch Membership",
|
||||||
|
filters={"course": course_name, "member": email})
|
||||||
|
|
||||||
|
batch = frappe.get_doc("LMS Batch", batch_name)
|
||||||
|
if not batch:
|
||||||
|
raise ValueError(f"Invalid Batch: {batch_name}")
|
||||||
|
|
||||||
|
if batch.course != course_name:
|
||||||
|
raise ValueError("Can not switch batches across courses")
|
||||||
|
|
||||||
|
if batch.is_member(email):
|
||||||
|
print(f"{email} is already a member of {batch.title}")
|
||||||
|
return
|
||||||
|
|
||||||
|
old_batch = frappe.get_doc("LMS Batch", membership.batch)
|
||||||
|
|
||||||
|
print("updating membership", membership.name)
|
||||||
|
membership.batch = batch_name
|
||||||
|
membership.save()
|
||||||
|
|
||||||
|
# update exercise submissions
|
||||||
|
filters = {
|
||||||
|
"owner": email,
|
||||||
|
"batch": old_batch.name
|
||||||
|
}
|
||||||
|
for name in frappe.db.get_all("Exercise Submission", filters=filters, pluck='name'):
|
||||||
|
doc = frappe.get_doc("Exercise Submission", name)
|
||||||
|
print("updating exercise submission", name)
|
||||||
|
doc.batch = batch_name
|
||||||
|
doc.save()
|
||||||
|
|||||||
@@ -2,7 +2,13 @@
|
|||||||
// For license information, please see license.txt
|
// For license information, please see license.txt
|
||||||
|
|
||||||
frappe.ui.form.on('LMS Batch Membership', {
|
frappe.ui.form.on('LMS Batch Membership', {
|
||||||
// refresh: function(frm) {
|
onload: function(frm) {
|
||||||
|
frm.set_query('member', function(doc) {
|
||||||
// }
|
return {
|
||||||
|
filters: {
|
||||||
|
"ignore_user_type": 1,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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):
|
||||||
|
filters={
|
||||||
|
"member": self.member,
|
||||||
|
"course": self.course,
|
||||||
|
"name": ["!=", self.name]
|
||||||
|
}
|
||||||
|
if self.batch:
|
||||||
|
filters["batch"] = self.batch
|
||||||
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
||||||
filters={
|
filters,
|
||||||
"member": self.member,
|
|
||||||
"batch": self.batch,
|
|
||||||
"name": ["!=", self.name]
|
|
||||||
},
|
|
||||||
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):
|
||||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
"""Ensures that a studnet is only part of one batch.
|
||||||
previous_membership = frappe.get_all("LMS Batch Membership",
|
"""
|
||||||
filters={
|
# nothing to worry if the member is not a student
|
||||||
"member": self.member,
|
if self.member_type != "Student":
|
||||||
"name": ["!=", self.name]
|
return
|
||||||
},
|
|
||||||
fields=["batch", "member_type"]
|
|
||||||
)
|
|
||||||
|
|
||||||
for membership in previous_membership:
|
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||||
batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course")
|
memberships = frappe.get_all(
|
||||||
if batch_course == course and (membership.member_type == "Student" or self.member_type == "Student"):
|
"LMS Batch Membership",
|
||||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
filters={
|
||||||
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
|
"member": self.member,
|
||||||
|
"name": ["!=", self.name],
|
||||||
|
"member_type": "Student",
|
||||||
|
"course": self.course
|
||||||
|
},
|
||||||
|
fields=["batch", "member_type", "name"]
|
||||||
|
)
|
||||||
|
|
||||||
|
if memberships:
|
||||||
|
membership = memberships[0]
|
||||||
|
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||||
|
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)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ class TestLMSBatchMembership(unittest.TestCase):
|
|||||||
"doctype": "LMS Course",
|
"doctype": "LMS Course",
|
||||||
"name": "test-course",
|
"name": "test-course",
|
||||||
"title": "Test Course",
|
"title": "Test Course",
|
||||||
"short_code": "XX"
|
"short_code": "XX",
|
||||||
|
"short_introduction": "Test Course",
|
||||||
|
"description": "Test Course"
|
||||||
})
|
})
|
||||||
course.insert()
|
course.insert()
|
||||||
|
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -28,7 +42,8 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
"fieldtype": "Markdown Editor",
|
"fieldtype": "Markdown Editor",
|
||||||
"label": "Description"
|
"label": "Description",
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
@@ -57,7 +72,14 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "short_introduction",
|
"fieldname": "short_introduction",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Short Introduction"
|
"label": "Short Introduction",
|
||||||
|
"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,
|
||||||
@@ -84,7 +106,7 @@
|
|||||||
"link_fieldname": "course"
|
"link_fieldname": "course"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-06 13:37:03.318829",
|
"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,11 +82,11 @@ 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
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_student_batch(self, email):
|
def get_student_batch(self, email):
|
||||||
"""Returns the batch the given student is part of.
|
"""Returns the batch the given student is part of.
|
||||||
@@ -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.")
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ class TestLMSCourse(unittest.TestCase):
|
|||||||
def new_course(self, title):
|
def new_course(self, title):
|
||||||
doc = frappe.get_doc({
|
doc = frappe.get_doc({
|
||||||
"doctype": "LMS Course",
|
"doctype": "LMS Course",
|
||||||
"title": title
|
"title": title,
|
||||||
|
"short_introduction": title,
|
||||||
|
"description": title
|
||||||
})
|
})
|
||||||
doc.insert()
|
doc.insert()
|
||||||
return doc
|
return doc
|
||||||
@@ -24,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()
|
||||||
|
|||||||
@@ -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 Course Progress', {
|
||||||
// refresh: function(frm) {
|
// refresh: function(frm) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-05-31 17:20:13.388453",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"status",
|
||||||
|
"column_break_3",
|
||||||
|
"lesson",
|
||||||
|
"chapter",
|
||||||
|
"course"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fetch_from": "chapter.course",
|
||||||
|
"fieldname": "course",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
|
"label": "Course",
|
||||||
|
"options": "LMS Course",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "lesson.chapter",
|
||||||
|
"fieldname": "chapter",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Chapter",
|
||||||
|
"options": "Chapter",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "lesson",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Lesson",
|
||||||
|
"options": "Lesson"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "status",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"in_standard_filter": 1,
|
||||||
|
"label": "Status",
|
||||||
|
"options": "Complete\nPartially Complete\nIncomplete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_3",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-06-02 13:05:31.114939",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS Course Progress",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"create": 1,
|
||||||
|
"delete": 1,
|
||||||
|
"email": 1,
|
||||||
|
"export": 1,
|
||||||
|
"print": 1,
|
||||||
|
"read": 1,
|
||||||
|
"report": 1,
|
||||||
|
"role": "System Manager",
|
||||||
|
"share": 1,
|
||||||
|
"write": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (c) 2021, FOSS United and contributors
|
# 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 LMSCourseProgress(Document):
|
||||||
pass
|
pass
|
||||||
@@ -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 TestLMSSketch(unittest.TestCase):
|
class TestLMSCourseProgress(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
@@ -18,7 +18,7 @@ class LMSMessage(Document):
|
|||||||
template = self.get_message_template()
|
template = self.get_message_template()
|
||||||
message = frappe._dict({
|
message = frappe._dict({
|
||||||
"author_name": self.author_name,
|
"author_name": self.author_name,
|
||||||
"message_time": frappe.utils.pretty_date(self.creation),
|
"message_time": frappe.utils.format_datetime(self.creation, "dd-mm-yyyy HH:mm"),
|
||||||
"message": frappe.utils.md_to_html(self.message)
|
"message": frappe.utils.md_to_html(self.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -32,26 +32,28 @@ class LMSMessage(Document):
|
|||||||
template = frappe.render_template(template, {{
|
template = frappe.render_template(template, {{
|
||||||
"message": message
|
"message": message
|
||||||
}})
|
}})
|
||||||
$(".message-section").append(template);
|
$(".messages").append(template);
|
||||||
|
var message_element = document.getElementsByClassName("messages")[0]
|
||||||
|
message_element.scrollTo(0, message_element.scrollHeight);
|
||||||
""".format(template, message, self.owner)
|
""".format(template, message, self.owner)
|
||||||
|
|
||||||
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
||||||
|
|
||||||
def get_message_template(self):
|
def get_message_template(self):
|
||||||
return """
|
return """
|
||||||
<div class="discussion {% if message.is_author %} is-author {% endif %}">
|
<li class="{% if message.is_author %} ours {% endif %}">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="font-weight-bold">
|
<div class="font-weight-bold">
|
||||||
{{ message.author_name }}
|
{{ message.author_name }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-muted">
|
<small class="">
|
||||||
{{ message.message_time }}
|
{{ message.message_time }}
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="message-para">
|
||||||
<div class="mt-5">
|
|
||||||
{{ message.message }}
|
{{ message.message }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</li>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def send_email(self):
|
def send_email(self):
|
||||||
@@ -106,4 +108,3 @@ def send_daily_digest():
|
|||||||
},
|
},
|
||||||
delayed = False
|
delayed = False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
8
community/lms/doctype/lms_option/lms_option.py
Normal file
8
community/lms/doctype/lms_option/lms_option.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 LMSOption(Document):
|
||||||
|
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('LMS Sketch', {
|
frappe.ui.form.on('LMS Quiz', {
|
||||||
// refresh: function(frm) {
|
// refresh: function(frm) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
@@ -1,45 +1,41 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"autoname": "format:SKETCH-{#}",
|
"autoname": "field:title",
|
||||||
"creation": "2021-03-09 16:31:50.523524",
|
"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": [
|
||||||
"title",
|
"title",
|
||||||
"runtime",
|
"questions",
|
||||||
"code",
|
"lesson"
|
||||||
"svg"
|
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldname": "title",
|
"fieldname": "title",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Title"
|
"label": "Title",
|
||||||
|
"unique": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "runtime",
|
"fieldname": "questions",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Table",
|
||||||
"label": "Runtime"
|
"label": "Questions",
|
||||||
|
"options": "LMS Quiz Question"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "code",
|
"fieldname": "lesson",
|
||||||
"fieldtype": "Code",
|
"fieldtype": "Link",
|
||||||
"label": "Code"
|
"label": "Lesson",
|
||||||
},
|
"options": "Lesson"
|
||||||
{
|
|
||||||
"fieldname": "svg",
|
|
||||||
"fieldtype": "Code",
|
|
||||||
"label": "SVG",
|
|
||||||
"read_only": 1
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-03-12 08:42:56.671658",
|
"modified": "2021-06-23 17:58:57.642873",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Sketch",
|
"name": "LMS Quiz",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -57,6 +53,5 @@
|
|||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"track_changes": 1,
|
"track_changes": 1
|
||||||
"track_views": 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) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
});
|
||||||
@@ -1,41 +1,39 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"creation": "2021-04-07 00:26:28.806520",
|
"creation": "2021-06-07 14:19:54.958989",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"section",
|
"quiz",
|
||||||
"code",
|
"result",
|
||||||
"author"
|
"score"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldname": "section",
|
"fieldname": "quiz",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"label": "Quiz",
|
||||||
"label": "Section",
|
"options": "LMS Quiz"
|
||||||
"options": "LMS Section"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "code",
|
"fieldname": "result",
|
||||||
"fieldtype": "Code",
|
"fieldtype": "Table",
|
||||||
"label": "Code"
|
"label": "Result",
|
||||||
|
"options": "LMS Quiz Result"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "author",
|
"fieldname": "score",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Data",
|
||||||
"in_list_view": 1,
|
"label": "Score"
|
||||||
"label": "Author",
|
|
||||||
"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-07 14:19:54.958989",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Code Revision",
|
"name": "LMS Quiz Submission",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -53,6 +51,5 @@
|
|||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"title_field": "section",
|
|
||||||
"track_changes": 1
|
"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.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
"""Utilities to work with livecode service.
|
|
||||||
"""
|
|
||||||
import websocket
|
|
||||||
import json
|
|
||||||
from .svg import SVG
|
|
||||||
import frappe
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
# Files to pass to livecode server
|
|
||||||
# The same code is part of livecode-canvas.js
|
|
||||||
# TODO: generate livecode-canvas.js from this file
|
|
||||||
START = '''
|
|
||||||
import sketch
|
|
||||||
code = open("main.py").read()
|
|
||||||
env = dict(sketch.__dict__)
|
|
||||||
exec(code, env)
|
|
||||||
'''
|
|
||||||
|
|
||||||
SKETCH = '''
|
|
||||||
import json
|
|
||||||
|
|
||||||
def sendmsg(msgtype, function, args):
|
|
||||||
"""Sends a message to the frontend.
|
|
||||||
|
|
||||||
The frontend will receive the specified message whenever
|
|
||||||
this function is called. The frontend can decide to some
|
|
||||||
action on each of these messages.
|
|
||||||
"""
|
|
||||||
msg = dict(msgtype=msgtype, function=function, args=args)
|
|
||||||
print("--MSG--", json.dumps(msg))
|
|
||||||
|
|
||||||
def _draw(func, **kwargs):
|
|
||||||
sendmsg(msgtype="draw", function=func, args=kwargs)
|
|
||||||
|
|
||||||
def circle(x, y, d):
|
|
||||||
"""Draws a circle of diameter d with center (x, y).
|
|
||||||
"""
|
|
||||||
_draw("circle", x=x, y=y, d=d)
|
|
||||||
|
|
||||||
def line(x1, y1, x2, y2):
|
|
||||||
"""Draws a line from point (x1, y1) to point (x2, y2).
|
|
||||||
"""
|
|
||||||
_draw("line", x1=x1, y1=y1, x2=x2, y2=y2)
|
|
||||||
|
|
||||||
def rect(x, y, w, h):
|
|
||||||
"""Draws a rectangle on the canvas.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
x: x coordinate of the top-left corner of the rectangle
|
|
||||||
y: y coordinate of the top-left corner of the rectangle
|
|
||||||
w: width of the rectangle
|
|
||||||
h: height of the rectangle
|
|
||||||
"""
|
|
||||||
_draw("rect", x=x, y=y, w=w, h=h)
|
|
||||||
|
|
||||||
def clear():
|
|
||||||
_draw("clear")
|
|
||||||
|
|
||||||
# clear the canvas on start
|
|
||||||
clear()
|
|
||||||
'''
|
|
||||||
|
|
||||||
def get_livecode_url():
|
|
||||||
doc = frappe.get_cached_doc("LMS Settings")
|
|
||||||
return doc.livecode_url
|
|
||||||
|
|
||||||
def get_livecode_ws_url():
|
|
||||||
url = urlparse(get_livecode_url())
|
|
||||||
protocol = "wss" if url.scheme == "https" else "ws"
|
|
||||||
return protocol + "://" + url.netloc + "/livecode"
|
|
||||||
|
|
||||||
def livecode_to_svg(livecode_ws_url, code, *, timeout=3):
|
|
||||||
"""Renders the code as svg.
|
|
||||||
"""
|
|
||||||
if livecode_ws_url is None:
|
|
||||||
livecode_ws_url = get_livecode_ws_url()
|
|
||||||
|
|
||||||
try:
|
|
||||||
ws = websocket.WebSocket()
|
|
||||||
ws.settimeout(timeout)
|
|
||||||
ws.connect(livecode_ws_url)
|
|
||||||
|
|
||||||
msg = {
|
|
||||||
"msgtype": "exec",
|
|
||||||
"runtime": "python",
|
|
||||||
"code": code,
|
|
||||||
"files": [
|
|
||||||
{"filename": "start.py", "contents": START},
|
|
||||||
{"filename": "sketch.py", "contents": SKETCH},
|
|
||||||
],
|
|
||||||
"command": ["python", "start.py"]
|
|
||||||
}
|
|
||||||
ws.send(json.dumps(msg))
|
|
||||||
|
|
||||||
messages = _read_messages(ws)
|
|
||||||
commands = [m for m in messages if m['msgtype'] == 'draw']
|
|
||||||
img = draw_image(commands)
|
|
||||||
return img.tostring()
|
|
||||||
except websocket.WebSocketException as e:
|
|
||||||
frappe.log_error(frappe.get_traceback(), 'livecode_to_svg failed')
|
|
||||||
|
|
||||||
def _read_messages(ws):
|
|
||||||
messages = []
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
msg = ws.recv()
|
|
||||||
if not msg:
|
|
||||||
break
|
|
||||||
messages.append(json.loads(msg))
|
|
||||||
except websocket.WebSocketTimeoutException as e:
|
|
||||||
print("Error:", e)
|
|
||||||
pass
|
|
||||||
return messages
|
|
||||||
|
|
||||||
def draw_image(commands):
|
|
||||||
img = SVG(width=300, height=300, viewBox="0 0 300 300", fill='none', stroke='black')
|
|
||||||
for c in commands:
|
|
||||||
args = c['args']
|
|
||||||
if c['function'] == 'circle':
|
|
||||||
img.circle(cx=args['x'], cy=args['y'], r=args['d']/2)
|
|
||||||
elif c['function'] == 'line':
|
|
||||||
img.line(x1=args['x1'], y1=args['y1'], x2=args['x2'], y2=args['y2'])
|
|
||||||
elif c['function'] == 'rect':
|
|
||||||
img.rect(x=args['x'], y=args['y'], width=args['w'], height=args['h'])
|
|
||||||
return img
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (c) 2021, FOSS United and contributors
|
|
||||||
# For license information, please see license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import hashlib
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
import frappe
|
|
||||||
from frappe.model.document import Document
|
|
||||||
from . import livecode
|
|
||||||
|
|
||||||
DEFAULT_IMAGE = """
|
|
||||||
<svg viewBox="0 0 300 300" width="300" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
</svg>
|
|
||||||
"""
|
|
||||||
|
|
||||||
class LMSSketch(Document):
|
|
||||||
@property
|
|
||||||
def sketch_id(self):
|
|
||||||
"""Returns the numeric part of the name.
|
|
||||||
|
|
||||||
For example, the skech_id will be "123" for sketch with name "SKETCH-123".
|
|
||||||
"""
|
|
||||||
return self.name.replace("SKETCH-", "")
|
|
||||||
|
|
||||||
def get_owner(self):
|
|
||||||
"""Returns the owner of this sketch as a document.
|
|
||||||
"""
|
|
||||||
return frappe.get_doc("User", self.owner)
|
|
||||||
|
|
||||||
def get_owner_name(self):
|
|
||||||
return self.get_owner().full_name
|
|
||||||
|
|
||||||
def get_livecode_url(self):
|
|
||||||
doc = frappe.get_cached_doc("LMS Settings")
|
|
||||||
return doc.livecode_url
|
|
||||||
|
|
||||||
def get_livecode_ws_url(self):
|
|
||||||
url = urlparse(self.get_livecode_url())
|
|
||||||
protocol = "wss" if url.scheme == "https" else "ws"
|
|
||||||
return protocol + "://" + url.netloc + "/livecode"
|
|
||||||
|
|
||||||
def to_svg(self):
|
|
||||||
return self.svg or self.render_svg()
|
|
||||||
|
|
||||||
def render_svg(self):
|
|
||||||
h = hashlib.md5(self.code.encode('utf-8')).hexdigest()
|
|
||||||
cache = frappe.cache()
|
|
||||||
key = "sketch-" + h
|
|
||||||
value = cache.get(key)
|
|
||||||
if value:
|
|
||||||
value = value.decode('utf-8')
|
|
||||||
else:
|
|
||||||
ws_url = self.get_livecode_ws_url()
|
|
||||||
value = livecode.livecode_to_svg(ws_url, self.code)
|
|
||||||
if value:
|
|
||||||
cache.set(key, value)
|
|
||||||
return value or DEFAULT_IMAGE
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_recent_sketches(limit=100, owner=None):
|
|
||||||
"""Returns the recent sketches.
|
|
||||||
"""
|
|
||||||
filters = {}
|
|
||||||
if owner:
|
|
||||||
filters = {"owner": owner}
|
|
||||||
sketches = frappe.get_all(
|
|
||||||
"LMS Sketch",
|
|
||||||
filters=filters,
|
|
||||||
fields='*',
|
|
||||||
order_by='modified desc',
|
|
||||||
page_length=limit
|
|
||||||
)
|
|
||||||
return [frappe.get_doc(doctype='LMS Sketch', **doc) for doc in sketches]
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return f"<LMSSketch {self.name}>"
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def save_sketch(name, title, code):
|
|
||||||
if not name or name == "new":
|
|
||||||
doc = frappe.new_doc('LMS Sketch')
|
|
||||||
doc.title = title
|
|
||||||
doc.code = code
|
|
||||||
doc.runtime = 'python-canvas'
|
|
||||||
doc.insert(ignore_permissions=True)
|
|
||||||
status = "created"
|
|
||||||
else:
|
|
||||||
doc = frappe.get_doc("LMS Sketch", name)
|
|
||||||
|
|
||||||
if doc.owner != frappe.session.user:
|
|
||||||
return {
|
|
||||||
"ok": False,
|
|
||||||
"error": "Permission Denied"
|
|
||||||
}
|
|
||||||
doc.title = title
|
|
||||||
doc.code = code
|
|
||||||
doc.svg = ''
|
|
||||||
doc.save()
|
|
||||||
status = "updated"
|
|
||||||
return {
|
|
||||||
"ok": True,
|
|
||||||
"status": status,
|
|
||||||
"name": doc.name,
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
"""SVG rendering library.
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
from svg import SVG
|
|
||||||
|
|
||||||
svg = SVG(width=200, height=200)
|
|
||||||
svg.circle(cx=100, cy=200, r=50)
|
|
||||||
print(svg.tostring())
|
|
||||||
"""
|
|
||||||
from xml.etree import ElementTree
|
|
||||||
|
|
||||||
TAGNAMES = set([
|
|
||||||
"circle", "ellipse",
|
|
||||||
"line", "path", "rect", "polygon", "polyline",
|
|
||||||
"text", "textPath", "title",
|
|
||||||
"marker", "defs",
|
|
||||||
"g"
|
|
||||||
])
|
|
||||||
|
|
||||||
class Node:
|
|
||||||
"""SVG Node"""
|
|
||||||
def __init__(self, tag, **attrs):
|
|
||||||
self.tag = tag
|
|
||||||
self.attrs = dict((k.replace('_', '-'), str(v)) for k, v in attrs.items())
|
|
||||||
self.children = []
|
|
||||||
|
|
||||||
def node(self, tag, **attrs):
|
|
||||||
n = Node(tag, **attrs)
|
|
||||||
self.children.append(n)
|
|
||||||
return n
|
|
||||||
|
|
||||||
def apply(self, func):
|
|
||||||
"""Applies a function to this node and
|
|
||||||
all the children recursively.
|
|
||||||
"""
|
|
||||||
func(self)
|
|
||||||
for n in self.children:
|
|
||||||
n.apply(func)
|
|
||||||
|
|
||||||
def clone(self):
|
|
||||||
node = Node(self.tag, **self.attrs)
|
|
||||||
node.children = [n.clone() for n in self.children]
|
|
||||||
return node
|
|
||||||
|
|
||||||
def add_node(self, node):
|
|
||||||
if not isinstance(node, Node):
|
|
||||||
node = Text(node)
|
|
||||||
self.children.append(node)
|
|
||||||
|
|
||||||
def __getattr__(self, tag):
|
|
||||||
if tag not in TAGNAMES:
|
|
||||||
raise AttributeError(tag)
|
|
||||||
return lambda **attrs: self.node(tag, **attrs)
|
|
||||||
|
|
||||||
def translate(self, x, y):
|
|
||||||
return self.g(transform="translate(%s, %s)" % (x, y))
|
|
||||||
|
|
||||||
def scale(self, *args):
|
|
||||||
return self.g(transform="scale(%s)" % ", ".join(str(a) for a in args))
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<%s .../>" % self.tag
|
|
||||||
|
|
||||||
def __enter__(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def build_tree(self, builder):
|
|
||||||
builder.start(self.tag, self.attrs)
|
|
||||||
for node in self.children:
|
|
||||||
node.build_tree(builder)
|
|
||||||
return builder.end(self.tag)
|
|
||||||
|
|
||||||
def _indent(self, elem, level=0):
|
|
||||||
"""Indent etree node for prettyprinting."""
|
|
||||||
|
|
||||||
i = "\n" + level*" "
|
|
||||||
if len(elem):
|
|
||||||
if not elem.text or not elem.text.strip():
|
|
||||||
elem.text = i + " "
|
|
||||||
if not elem.tail or not elem.tail.strip():
|
|
||||||
elem.tail = i
|
|
||||||
for elem in elem:
|
|
||||||
self._indent(elem, level+1)
|
|
||||||
if not elem.tail or not elem.tail.strip():
|
|
||||||
elem.tail = i
|
|
||||||
else:
|
|
||||||
if level and (not elem.tail or not elem.tail.strip()):
|
|
||||||
elem.tail = i
|
|
||||||
|
|
||||||
def save(self, filename, encoding='utf-8'):
|
|
||||||
f = open(filename, 'w')
|
|
||||||
f.write(self.tostring())
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def tostring(self, encoding='utf-8'):
|
|
||||||
builder = ElementTree.TreeBuilder()
|
|
||||||
self.build_tree(builder)
|
|
||||||
e = builder.close()
|
|
||||||
self._indent(e)
|
|
||||||
return ElementTree.tostring(e, encoding).decode(encoding)
|
|
||||||
|
|
||||||
class Text(Node):
|
|
||||||
"""Text Node
|
|
||||||
|
|
||||||
>>> p = Node("p")
|
|
||||||
>>> p.add_node("hello, world!")
|
|
||||||
>>> p.tostring()
|
|
||||||
'<p>hello, world!</p>'
|
|
||||||
"""
|
|
||||||
def __init__(self, text):
|
|
||||||
Node.__init__(self, "__text__")
|
|
||||||
self._text = text
|
|
||||||
|
|
||||||
def build_tree(self, builder):
|
|
||||||
builder.data(str(self._text))
|
|
||||||
|
|
||||||
class SVG(Node):
|
|
||||||
"""
|
|
||||||
>>> svg = SVG(width=200, height=200)
|
|
||||||
>>> svg.rect(x=0, y=0, width=200, height=200, fill="blue")
|
|
||||||
<rect .../>
|
|
||||||
>>> with svg.translate(-50, -50) as g:
|
|
||||||
... g.rect(x=0, y=0, width=50, height=100, fill="red")
|
|
||||||
... g.rect(x=50, y=0, width=50, height=100, fill="green")
|
|
||||||
<rect .../>
|
|
||||||
<rect .../>
|
|
||||||
>>> print(svg.tostring())
|
|
||||||
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect x="0" y="0" width="200" height="200" fill="blue" />
|
|
||||||
<g transform="translate(-50, -50)">
|
|
||||||
<rect x="0" y="0" width="50" height="100" fill="red" />
|
|
||||||
<rect x="50" y="0" width="50" height="100" fill="green" />
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
"""
|
|
||||||
def __init__(self, **attrs):
|
|
||||||
attrs['xmlns'] = "http://www.w3.org/2000/svg"
|
|
||||||
Node.__init__(self, 'svg', **attrs)
|
|
||||||
|
|
||||||
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>"
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
"""Handy module to make access to all doctypes from a single place.
|
"""Handy module to make access to all doctypes from a single place.
|
||||||
"""
|
"""
|
||||||
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_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-04-30 11:22:18.188712",
|
"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",
|
||||||
@@ -39,12 +39,12 @@
|
|||||||
"allow_read_on_all_link_options": 0,
|
"allow_read_on_all_link_options": 0,
|
||||||
"fieldname": "course",
|
"fieldname": "course",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 0,
|
"hidden": 1,
|
||||||
"label": "Course",
|
"label": "Course",
|
||||||
"max_length": 0,
|
"max_length": 0,
|
||||||
"max_value": 0,
|
"max_value": 0,
|
||||||
"options": "",
|
"options": "LMS Course",
|
||||||
"read_only": 1,
|
"read_only": 0,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"show_in_filter": 0
|
"show_in_filter": 0
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
frappe.ready(function() {
|
|
||||||
// bind events here
|
|
||||||
})
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
{
|
|
||||||
"accept_payment": 0,
|
|
||||||
"allow_comments": 0,
|
|
||||||
"allow_delete": 0,
|
|
||||||
"allow_edit": 0,
|
|
||||||
"allow_incomplete": 0,
|
|
||||||
"allow_multiple": 0,
|
|
||||||
"allow_print": 0,
|
|
||||||
"amount": 0.0,
|
|
||||||
"amount_based_on_field": 0,
|
|
||||||
"apply_document_permissions": 0,
|
|
||||||
"button_label": "Save",
|
|
||||||
"creation": "2021-04-15 13:32:14.171328",
|
|
||||||
"doc_type": "LMS Batch Membership",
|
|
||||||
"docstatus": 0,
|
|
||||||
"doctype": "Web Form",
|
|
||||||
"idx": 0,
|
|
||||||
"is_standard": 1,
|
|
||||||
"login_required": 1,
|
|
||||||
"max_attachment_size": 0,
|
|
||||||
"modified": "2021-04-15 13:32:14.171328",
|
|
||||||
"modified_by": "Administrator",
|
|
||||||
"module": "LMS",
|
|
||||||
"name": "join-a-batch",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"payment_button_label": "Buy Now",
|
|
||||||
"published": 1,
|
|
||||||
"route": "join-a-batch",
|
|
||||||
"route_to_success_link": 0,
|
|
||||||
"show_attachments": 0,
|
|
||||||
"show_in_grid": 0,
|
|
||||||
"show_sidebar": 0,
|
|
||||||
"sidebar_items": [],
|
|
||||||
"success_url": "/join-a-batch",
|
|
||||||
"title": "Join a Batch",
|
|
||||||
"web_form_fields": [
|
|
||||||
{
|
|
||||||
"allow_read_on_all_link_options": 0,
|
|
||||||
"fieldtype": "Attach",
|
|
||||||
"hidden": 0,
|
|
||||||
"max_length": 0,
|
|
||||||
"max_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"show_in_filter": 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import frappe
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
# do your magic here
|
|
||||||
pass
|
|
||||||
4
community/lms/widgets/BatchHeader.html
Normal file
4
community/lms/widgets/BatchHeader.html
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<div class="p-5 batch-header">
|
||||||
|
<h3>{{batch_name}}</h3>
|
||||||
|
<div class="text-muted">{{member_count}} members</div>
|
||||||
|
</div>
|
||||||
67
community/lms/widgets/BatchTabs.html
Normal file
67
community/lms/widgets/BatchTabs.html
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<div class="mt-5">
|
||||||
|
<a class="anchor_style" href="/courses">Courses</a> /{% if course.is_mentor(frappe.session.user) %} <a
|
||||||
|
class="anchor_style" href="/courses/{{ course.name }}"> {{ course.title }}</a> {% else %} <span class="text-muted">
|
||||||
|
{{ course.title }}</span> {% endif %}
|
||||||
|
{% set all_memberships = course.get_all_memberships(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>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if not membership %}
|
||||||
|
{% set display_class = "hide" %}
|
||||||
|
{% else %}
|
||||||
|
{% set display_class = "" %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs mt-4">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" id="home" href="/courses/{{course.name}}/home{{ course.query_parameter }}">Home</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
{% 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 class="nav-item">
|
||||||
|
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/schedule">Schedule</a>
|
||||||
|
</li> -->
|
||||||
|
<li class="nav-item {{ display_class }}">
|
||||||
|
<a class="nav-link" id="members" href="/courses/{{course.name}}/members{{ course.query_parameter }}">Members</a>
|
||||||
|
</li>
|
||||||
|
<!-- <li class="nav-item {{ display_class }}">
|
||||||
|
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/discuss">Discussion</a>
|
||||||
|
</li> -->
|
||||||
|
<!-- <li class="nav-item">
|
||||||
|
<a class="nav-link" id="about" href="/courses/{{course.name}}/about">About</a>
|
||||||
|
</li> -->
|
||||||
|
{% if membership and membership.batch and course.is_mentor(frappe.session.user) %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress{{ course.query_parameter }}">Progress</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
frappe.ready(() => {
|
||||||
|
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}{{ course.query_parameter }}"]`)
|
||||||
|
if (selector) {
|
||||||
|
selector.classList.add('active');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#learn").addClass('active')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -1,14 +1,27 @@
|
|||||||
<div class="chapter-teaser">
|
<div class="chapter-teaser">
|
||||||
<div class="teaser-body">
|
<div class="teaser-body">
|
||||||
<h3 class="chapter-title"><span class="chapter-number">{{index}}</span> {{ chapter.title }}</h3>
|
<div class="chapter-title mb-5 font-weight-bold"><span class="mr-1">{{index}}.</span> {{ chapter.title }}</div>
|
||||||
<div class="chapter-description">
|
<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">
|
||||||
{{lesson.title}}
|
{% 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>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %}
|
||||||
|
<span class="ml-5 badge p-2 {{ lesson.get_slugified_class() }}"> {{ lesson.get_progress() }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
7
community/lms/widgets/CourseOutline.html
Normal file
7
community/lms/widgets/CourseOutline.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div class="mt-5">
|
||||||
|
<h3> Course Outline </h3>
|
||||||
|
|
||||||
|
{% for chapter in course.get_chapters() %}
|
||||||
|
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
{% 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 %}
|
||||||
|
|||||||
6
community/lms/widgets/InstructorSection.html
Normal file
6
community/lms/widgets/InstructorSection.html
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<div class="instructor">
|
||||||
|
{{ widgets.Avatar(member=instructor, avatar_class="avatar-medium") }}
|
||||||
|
<a class="ml-1 instructor-title" href="/{{instructor.username}}">{{ instructor.full_name }}</a>
|
||||||
|
<div class="instructor-subtitle">Course Creator</div>
|
||||||
|
<!-- <div class="instructor-subtitle">Created {{instructor.get_course_count()}} courses</div> -->
|
||||||
|
</div>
|
||||||
30
community/lms/widgets/RenderBatch.html
Normal file
30
community/lms/widgets/RenderBatch.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<div class="batch">
|
||||||
|
<div class="batch-details">
|
||||||
|
<div class="">Session every {{batch.sessions_on}}</div>
|
||||||
|
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
||||||
|
{{frappe.utils.format_time(batch.end_time, "short")}}
|
||||||
|
</div>
|
||||||
|
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
||||||
|
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
||||||
|
|
||||||
|
{% for m in course.get_mentors(batch.name) %}
|
||||||
|
<div>
|
||||||
|
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||||
|
<span class="instructor-title">{{m.full_name}}</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% if can_manage or can_join %}
|
||||||
|
<div class="cta">
|
||||||
|
<div class="">
|
||||||
|
{% if can_manage %}
|
||||||
|
<a href="/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 %}
|
||||||
|
<button class="join-batch btn btn-secondary" data-batch="{{ batch.name | urlencode }}"
|
||||||
|
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
160
community/lms/workspace/lms/lms.json
Normal file
160
community/lms/workspace/lms/lms.json
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
{
|
||||||
|
"category": "Modules",
|
||||||
|
"charts": [],
|
||||||
|
"creation": "2021-06-29 13:05:28.741459",
|
||||||
|
"developer_mode_only": 0,
|
||||||
|
"disable_user_customization": 0,
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Workspace",
|
||||||
|
"extends_another_page": 0,
|
||||||
|
"hide_custom": 0,
|
||||||
|
"icon": "education",
|
||||||
|
"idx": 0,
|
||||||
|
"is_default": 0,
|
||||||
|
"is_standard": 1,
|
||||||
|
"label": "LMS",
|
||||||
|
"links": [
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Card Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Course",
|
||||||
|
"link_to": "LMS Course",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Batch",
|
||||||
|
"link_to": "LMS Batch",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Batch Membership",
|
||||||
|
"link_to": "LMS Batch Membership",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Course Mentor Mapping",
|
||||||
|
"link_to": "LMS Course Mentor Mapping",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "Content",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Card Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "Chapter",
|
||||||
|
"link_to": "Chapter",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "Lesson",
|
||||||
|
"link_to": "Lesson",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "Exercise",
|
||||||
|
"link_to": "Exercise",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "Exercise Submission",
|
||||||
|
"link_to": "Exercise Submission",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Quiz",
|
||||||
|
"link_to": "LMS Quiz",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": 0,
|
||||||
|
"is_query_report": 0,
|
||||||
|
"label": "LMS Quiz Submission",
|
||||||
|
"link_to": "LMS Quiz Submission",
|
||||||
|
"link_type": "DocType",
|
||||||
|
"onboard": 0,
|
||||||
|
"type": "Link"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"modified": "2021-06-29 15:11:07.324651",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "LMS",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"pin_to_bottom": 0,
|
||||||
|
"pin_to_top": 1,
|
||||||
|
"shortcuts": [
|
||||||
|
{
|
||||||
|
"color": "#29CD42",
|
||||||
|
"doc_view": "List",
|
||||||
|
"format": "{} Published",
|
||||||
|
"label": "Courses",
|
||||||
|
"link_to": "LMS Course",
|
||||||
|
"stats_filter": "{\"is_published\": 1}",
|
||||||
|
"type": "DocType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "#29CD42",
|
||||||
|
"doc_view": "List",
|
||||||
|
"format": "{} Active ",
|
||||||
|
"label": "Batches",
|
||||||
|
"link_to": "LMS Batch",
|
||||||
|
"stats_filter": "{\"status\": \"Active\"}",
|
||||||
|
"type": "DocType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "#39E4A5",
|
||||||
|
"doc_view": "List",
|
||||||
|
"format": "{} Students",
|
||||||
|
"label": "Memberships",
|
||||||
|
"link_to": "LMS Batch Membership",
|
||||||
|
"stats_filter": "{\"member_type\": \"Student\"}",
|
||||||
|
"type": "DocType"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
108
community/plugins.py
Normal file
108
community/plugins.py
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
"""
|
||||||
|
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()
|
||||||
|
|
||||||
|
class LiveCodeExtension(PageExtension):
|
||||||
|
def render_header(self):
|
||||||
|
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
|
||||||
|
context = {
|
||||||
|
"livecode_url": livecode_url
|
||||||
|
}
|
||||||
|
return frappe.render_template(
|
||||||
|
"templates/livecode/extension_header.html",
|
||||||
|
context)
|
||||||
|
|
||||||
|
def render_footer(self):
|
||||||
|
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
|
||||||
|
context = {
|
||||||
|
"livecode_url": livecode_url
|
||||||
|
}
|
||||||
|
return frappe.render_template(
|
||||||
|
"templates/livecode/extension_footer.html",
|
||||||
|
context)
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,14 +100,6 @@ body {
|
|||||||
border-top: 1px solid #ddc;
|
border-top: 1px solid #ddc;
|
||||||
}
|
}
|
||||||
|
|
||||||
.batch .cta button {
|
|
||||||
background: var(--cta-color);
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.batch .right {
|
.batch .right {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
@@ -127,44 +122,13 @@ img.profile-photo {
|
|||||||
max-width: 100%
|
max-width: 100%
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* override style of base */
|
|
||||||
|
|
||||||
.message {
|
.message {
|
||||||
border: 1px dashed var(--text-color);
|
border: 1px dashed var(--text-color);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard__profile {
|
|
||||||
width: 150px;
|
|
||||||
height: 155px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard__profileSmall {
|
|
||||||
width: 59px;
|
|
||||||
height: 57px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard__abbr {
|
|
||||||
font-size: 50px;
|
|
||||||
width: 155px;
|
|
||||||
height: 155px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dashboard__abbrSmall {
|
|
||||||
font-size: 20px;
|
|
||||||
width: 59px;
|
|
||||||
height: 57px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.msger-inputarea {
|
.msger-inputarea {
|
||||||
position: fixed;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@@ -182,37 +146,6 @@ img.profile-photo {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
background: #ddd;
|
background: #ddd;
|
||||||
}
|
}
|
||||||
.msger-send-btn {
|
|
||||||
margin-left: 10px;
|
|
||||||
background: var(--cta-color);
|
|
||||||
color: #fff;
|
|
||||||
font-weight: bold;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background 0.23s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.discussion {
|
|
||||||
border: 1px solid var(--text-color);
|
|
||||||
padding: 10px;
|
|
||||||
margin: 10px;
|
|
||||||
border-radius: 10px;
|
|
||||||
background: var(--received-message);
|
|
||||||
width: 50%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.is-author {
|
|
||||||
float: right;
|
|
||||||
background: var(--send-message);
|
|
||||||
}
|
|
||||||
|
|
||||||
.batch-header {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
background: var(--bg);
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-section {
|
.message-section {
|
||||||
margin-left: 3%;
|
margin-left: 3%;
|
||||||
@@ -226,7 +159,109 @@ img.profile-photo {
|
|||||||
line-height: 51px;
|
line-height: 51px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.anchor_style {
|
section {
|
||||||
text-decoration: none;
|
padding: 5rem 0 5rem 0;
|
||||||
color: inherit;
|
}
|
||||||
|
|
||||||
|
.messages-container {
|
||||||
|
margin: 0 auto;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messages {
|
||||||
|
overflow: auto;
|
||||||
|
height: 450px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
padding: 8px;
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messages li {
|
||||||
|
background: #F7F5F5;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 8px;
|
||||||
|
margin: 2px 8px 2px 0;
|
||||||
|
width: 40%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messages li.ours {
|
||||||
|
align-self: flex-end;
|
||||||
|
margin: 2px 0 2px 8px;
|
||||||
|
background: var(--primary-color);
|
||||||
|
color: #fff
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-para {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.batch-header {
|
||||||
|
background: #eee;
|
||||||
|
border: 2px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.page-card {
|
||||||
|
max-width: 360px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 70px auto;
|
||||||
|
border: 1px solid #d1d8dd;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #fff;
|
||||||
|
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
.page-card .page-card-head {
|
||||||
|
padding: 10px 15px;
|
||||||
|
margin: -15px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
border-bottom: 1px solid #d1d8dd;
|
||||||
|
}
|
||||||
|
.page-card .page-card-head .indicator {
|
||||||
|
color: #36414C;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
.page-card .page-card-head .indicator::before {
|
||||||
|
margin: 0 6px 0.5px 0px;
|
||||||
|
}
|
||||||
|
.page-card .btn {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type=checkbox] {
|
||||||
|
appearance: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partiallycomplete {
|
||||||
|
background: #FEF4E2;
|
||||||
|
color: #976417;
|
||||||
|
}
|
||||||
|
|
||||||
|
.partiallycomplete img {
|
||||||
|
background: #976417;
|
||||||
|
}
|
||||||
|
|
||||||
|
.complete {
|
||||||
|
background: #EAF5EE;
|
||||||
|
color: #38A160;
|
||||||
|
}
|
||||||
|
|
||||||
|
.complete img {
|
||||||
|
background: #38A160;
|
||||||
|
}
|
||||||
|
|
||||||
|
.incomplete {
|
||||||
|
background: #FEECEC;
|
||||||
|
color: #E24C4C;
|
||||||
|
}
|
||||||
|
|
||||||
|
.incomplete img {
|
||||||
|
background: #E24C4C;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-image {
|
||||||
|
margin-right: 3px;
|
||||||
|
border-radius: 50px;
|
||||||
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ h2 {
|
|||||||
|
|
||||||
.teaser-body {
|
.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,11 +188,8 @@ section.lightgray {
|
|||||||
.chapter-number {
|
.chapter-number {
|
||||||
background: var(--text-color);
|
background: var(--text-color);
|
||||||
color: white;
|
color: white;
|
||||||
border-radius: 50%;
|
|
||||||
height: 24px;
|
height: 24px;
|
||||||
min-width: 24px;
|
min-width: 24px;
|
||||||
align-items: center;
|
|
||||||
padding: 5px 8px 2px 8px;
|
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +263,7 @@ section.lightgray {
|
|||||||
background-color: rgba(255, 255, 255, 0);
|
background-color: rgba(255, 255, 255, 0);
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
word-wrap: break-word;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
@@ -287,9 +294,7 @@ section.lightgray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.lesson-teaser {
|
.lesson-teaser {
|
||||||
font-weight: bold;
|
line-height: 40px;
|
||||||
color: black;
|
|
||||||
padding-left: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#hero h1 {
|
#hero h1 {
|
||||||
@@ -335,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;
|
||||||
|
}
|
||||||
|
|||||||
BIN
community/public/images/Vector.png
Normal file
BIN
community/public/images/Vector.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 B |
BIN
community/public/images/wallpaper.png
Normal file
BIN
community/public/images/wallpaper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 922 B |
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>
|
||||||
168
community/templates/livecode/extension_footer.html
Normal file
168
community/templates/livecode/extension_footer.html
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<script type="text/javascript" src="/assets/frappe/node_modules/moment/min/moment-with-locales.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/assets/frappe/js/frappe/utils/datetime.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
// comment_when is failing because of this
|
||||||
|
if (!frappe.sys_defaults) {
|
||||||
|
frappe.sys_defaults = {}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/assets/mon_school/js/livecode-files.js"></script>
|
||||||
|
|
||||||
|
<template id="livecode-template">
|
||||||
|
<div class="livecode-editor livecode-editor-inline">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-md-6">
|
||||||
|
<div class="controls">
|
||||||
|
<button class="run">Run</button>
|
||||||
|
|
||||||
|
<div class="exercise-controls pull-right">
|
||||||
|
<span style="padding-right: 10px;"><span class="last-submitted human-time" data-timestamp=""></span></span>
|
||||||
|
<button class="submit btn-primary">Submit</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="code-editor">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-md-6">
|
||||||
|
<div class="code-wrapper">
|
||||||
|
<textarea class="code"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4 col-md-6 canvas-wrapper">
|
||||||
|
<div class="svg-image" width="300" height="300"></div>
|
||||||
|
<pre class="output"></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function getLiveCodeOptions() {
|
||||||
|
return {
|
||||||
|
base_url: "{{ livecode_url }}",
|
||||||
|
runtime: "python",
|
||||||
|
files: LIVECODE_FILES, // loaded from livecode-files.js
|
||||||
|
command: ["python", "start.py"],
|
||||||
|
codemirror: true,
|
||||||
|
onMessage: {
|
||||||
|
image: function(editor, msg) {
|
||||||
|
const element = editor.parent.querySelector(".svg-image");
|
||||||
|
element.innerHTML = msg.image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
var editorLookup = {};
|
||||||
|
|
||||||
|
$("pre.example, pre.exercise").each((i, e) => {
|
||||||
|
var code = $(e).text();
|
||||||
|
var template = document.querySelector('#livecode-template');
|
||||||
|
var clone = template.content.cloneNode(true);
|
||||||
|
|
||||||
|
$(e)
|
||||||
|
.wrap('<div></div>')
|
||||||
|
.hide()
|
||||||
|
.parent()
|
||||||
|
.append(clone)
|
||||||
|
.find("textarea.code")
|
||||||
|
.val(code);
|
||||||
|
|
||||||
|
if ($(e).hasClass("exercise")) {
|
||||||
|
var last_submitted = $(e).data("last-submitted");
|
||||||
|
if (last_submitted) {
|
||||||
|
$(e).parent().find(".last-submitted")
|
||||||
|
.data("timestamp", last_submitted)
|
||||||
|
.html(__("Submitted {0}", [comment_when(last_submitted)]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(e).parent().find(".exercise-controls").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var editor = new LiveCodeEditor(e.parentElement, {
|
||||||
|
...getLiveCodeOptions(),
|
||||||
|
codemirror: true,
|
||||||
|
onMessage: {
|
||||||
|
image: function(editor, msg) {
|
||||||
|
const canvasElement = editor.parent.querySelector("div.svg-image");
|
||||||
|
canvasElement.innerHTML = msg.image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(e).parent().find(".submit").on('click', function() {
|
||||||
|
var name = $(e).data("name");
|
||||||
|
let code = editor.codemirror.doc.getValue();
|
||||||
|
|
||||||
|
frappe.call("community.lms.api.submit_solution", {
|
||||||
|
"exercise": name,
|
||||||
|
"code": code
|
||||||
|
}).then(r => {
|
||||||
|
if (r.message.name) {
|
||||||
|
frappe.msgprint("Submitted successfully!");
|
||||||
|
|
||||||
|
let d = r.message.creation;
|
||||||
|
$(e).parent().find(".human-time").html(__("Submitted {0}", [comment_when(d)]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".exercise-image").each((i, e) => {
|
||||||
|
var svg = JSON.parse($(e).data("image"));
|
||||||
|
$(e).html(svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("pre.exercise").each((i, e) => {
|
||||||
|
var svg = JSON.parse($(e).data("image"));
|
||||||
|
$(e).parent().find(".svg-image").html(svg);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
.svg-image {
|
||||||
|
border: 5px solid #ddd;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
width: 310px;
|
||||||
|
height: 310px;
|
||||||
|
}
|
||||||
|
.livecode-editor {
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.livecode-editor-small .svg-image {
|
||||||
|
border: 5px solid #ddd;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
width: 210px;
|
||||||
|
height: 210px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* work-in-progress styles for showing admonition */
|
||||||
|
.admonition {
|
||||||
|
border: 1px solid #aaa;
|
||||||
|
border-left: .5rem solid #888;
|
||||||
|
border-radius: .3em;
|
||||||
|
font-size: 0.9em;
|
||||||
|
margin: 1.5em 0;
|
||||||
|
padding: 0 0.5em;
|
||||||
|
}
|
||||||
|
.admonition-title {
|
||||||
|
padding: 0.5em 0px;
|
||||||
|
font-weight: bold;
|
||||||
|
padding-top:
|
||||||
|
}
|
||||||
|
</style>
|
||||||
8
community/templates/livecode/extension_header.html
Normal file
8
community/templates/livecode/extension_header.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.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>
|
||||||
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>
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% from "www/macros/common_macro.html" import InstructorsSection, MentorsSection %}
|
|
||||||
|
|
||||||
{% block title %}About{% endblock %}
|
{% block title %}About{% endblock %}
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
@@ -11,48 +8,33 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ CourseBasicDetail(course)}}
|
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||||
{{ InstructorsSection(course.get_instructor()) }}
|
<div class="tab-content" id="about">
|
||||||
{{ BatchDetails(batch)}}
|
{{ CourseBasicDetail(course)}}
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<div class="col-lg-4 col-md-12">
|
||||||
|
<div class="sidebar">
|
||||||
|
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% macro CourseBasicDetail(course) %}
|
{% macro CourseBasicDetail(course) %}
|
||||||
<h2>{{course.title}}</h2>
|
<h2>{{course.title}}</h2>
|
||||||
<div class="course-description">
|
<div class="course-description">
|
||||||
{{course.short_introduction}}
|
{{course.short_introduction}}
|
||||||
</div>
|
</div>
|
||||||
{% if course.video_link %}
|
{% if course.video_link %}
|
||||||
<div class="preview-video">
|
<div class="preview-video">
|
||||||
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||||
allowfullscreen></iframe>
|
allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h2>About the Course</h2>
|
<h2>About the Course</h2>
|
||||||
<div>{{frappe.utils.md_to_html(course.description)}}</div>
|
<div>{{frappe.utils.md_to_html(course.description)}}</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro BatchDetails(batch) %}
|
|
||||||
<h2>About the Batch</h2>
|
|
||||||
|
|
||||||
<div class="batch">
|
|
||||||
<div class="batch-details">
|
|
||||||
<div>Session every {{batch.sessions_on}}</div>
|
|
||||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
|
||||||
{{frappe.utils.format_time(batch.end_time, "short")}}</div>
|
|
||||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
|
||||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
|
||||||
|
|
||||||
{% for m in batch.get_mentors() %}
|
|
||||||
<div>
|
|
||||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
|
||||||
<span class="instructor-title">{{m.full_name}}</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endmacro %}
|
|
||||||
|
|||||||
@@ -3,5 +3,3 @@ from . import utils
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
utils.get_common_context(context)
|
utils.get_common_context(context)
|
||||||
|
|
||||||
print("context", context)
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% from "www/macros/common_macro.html" import BatchHearder %}
|
|
||||||
|
|
||||||
{% block title %}Discuss{% endblock %}
|
{% block title %}Discuss{% endblock %}
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
@@ -11,16 +9,14 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
|
|
||||||
<div class="">
|
<div class="container">
|
||||||
<div class="batch-header">
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
{{ BatchHearder(course.title, member_count) }}
|
<div class="messages-container mt-5">
|
||||||
</div>
|
{{ widgets.BatchHeader(batch_name=batch.title, member_count=member_count)}}
|
||||||
<div class="messages">
|
<ol class="messages">
|
||||||
<div class="message-section">
|
|
||||||
{{ Messages(messages) }}
|
{{ Messages(messages) }}
|
||||||
</div>
|
</ol>
|
||||||
{{ TextArea() }}
|
{{ TextArea() }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -28,25 +24,25 @@
|
|||||||
|
|
||||||
{% macro Messages(messages) %}
|
{% macro Messages(messages) %}
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<div class="discussion {% if message.is_author %} is-author {% endif %}">
|
<li class="{% if message.is_author %} ours {% endif %}">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<div class="font-weight-bold">
|
<div class="font-weight-bold">
|
||||||
{{ message.author_name }}
|
{{ message.author_name }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-muted">
|
<small class="">
|
||||||
{{ frappe.utils.pretty_date(message.creation) }}
|
{{ frappe.utils.format_datetime(message.creation, "dd-mm-yyyy HH:mm") }}
|
||||||
</div>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-5">
|
<div class="message-para">
|
||||||
{{ message.message }}
|
{{ message.message }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro TextArea() %}
|
{% macro TextArea() %}
|
||||||
<form class="msger-inputarea">
|
<form class="msger-inputarea mb-1">
|
||||||
<input type="text" class="msger-input" placeholder="Write your message...">
|
<input type="text" class="msger-input" placeholder="Write your message...">
|
||||||
<button type="submit" class="msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
<button type="submit" class="btn btn-primary msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
||||||
</form>
|
</form>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ frappe.ready(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
var message_element = document.getElementsByClassName("messages")[0]
|
||||||
|
message_element.scrollTo(0, message_element.scrollHeight);
|
||||||
|
document.getElementsByClassName("messages-container")[0].scrollIntoView({block: "center"})
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
$(".msger-send-btn").click((e) => {
|
$(".msger-send-btn").click((e) => {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
61
community/www/batch/home.html
Normal file
61
community/www/batch/home.html
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{% extends "templates/base.html" %}
|
||||||
|
{% block title %} Batch {% endblock %}
|
||||||
|
|
||||||
|
{% block head_include %}
|
||||||
|
<meta name="description" content="Courses" />
|
||||||
|
<meta name="keywords" content="" />
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container mt-5">
|
||||||
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
|
<div class="course-details mt-5">
|
||||||
|
{{ widgets.CourseOutline(course=course, batch=batch, show_link=membership, show_progress=True) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if batch %}
|
||||||
|
<div class="w-25">
|
||||||
|
<h3>Batch Schedule</h3>
|
||||||
|
{{ widgets.RenderBatch(course=course, batch=batch) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if batch.description %}
|
||||||
|
<div class="mt-5">
|
||||||
|
<h3>Batch Details</h3>
|
||||||
|
{{ frappe.utils.md_to_html(batch.description) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% if course.is_mentor(frappe.session.user) %}
|
||||||
|
{% set invite_link = frappe.utils.get_url() + "/courses/" + course.name + "/join?batch=" + batch.name %}
|
||||||
|
<div class="">
|
||||||
|
<h3> Invite Members </h3>
|
||||||
|
<a href="" class="" id="invite-link" data-link="{{ invite_link }}">Get Batch Invitation
|
||||||
|
Link</a>
|
||||||
|
<small id="copy-message" class="text-muted" style="display: none;">Copied to Clipboard.</small>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
frappe.ready(() => {
|
||||||
|
$("#invite-link").click((e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
var link_element = $("#invite-link");
|
||||||
|
var input_element = document.createElement("input");
|
||||||
|
input_element.value = link_element.attr("data-link")
|
||||||
|
document.body.appendChild(input_element);
|
||||||
|
input_element.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
input_element.remove();
|
||||||
|
$("#copy-message").slideDown(function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
$("#copy-message").slideUp();
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
5
community/www/batch/home.py
Normal file
5
community/www/batch/home.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
72
community/www/batch/join.html
Normal file
72
community/www/batch/join.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
% extends "templates/base.html" %}
|
||||||
|
{% block title %}Join a Course{% endblock %}
|
||||||
|
|
||||||
|
{% block head_include %}
|
||||||
|
<meta name="description" content="Join a Course"/>
|
||||||
|
<meta name="keywords" content="" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if frappe.session.user == "Guest" %}
|
||||||
|
|
||||||
|
<div class="page-card">
|
||||||
|
<div class='page-card-head'>
|
||||||
|
<span class='indicator blue password-box'>Login Required</span>
|
||||||
|
</div>
|
||||||
|
<div class=''>Please log in to confirm joining the course {{ batch.course_title }}.</div>
|
||||||
|
<a type="submit" id="login" class="btn btn-primary w-100"
|
||||||
|
href="/login?redirect-to=/courses/{{ batch.course }}/join?batch={{ batch.name }}">{{_("Login")}}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% elif already_a_member %}
|
||||||
|
|
||||||
|
<div class="page-card">
|
||||||
|
<div class='page-card-head'>
|
||||||
|
<span class='indicator blue password-box'>Already a member</span>
|
||||||
|
</div>
|
||||||
|
<div class=''>You are already a member of the batch {{ batch.title }} for the course {{ batch.course_title }}.
|
||||||
|
</div>
|
||||||
|
<a type="submit" id="batch-home" class="btn btn-primary w-100" href="">{{_("Go to Batch Home")}}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
<div class="page-card">
|
||||||
|
<div class='page-card-head'>
|
||||||
|
<span class='indicator blue password-box'>Confirm your membership</span>
|
||||||
|
</div>
|
||||||
|
<div>Please provide your confirmation to be a part of the batch {{ batch.title }} for the course
|
||||||
|
{{ batch.course_title }}.
|
||||||
|
</div>
|
||||||
|
<a type="submit" id="confirm" class="btn btn-primary w-100">{{_("Confirm")}}</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script>
|
||||||
|
frappe.ready(() => {
|
||||||
|
$("#confirm").click((e) => {
|
||||||
|
frappe.call({
|
||||||
|
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||||
|
"args": {
|
||||||
|
"batch": {{ batch.name }},
|
||||||
|
"course": {{ batch.course }}
|
||||||
|
},
|
||||||
|
"callback": (data) => {
|
||||||
|
if (data.message == "OK") {
|
||||||
|
frappe.msgprint({
|
||||||
|
message: __("You are now a member of this batch!"),
|
||||||
|
clear: true
|
||||||
|
});
|
||||||
|
setTimeout(function () {
|
||||||
|
window.location.href = "/courses/{{ batch.course }}/home";
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
8
community/www/batch/join.py
Normal file
8
community/www/batch/join.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
context.no_cache = 1
|
||||||
|
batch_name = frappe.form_dict["batch"]
|
||||||
|
context.batch = frappe.get_doc("LMS Batch", batch_name)
|
||||||
|
context.already_a_member = context.batch.is_member(frappe.session.user)
|
||||||
|
context.batch.course_title = frappe.db.get_value("LMS Course", context.batch.course, "title")
|
||||||
@@ -1,99 +1,72 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
{% block title %}{{ lesson.title }}{% endblock %}
|
{% block title %}{{ lesson.title }}{% endblock %}
|
||||||
|
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="{{lesson.title}} - {{course.title}}" />
|
<meta name="description" content="{{lesson.title}} - {{course.title}}" />
|
||||||
<meta name="keywords" content="{{lesson.title}} - {{course.title}}" />
|
<meta name="keywords" content="{{lesson.title}} - {{course.title}}" />
|
||||||
<style>
|
<style>
|
||||||
</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">
|
||||||
|
|
||||||
<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 %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
<div class="lesson-page">
|
<div class="lesson-page">
|
||||||
{{ pagination(prev_url, next_url) }}
|
|
||||||
|
|
||||||
<h2>{{ lesson.title }}</h2>
|
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-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_url, next_url) }}
|
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% macro pagination(prev_chap, prev_url, next_chap, next_url) %}
|
||||||
{% macro render_section(s) %}
|
<div class="lesson-pagination">
|
||||||
{% if s.type == "text" %}
|
{% if prev_url %}
|
||||||
{{ render_section_text(s) }}
|
<span>
|
||||||
{% elif s.type == "example" or s.type == "code" %}
|
Prev: <a href="{{prev_url}}">{{prev_chap}}</a>
|
||||||
{{ LiveCodeEditor(s.name,
|
</span>
|
||||||
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 %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% if next_url %}
|
||||||
|
<span class="pull-right">
|
||||||
{% macro render_section_text(s) %}
|
Next: <a href="{{next_url}}">{{next_chap}}</a>
|
||||||
<div class="row">
|
</span>
|
||||||
<div class="col-md-9">
|
{% endif %}
|
||||||
{{ frappe.utils.md_to_html(s.contents) }}
|
<div style="clear: both;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endmacro %}
|
|
||||||
|
|
||||||
{% macro pagination(prev_url, next_url) %}
|
|
||||||
<div class="lesson-pagination">
|
|
||||||
{% if prev_url %}
|
|
||||||
<a href="{{prev_url}}" class="btn">← Prev</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if next_url %}
|
|
||||||
<a href="{{next_url}}" class="btn pull-right">Next →</a>
|
|
||||||
{% endif %}
|
|
||||||
<div style="clear: both;"></div>
|
|
||||||
</div>
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{{ LiveCodeEditorJS() }}
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
var page_context = {{ page_context | tojson }};
|
||||||
var batch_name = "{{ batch.name }}";
|
</script>
|
||||||
var lesson_name = "{{ lesson.name }}";
|
|
||||||
|
|
||||||
frappe.call("community.lms.api.save_current_lesson", {
|
|
||||||
"batch_name": batch_name,
|
|
||||||
"lesson_name": lesson_name
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
{% for ext in page_extensions %}
|
||||||
|
{{ ext.render_footer() }}
|
||||||
|
{% endfor %}
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
|
|||||||
69
community/www/batch/learn.js
Normal file
69
community/www/batch/learn.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
frappe.ready(() => {
|
||||||
|
|
||||||
|
/* Save Lesson Progress */
|
||||||
|
if ($(".title").attr("data-membership") && !$(".title").hasClass("is_mentor")) {
|
||||||
|
frappe.call({
|
||||||
|
method: "community.lms.doctype.lesson.lesson.save_progress",
|
||||||
|
args: {
|
||||||
|
lesson: $(".title").attr("data-lesson"),
|
||||||
|
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,5 +1,9 @@
|
|||||||
|
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)
|
||||||
@@ -9,11 +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
|
||||||
batch_name = context.batch.name
|
|
||||||
|
|
||||||
if not chapter_index or not lesson_index:
|
if not chapter_index or not lesson_index:
|
||||||
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
|
if context.batch:
|
||||||
frappe.local.flags.redirect_location = get_learn_url(course_name, batch_name, index_)
|
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
|
||||||
|
else:
|
||||||
|
index_ = "1.1"
|
||||||
|
frappe.local.flags.redirect_location = context.course.get_learn_url(index_) + 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)
|
||||||
@@ -21,18 +26,36 @@ def get_context(context):
|
|||||||
context.chapter_index = chapter_index
|
context.chapter_index = chapter_index
|
||||||
|
|
||||||
outline = context.course.get_outline()
|
outline = context.course.get_outline()
|
||||||
next_ = outline.get_next(lesson_number)
|
|
||||||
prev_ = outline.get_prev(lesson_number)
|
prev_ = outline.get_prev(lesson_number)
|
||||||
context.next_url = get_learn_url(course_name, batch_name, next_)
|
next_ = outline.get_next(lesson_number)
|
||||||
context.prev_url = get_learn_url(course_name, batch_name, prev_)
|
context.prev_chap = get_chapter_title(course_name, prev_)
|
||||||
|
context.next_chap = get_chapter_title(course_name, next_)
|
||||||
|
context.next_url = context.course.get_learn_url(next_) and context.course.get_learn_url(next_) + context.course.query_parameter
|
||||||
|
context.prev_url = context.course.get_learn_url(prev_) and context.course.get_learn_url(prev_) + context.course.query_parameter
|
||||||
|
|
||||||
def get_learn_url(course_name, batch_name, lesson_number):
|
context.page_extensions = get_page_extensions()
|
||||||
|
|
||||||
|
context.page_context = {
|
||||||
|
"course": context.course.name,
|
||||||
|
"batch": context.get("batch") and context.batch.name,
|
||||||
|
"lesson": context.lesson.name
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_chapter_title(course_name, lesson_number):
|
||||||
if not lesson_number:
|
if not lesson_number:
|
||||||
return
|
return
|
||||||
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
|
lesson_split = cstr(lesson_number).split(".")
|
||||||
|
chapter_index = lesson_split[0]
|
||||||
|
lesson_index = lesson_split[1]
|
||||||
|
chapter_name = frappe.db.get_value("Chapter", {"course": course_name, "index_": chapter_index}, "name")
|
||||||
|
return frappe.db.get_value("Lesson", {"chapter": chapter_name, "index_": lesson_index}, "title")
|
||||||
|
|
||||||
def get_lesson_index(course, batch, user):
|
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.plugins.PageExtension"]
|
||||||
|
classnames = frappe.get_hooks("community_lesson_page_extensions") or default_value
|
||||||
|
extensions = [frappe.get_attr(name)() for name in classnames]
|
||||||
|
return extensions
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% from "www/macros/common_macro.html" import BatchHearder %}
|
|
||||||
|
|
||||||
{% block title %}Members{% endblock %}
|
{% block title %}Members{% endblock %}
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
@@ -10,10 +8,9 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ BatchHearder(course.title, member_count)}}
|
{{ widgets.BatchTabs(course=course, membership=membership) }}
|
||||||
{{ MembersList(members)}}
|
{{ MembersList(members)}}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -23,17 +20,24 @@
|
|||||||
<div class="mt-5">
|
<div class="mt-5">
|
||||||
{% for member in members %}
|
{% for member in members %}
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<div>
|
{{ widgets.Avatar(member=member, avatar_class="avatar-large") }}
|
||||||
{{ widgets.Avatar(member=member, avatar_class="avatar-medium") }}
|
<div class="d-flex flex-column ml-2">
|
||||||
|
<div class="d-flex">
|
||||||
|
<a class="anchor_style ml-2" href="/{{member.username}}">
|
||||||
|
<h3>{{ member.full_name }}</h3>
|
||||||
|
</a>
|
||||||
|
{% if course.is_mentor(member.name) %}
|
||||||
|
<div class="badge badge-success ml-2 align-self-start">Mentor</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% if member.bio %}
|
||||||
|
<i class="ml-2">{{member.bio}}</i>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-5 mr-5">
|
|
||||||
<a href="/{{member.username}}">{{ member.full_name }}</a>
|
|
||||||
</div>
|
|
||||||
{% if course.is_mentor(member.name) %}
|
|
||||||
<div class="badge badge-success">Mentor</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% if loop.index != member_count %}
|
||||||
<hr>
|
<hr>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -3,3 +3,5 @@ from . import utils
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
utils.get_common_context(context)
|
utils.get_common_context(context)
|
||||||
|
if not context.membership:
|
||||||
|
utils.redirect_to_lesson(context.course)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
{% block title %}{{ course.title }} - Batch Dashboard{% endblock %}
|
{% block title %}{{ course.title }} - Batch Dashboard{% endblock %}
|
||||||
|
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="{{course.title}} - Batch Dashboard" />
|
<meta name="description" content="{{course.title}} - Batch Dashboard" />
|
||||||
<meta name="keywords" content="{{course.title}} - Batch Dashboard" />
|
<meta name="keywords" content="{{course.title}} - Batch Dashboard" />
|
||||||
<style>
|
<style>
|
||||||
</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="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
||||||
@@ -23,23 +22,23 @@
|
|||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{{ 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>
|
||||||
<div class="livecode-editor-small">
|
<div class="livecode-editor-small">
|
||||||
{{ LiveCodeEditor(name=s.name, code=s.solution, reset_code=s.solution) }}
|
{{ LiveCodeEditor(name=s.name, code=s.solution, reset_code=s.solution) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,6 +46,6 @@
|
|||||||
|
|
||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{{ LiveCodeEditorJS() }}
|
{{ LiveCodeEditorJS() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -17,25 +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)
|
||||||
students_map = {s['email']: s for s in students}
|
if not len(students):
|
||||||
|
return []
|
||||||
|
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 (
|
||||||
@@ -46,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
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% block title %}Schedule{% endblock %}
|
{% block title %}Schedule{% endblock %}
|
||||||
|
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="" />
|
<meta name="keywords" content="" />
|
||||||
@@ -8,7 +8,10 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch) }}
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
{{ widgets.BatchTabs(course=course, batch=batch) }}
|
||||||
|
<h3>
|
||||||
|
Schedule
|
||||||
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -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"]
|
||||||
batch_name = frappe.form_dict["batch"]
|
try:
|
||||||
|
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
|
||||||
context.batch = batch
|
|
||||||
context.members = batch.get_mentors() + batch.get_students()
|
membership = course.get_membership(frappe.session.user, batch_name)
|
||||||
context.member_count = len(context.members)
|
if membership:
|
||||||
|
context.membership = membership
|
||||||
|
batch = course.get_batch(membership.batch)
|
||||||
|
|
||||||
|
if batch:
|
||||||
|
context.batch = batch
|
||||||
|
|
||||||
|
context.members = course.get_mentors(membership.batch) + course.get_students(membership.batch)
|
||||||
|
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
|
||||||
|
|||||||
@@ -1,35 +1,37 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/common_macro.html" import InstructorsSection, MentorsSection %}
|
{% from "www/macros/common_macro.html" import MentorsSection %}
|
||||||
{% block title %}{{ course.title }}{% endblock %}
|
{% block title %}{{ course.title }}{% endblock %}
|
||||||
{% 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 %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="course-header">
|
<div class="course-header">
|
||||||
<div class="course-type">course</div>
|
<div class="mb-5">
|
||||||
<h1 id="course-title" data-course="{{course.name}}">{{course.title}}</h1>
|
<a class="anchor_style" href="/courses">Courses</a> / <span class="text-muted">{{ course.title }}</span>
|
||||||
|
</div>
|
||||||
|
<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) }}
|
||||||
|
{{ widgets.InstructorSection(instructor=course.get_instructor()) }}
|
||||||
{{ BatchSection(course) }}
|
{{ BatchSection(course) }}
|
||||||
{{ CourseOutline(course) }}
|
{{ widgets.CourseOutline(course=course, show_link=membership) }}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-4 col-md-12">
|
|
||||||
<div class="sidebar">
|
|
||||||
{{ InstructorsSection(course.get_instructor()) }}
|
|
||||||
</div>
|
|
||||||
<div class="sidebar">
|
|
||||||
{{ MentorsSection(course.get_mentors(), course.is_mentor(frappe.session.user), course.name) }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -37,106 +39,73 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% macro CourseVideo(course) %}
|
{% macro CourseVideo(course) %}
|
||||||
{% if course.video_link %}
|
{% if course.video_link %}
|
||||||
<div class="preview-video">
|
<div class="preview-video">
|
||||||
<iframe
|
<iframe width="560" height="315" src="{{course.video_link}}" title="YouTube video player" frameborder="0"
|
||||||
width="560"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
||||||
height="315"
|
allowfullscreen></iframe>
|
||||||
src="{{course.video_link}}"
|
</div>
|
||||||
title="YouTube video player"
|
{% endif %}
|
||||||
frameborder="0"
|
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
||||||
allowfullscreen></iframe>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% 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) %}
|
||||||
{% if course.is_mentor(frappe.session.user) %}
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-md-12">
|
||||||
|
{% if course.is_mentor(frappe.session.user) %}
|
||||||
{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }}
|
{{ 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 %}
|
||||||
{% endmacro %}
|
|
||||||
|
|
||||||
{% macro RenderBatch(batch, can_manage=False) %}
|
|
||||||
<div class="batch">
|
|
||||||
<div class="batch-details">
|
|
||||||
<div>Session every {{batch.sessions_on}}</div>
|
|
||||||
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
|
|
||||||
{{frappe.utils.format_time(batch.end_time, "short")}}</div>
|
|
||||||
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
|
|
||||||
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
|
|
||||||
|
|
||||||
{% for m in batch.get_mentors() %}
|
|
||||||
<div>
|
|
||||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
|
||||||
<span class="instructor-title">{{m.full_name}}</span>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
<div class="cta">
|
|
||||||
<div class="">
|
|
||||||
{% if can_manage %}
|
|
||||||
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
|
|
||||||
{% else %}
|
|
||||||
<button class="join-batch" data-batch="{{ batch.name | urlencode }}"
|
|
||||||
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</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 %}
|
||||||
<div class="col-lg-4 col-md-6">
|
<div class="col-lg-4 col-md-6">
|
||||||
{{ RenderBatch(batch, can_manage=True) }}
|
{{ widgets.RenderBatch(course=course, batch=batch, can_manage=True) }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new batch</a>
|
<a class="add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.name}}">Add a new
|
||||||
{% else %}
|
batch</a>
|
||||||
<div class="mentor_message">
|
{% else %}
|
||||||
<p> You are a mentor for this course. </p>
|
<div class="mentor_message">
|
||||||
<a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}" >Create your first batch</a>
|
<p> You are a mentor for this course. </p>
|
||||||
</div>
|
<a class="" href="/add-a-new-batch?new=1&course={{course.name}}">Create your first batch</a>
|
||||||
{% endif %}
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro BatchSectionForStudents(course, upcoming_batches) %}
|
{% macro BatchSectionForStudents(course, upcoming_batches) %}
|
||||||
<h2>Upcoming Batches</h2>
|
{% if upcoming_batches %}
|
||||||
|
<div class="mt-5">
|
||||||
|
<h3 class="upcoming">Upcoming Batches</h3>
|
||||||
<div class="row">
|
<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">
|
||||||
{{ RenderBatch(batch, can_manage=False) }}
|
{{ widgets.RenderBatch(course=course, batch=batch, can_join=True) }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% else %}
|
||||||
|
<div class="mt-5 upcoming">There are no Upcoming Batches for this course currently.</div>
|
||||||
{% macro CourseOutline(course) %}
|
{% endif %}
|
||||||
<h2>Course Outline</h2>
|
</div>
|
||||||
|
|
||||||
{% for chapter in course.get_chapters() %}
|
|
||||||
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter)}}
|
|
||||||
{% endfor %}
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -1,72 +1,78 @@
|
|||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
if (frappe.session.user != "Guest") {
|
if (frappe.session.user != "Guest") {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
|
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
|
||||||
'args': {
|
'args': {
|
||||||
course: decodeURIComponent($("#course-title").attr("data-course")),
|
course: decodeURIComponent($("#course-title").attr("data-course")),
|
||||||
},
|
},
|
||||||
'callback': (data) => {
|
'callback': (data) => {
|
||||||
if (data.message > 0) {
|
if (data.message > 0) {
|
||||||
$("#mentor-request").addClass("hide");
|
$("#mentor-request").addClass("hide");
|
||||||
$("#already-applied").removeClass("hide")
|
$("#already-applied").removeClass("hide")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#apply-now").click((e) => {
|
$("#apply-now").click((e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
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/${$(e.currentTarget).attr("data-course")}`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frappe.call({
|
frappe.call({
|
||||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
|
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
|
||||||
"args": {
|
"args": {
|
||||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||||
},
|
},
|
||||||
"callback": (data) => {
|
"callback": (data) => {
|
||||||
if (data.message == "OK") {
|
if (data.message == "OK") {
|
||||||
$("#mentor-request").addClass("hide");
|
$("#mentor-request").addClass("hide");
|
||||||
$("#already-applied").removeClass("hide")
|
$("#already-applied").removeClass("hide")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
$("#cancel-request").click((e) => {
|
$("#cancel-request").click((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
frappe.call({
|
frappe.call({
|
||||||
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
|
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
|
||||||
"args": {
|
"args": {
|
||||||
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
|
||||||
},
|
},
|
||||||
"callback": (data) => {
|
"callback": (data) => {
|
||||||
if (data.message == "OK") {
|
if (data.message == "OK") {
|
||||||
$("#mentor-request").removeClass("hide");
|
$("#mentor-request").removeClass("hide");
|
||||||
$("#already-applied").addClass("hide")
|
$("#already-applied").addClass("hide")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
$(".join-batch").click((e) => {
|
$(".join-batch").click((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault();
|
||||||
if (frappe.session.user == "Guest") {
|
var course = $(e.currentTarget).attr("data-course")
|
||||||
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
if (frappe.session.user == "Guest") {
|
||||||
return;
|
window.location.href = `/login?redirect-to=/courses/${course}`;
|
||||||
}
|
return;
|
||||||
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
}
|
||||||
frappe.call({
|
var batch = $(e.currentTarget).attr("data-batch");
|
||||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
batch = batch ? decodeURIComponent(batch) : "";
|
||||||
"args": {
|
frappe.call({
|
||||||
"batch": batch
|
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
||||||
},
|
"args": {
|
||||||
"callback": (data) => {
|
"batch": batch ? batch : "",
|
||||||
if (data.message == "OK") {
|
"course": course
|
||||||
frappe.msgprint(__("You are now a student of this course."))
|
},
|
||||||
}
|
"callback": (data) => {
|
||||||
}
|
if (data.message == "OK") {
|
||||||
})
|
frappe.msgprint(__("You are now a student of this course."));
|
||||||
})
|
setTimeout(function () {
|
||||||
|
window.location.href = `/courses/${course}/home`;
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
|
{% from "www/hackathons/macros/card.html" import null_card %}
|
||||||
{% block title %}{{ 'Courses' }}{% endblock %}
|
{% block title %}{{ 'Courses' }}{% endblock %}
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="{{ 'Courses' }}" />
|
<meta name="description" content="{{ 'Courses' }}" />
|
||||||
<meta name="keywords" content="Courses" />
|
<meta name="keywords" content="Courses" />
|
||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% 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 %}
|
||||||
|
{% for n in range( (3 - (courses|length)) %3) %}
|
||||||
|
{{ null_card() }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %} -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -24,13 +28,18 @@
|
|||||||
|
|
||||||
|
|
||||||
{% macro course_card(course) %}
|
{% macro course_card(course) %}
|
||||||
<div class="card mb-5 w-100">
|
<div class="col-sm-4 mb-4 text-left">
|
||||||
<div class="card-body">
|
<a class="anchor_style" style="color: inherit;" href="/courses/{{course.name}}">
|
||||||
<h5 class="card-title"><a href="/courses/{{course.name}}">{{course.title}}</a></h5>
|
<div class="card h-100" style="box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);">
|
||||||
{% if course.description %}
|
<div class='card-body'>
|
||||||
<p class="card-text">{{ frappe.utils.md_to_html(course.description[:250]) }}</p>
|
<h5 class='card-title'>{{ course.title }}</h5>
|
||||||
{% endif %}
|
{% if course.description %}
|
||||||
<a href="/courses/{{course.name}}" class="card-link">See more →</a>
|
<div class="mt-4">
|
||||||
</div>
|
{{ frappe.utils.md_to_html(course.description[:200]) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
frappe.ready(() => {
|
|
||||||
|
|
||||||
})
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user