Compare commits
154 Commits
style-fixe
...
discussion
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3672e9d91 | ||
|
|
6c9d49bf8c | ||
|
|
2de058246b | ||
|
|
798ea30382 | ||
|
|
83a2f42df9 | ||
|
|
66aace247c | ||
|
|
bc3db06960 | ||
|
|
ddaa063587 | ||
|
|
f9b4fe468e | ||
|
|
6cbca8d1bb | ||
|
|
d5067a4bcd | ||
|
|
04d44510de | ||
|
|
844fcc9bca | ||
|
|
145b5efab0 | ||
|
|
4079ed97b9 | ||
|
|
63d70fc037 | ||
|
|
ce86b5deda | ||
|
|
037e946bbe | ||
|
|
a51c8de1eb | ||
|
|
53dc517180 | ||
|
|
44ca940c6b | ||
|
|
c0b688c720 | ||
|
|
861d5f231d | ||
|
|
d14b4f55a6 | ||
|
|
db9a6c3eda | ||
|
|
a667643681 | ||
|
|
f278e4b6a5 | ||
|
|
33a12c2dec | ||
|
|
508f90f459 | ||
|
|
709f0c2274 | ||
|
|
be47700e7c | ||
|
|
40842830a4 | ||
|
|
11d070fa0d | ||
|
|
dd2f830a33 | ||
|
|
5431fcb450 | ||
|
|
324033e9ee | ||
|
|
86596d0cfe | ||
|
|
9323cfd748 | ||
|
|
d125b02cec | ||
|
|
282c4c5351 | ||
|
|
276d64a66a | ||
|
|
79eb381a41 | ||
|
|
44f9c0dfd3 | ||
|
|
0ca4cd724e | ||
|
|
8a3e31f021 | ||
|
|
9be8a1af0b | ||
|
|
b9cac20613 | ||
|
|
e6d5e6d37b | ||
|
|
0abfcac7da | ||
|
|
b70e8b9acc | ||
|
|
3b1e1aa3c3 | ||
|
|
8f74c74d50 | ||
|
|
d2f435016c | ||
|
|
389b35802b | ||
|
|
a9192a74f9 | ||
|
|
1366c7cf75 | ||
|
|
eaa9e8e3ea | ||
|
|
5ecae0df61 | ||
|
|
4891be1d8c | ||
|
|
ec852fc255 | ||
|
|
47f2d3cb7b | ||
|
|
37820c1e19 | ||
|
|
230fab3bb2 | ||
|
|
d292d2d093 | ||
|
|
51d5db01e9 | ||
|
|
0fd760df81 | ||
|
|
71d0a89968 | ||
|
|
d939a63412 | ||
|
|
daaa2d2fe2 | ||
|
|
6dd7cb19df | ||
|
|
b1de2481a8 | ||
|
|
27c01b3b0c | ||
|
|
b7aa9aff51 | ||
|
|
524a041fb9 | ||
|
|
9de0203914 | ||
|
|
0ed5309b97 | ||
|
|
68fd32d536 | ||
|
|
5ea3b25d21 | ||
|
|
2c24412633 | ||
|
|
1b8a45ba4a | ||
|
|
3dd4adbc1f | ||
|
|
0c52c9c4bc | ||
|
|
9caf44cdbd | ||
|
|
45d88bdc08 | ||
|
|
94b3ccd3d9 | ||
|
|
ee8273fd30 | ||
|
|
60c1449f40 | ||
|
|
67708325ae | ||
|
|
3e99577401 | ||
|
|
5e916dc2c8 | ||
|
|
0c64d46e99 | ||
|
|
3aa974f8bd | ||
|
|
621d01d502 | ||
|
|
aa20136223 | ||
|
|
9bc5408a44 | ||
|
|
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 | ||
|
|
3648b3ab47 | ||
|
|
823cf4e431 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,3 +5,6 @@
|
||||
tags
|
||||
community/docs/current
|
||||
community/public/dist
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Discussion Message', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -1,67 +1,53 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-03-19 12:19:32.355307",
|
||||
"creation": "2021-08-11 10:59:38.597046",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"author",
|
||||
"batch",
|
||||
"column_break_3",
|
||||
"author_name",
|
||||
"pin",
|
||||
"section_break_6",
|
||||
"thread",
|
||||
"column_break_2",
|
||||
"parent_message",
|
||||
"section_break_4",
|
||||
"message"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "batch",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Batch",
|
||||
"options": "LMS Batch"
|
||||
},
|
||||
{
|
||||
"fieldname": "author",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Author",
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fieldname": "message",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"fieldtype": "Long Text",
|
||||
"in_list_view": 1,
|
||||
"label": "Message"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "pin",
|
||||
"fieldtype": "Check",
|
||||
"label": "Pin"
|
||||
"fieldname": "thread",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Thread",
|
||||
"options": "Discussion Thread"
|
||||
},
|
||||
{
|
||||
"fetch_from": "author.full_name",
|
||||
"fieldname": "author_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Author Name",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldname": "column_break_2",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldname": "parent_message",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Parent Message",
|
||||
"options": "Discussion Message"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_4",
|
||||
"fieldtype": "Section Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-21 11:49:34.911479",
|
||||
"modified": "2021-08-12 15:59:04.811286",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Message",
|
||||
"module": "Community",
|
||||
"name": "Discussion Message",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -77,9 +63,7 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "author",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from community.widgets import Widget, Widgets
|
||||
|
||||
class DiscussionMessage(Document):
|
||||
def after_insert(self):
|
||||
data = {
|
||||
"message": self,
|
||||
"widgets": Widgets()
|
||||
}
|
||||
template = frappe.render_template("community/templates/message_card.html", data)
|
||||
thread_info = frappe.db.get_value("Discussion Thread", self.thread, ["reference_doctype", "reference_docname"], as_dict=True)
|
||||
frappe.publish_realtime(event="publish_message",
|
||||
message = {
|
||||
"thread": self.thread,
|
||||
"template": template,
|
||||
"thread_info": thread_info
|
||||
},
|
||||
after_commit=True)
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSSketch(unittest.TestCase):
|
||||
class TestDiscussionMessage(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Code Revision', {
|
||||
frappe.ui.form.on('Discussion Thread', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-08-11 10:55:29.341674",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"reference_doctype",
|
||||
"reference_docname"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "reference_doctype",
|
||||
"fieldtype": "Link",
|
||||
"label": "Reference Doctype",
|
||||
"options": "DocType"
|
||||
},
|
||||
{
|
||||
"fieldname": "reference_docname",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"label": "Reference Docname",
|
||||
"options": "reference_doctype"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-08-11 12:29:43.564123",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Community",
|
||||
"name": "Discussion Thread",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"search_fields": "title",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class DiscussionThread(Document):
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def submit_discussion(doctype, docname, message, title=None, thread_name=None):
|
||||
thread = []
|
||||
filters = {}
|
||||
if doctype and docname:
|
||||
filters = {
|
||||
"reference_doctype": doctype,
|
||||
"reference_docname": docname
|
||||
}
|
||||
|
||||
elif thread_name:
|
||||
filters = {
|
||||
"name": thread_name
|
||||
}
|
||||
|
||||
if filters:
|
||||
thread = frappe.get_all("Discussion Thread",filters)
|
||||
if len(thread):
|
||||
thread = thread[0]
|
||||
save_message(message, thread)
|
||||
|
||||
else:
|
||||
thread = frappe.get_doc({
|
||||
"doctype": "Discussion Thread",
|
||||
"title": title,
|
||||
"reference_doctype": doctype,
|
||||
"reference_docname": docname
|
||||
})
|
||||
thread.save(ignore_permissions=True)
|
||||
save_message(message, thread)
|
||||
|
||||
return thread.name
|
||||
|
||||
def save_message(message, thread):
|
||||
frappe.get_doc({
|
||||
"doctype": "Discussion Message",
|
||||
"message": message,
|
||||
"thread": thread.name
|
||||
}).save(ignore_permissions=True)
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSMessage(unittest.TestCase):
|
||||
class TestDiscussionThread(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,5 +1,5 @@
|
||||
{% set color = member.get_palette() %}
|
||||
<a href="/{{member.username}}">
|
||||
<a class="button-links" href="/{{member.username}}">
|
||||
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
||||
{% if member.user_image %}
|
||||
<img class="avatar-frame standard-image" style="object-fit: cover;" src="{{ member.user_image }}" title="{{ member.full_name }}">
|
||||
|
||||
70
community/community/widgets/DiscussionComment.html
Normal file
70
community/community/widgets/DiscussionComment.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<div class="discussions">
|
||||
|
||||
<form class="discussion-form {% if doctype or thread %} discussion-on-page {% endif %}" id="discussion-form">
|
||||
|
||||
|
||||
<div class="form-group" {% if title or thread %} style="display: none;" {% endif %}>
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<input type="text" autocomplete="off" class="input-with-feedback form-control thread-title"
|
||||
data-fieldtype="Data" data-fieldname="feedback_comments" placeholder="Title" spellcheck="false" {% if title
|
||||
%} value="{{ title }}" {% endif %}></input>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<textarea type="text" autocomplete="off" class="input-with-feedback form-control comment-field"
|
||||
data-fieldtype="Text" data-fieldname="feedback_comments" placeholder="Enter a comment..."
|
||||
spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="comment-footer">
|
||||
<div class="button is-secondary pull-right" id="submit-discussion"
|
||||
{% if doctype %} data-doctype="{{ doctype | urlencode}}" {% endif %}
|
||||
{% if docname %} data-docname="{{ docname | urlencode}}" {% endif %}
|
||||
{% if thread %} data-thread="{{ thread }}" {% endif %}>
|
||||
Post</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
$("#submit-discussion").click((e) => {
|
||||
submit_discussion(e);
|
||||
})
|
||||
})
|
||||
|
||||
var submit_discussion = (e) => {
|
||||
var message = $(".comment-field").val().trim();
|
||||
|
||||
if (message) {
|
||||
var doctype = $(e.currentTarget).attr("data-doctype");
|
||||
doctype = doctype ? decodeURIComponent(doctype) : doctype;
|
||||
|
||||
var docname = $(e.currentTarget).attr("data-docname");
|
||||
docname = docname ? decodeURIComponent(docname) : docname;
|
||||
|
||||
frappe.call({
|
||||
method: "community.community.doctype.discussion_thread.discussion_thread.submit_discussion",
|
||||
args: {
|
||||
"doctype": doctype ? doctype : "",
|
||||
"docname": docname ? docname : "",
|
||||
"message": $(".comment-field").val(),
|
||||
"title": $(".thread-title").val(),
|
||||
"thread_name": $(e.currentTarget).attr("data-thread")
|
||||
},
|
||||
callback: (data) => {
|
||||
if (! $(".discussion-on-page").length) {
|
||||
$("#discussion-modal").modal("hide");
|
||||
window.location.href = `/discussions/${data.message}`;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
80
community/community/widgets/DiscussionMessage.html
Normal file
80
community/community/widgets/DiscussionMessage.html
Normal file
@@ -0,0 +1,80 @@
|
||||
{% if doctype and docname and not thread %}
|
||||
|
||||
{% set thread_info = frappe.get_all("Discussion Thread", {"reference_doctype": doctype, "reference_docname": docname},
|
||||
["name"]) %}
|
||||
|
||||
{% if thread_info | length %}
|
||||
{% set thread = thread_info[0].name %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if thread %}
|
||||
{% set messages = frappe.get_all("Discussion Message", {"thread": thread}, ["name", "message", "owner", "creation"],
|
||||
order_by="creation") %}
|
||||
{% endif %}
|
||||
|
||||
{% if doctype %}
|
||||
<div class="course-home-headings mt-5"> Discussions </div>
|
||||
{% endif %}
|
||||
|
||||
<div class="messages mt-5">
|
||||
{% for message in messages %}
|
||||
{% include "community/templates/message_card.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if frappe.session.user == "Guest" or (condition is defined and not condition) %}
|
||||
<div class="d-flex flex-column align-items-center font-weight-bold">
|
||||
Want to join the discussion?
|
||||
{% if frappe.session.user == "Guest" %}
|
||||
<div class="button is-primary" id="login-from-discussion">Log In</div>
|
||||
{% elif not condition %}
|
||||
<div class="button is-primary" id="login-from-discussion" data-redirect="{{ redirect_to }}">{{ button_name }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ widgets.DiscussionComment(doctype=doctype, docname=docname, title=title, thread=thread ) }}
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
setup_socket_io();
|
||||
|
||||
$("#login-from-discussion").click((e) => {
|
||||
login_from_discussion(e);
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
var setup_socket_io = () => {
|
||||
const assets = [
|
||||
"/assets/frappe/js/lib/socket.io.min.js",
|
||||
"/assets/frappe/js/frappe/socketio_client.js",
|
||||
]
|
||||
frappe.require(assets, () => {
|
||||
|
||||
if (window.dev_server) {
|
||||
frappe.boot.socketio_port = "9000";
|
||||
}
|
||||
|
||||
frappe.socketio.init(9000);
|
||||
var target = $("#submit-discussion");
|
||||
|
||||
frappe.socketio.socket.on("publish_message", (data) => {
|
||||
if (target.attr("data-thread") == data.thread
|
||||
|| (decodeURIComponent(target.attr("data-doctype")) == data.thread_info.reference_doctype
|
||||
&& decodeURIComponent(target.attr("data-docname")) == data.thread_info.reference_docname)) {
|
||||
$(".comment-field").val("");
|
||||
$(".messages").append(data.template);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
var login_from_discussion = (e) => {
|
||||
var redirect = $(e.currentTarget).attr("data-redirect") || window.location.href;
|
||||
window.location.href = `/login?redirect-to=${redirect}`;
|
||||
}
|
||||
|
||||
</script>
|
||||
373
community/fixtures/custom_field.json
Normal file
373
community/fixtures/custom_field.json
Normal file
@@ -0,0 +1,373 @@
|
||||
[
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "linkedin",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "mobile_no",
|
||||
"label": "LinkedIn ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-linkedin",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "github",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "linkedin",
|
||||
"label": "Github ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-github",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "medium",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "github",
|
||||
"label": "Medium ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-medium",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "city",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "mute_sounds",
|
||||
"label": "City",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-city",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "college",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "city",
|
||||
"label": "College Name",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-college",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "branch",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "college",
|
||||
"label": "Branch",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-branch",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "profession",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "medium",
|
||||
"label": "Profession",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-profession",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
]
|
||||
@@ -3,13 +3,14 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
class CommunityProjectMember(Document):
|
||||
def validate(self):
|
||||
self.validate_if_already_member()
|
||||
|
||||
|
||||
def validate_if_already_member(self):
|
||||
if frappe.get_all("Community Project Member", {"owner": self.owner}):
|
||||
frappe.throw(_("You have already applied for the membership of this project."))
|
||||
|
||||
@@ -104,6 +104,8 @@ doc_events = {
|
||||
# ]
|
||||
#}
|
||||
|
||||
fixtures = ["Custom Field"]
|
||||
|
||||
# Testing
|
||||
# -------
|
||||
|
||||
@@ -134,16 +136,17 @@ primary_rules = [
|
||||
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
|
||||
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
|
||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||
{"from_route": "/dashboard", "to_route": ""},
|
||||
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
||||
{"from_route": "/courses/<course>/<batch>/home", "to_route": "batch/home"},
|
||||
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
|
||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
|
||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
|
||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
|
||||
{"from_route": "/courses/<course>/<batch>/progress", "to_route": "batch/progress"}
|
||||
{"from_route": "/courses/<course>/home", "to_route": "batch/home"},
|
||||
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/schedule", "to_route": "batch/schedule"},
|
||||
{"from_route": "/courses/<course>/members", "to_route": "batch/members"},
|
||||
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
|
||||
{"from_route": "/courses/<course>/about", "to_route": "batch/about"},
|
||||
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
|
||||
{"from_route": "/courses/<course>/join", "to_route": "batch/join"},
|
||||
{"from_route": "/discussions/<discussion>", "to_route": "discussions/discussion"}
|
||||
]
|
||||
|
||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||
@@ -160,10 +163,13 @@ whitelist = [
|
||||
"/socket.io",
|
||||
"/hackathons",
|
||||
"/dashboard",
|
||||
"/join-request"
|
||||
"/join-request",
|
||||
"/add-a-new-batch",
|
||||
"/new-sign-up",
|
||||
"/message"
|
||||
"/message",
|
||||
"/about",
|
||||
"/edit-profile",
|
||||
"/discussions"
|
||||
]
|
||||
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
|
||||
|
||||
@@ -174,4 +180,28 @@ profile_rules = [
|
||||
|
||||
website_route_rules = primary_rules + whitelist_rules + profile_rules
|
||||
|
||||
website_redirects = [
|
||||
{"source": "/update-profile", "target": "/edit-profile"},
|
||||
]
|
||||
|
||||
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()
|
||||
return {"name": doc.name}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_section(name):
|
||||
"""Saves the code edited in one of the sections.
|
||||
"""
|
||||
doc = frappe.get_doc("LMS Section", name)
|
||||
return doc and doc.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
def submit_solution(exercise, code):
|
||||
"""Submits a solution.
|
||||
@@ -36,14 +29,14 @@ def submit_solution(exercise, code):
|
||||
return {"name": doc.name, "creation": doc.creation}
|
||||
|
||||
@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.
|
||||
"""
|
||||
name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"batch": batch_name,
|
||||
"member_email": frappe.session.user
|
||||
"course": course_name,
|
||||
"member": frappe.session.user
|
||||
},
|
||||
fieldname="name")
|
||||
if not name:
|
||||
|
||||
@@ -2,7 +2,15 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Chapter', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function (frm) {
|
||||
frm.set_query("lesson", "lessons", function () {
|
||||
return {
|
||||
filters: {
|
||||
"chapter": frm.doc.name,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
"course",
|
||||
"title",
|
||||
"description",
|
||||
"locked",
|
||||
"index_"
|
||||
"lessons"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -24,12 +23,6 @@
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Description"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "locked",
|
||||
"fieldtype": "Check",
|
||||
"label": "Locked"
|
||||
},
|
||||
{
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
@@ -38,10 +31,10 @@
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "index_",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index"
|
||||
"fieldname": "lessons",
|
||||
"fieldtype": "Table",
|
||||
"label": "Lessons",
|
||||
"options": "Lessons"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
@@ -52,7 +45,7 @@
|
||||
"link_fieldname": "chapter"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-13 21:05:20.531890",
|
||||
"modified": "2021-07-27 16:28:08.667964",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Chapter",
|
||||
|
||||
@@ -7,9 +7,4 @@ import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Chapter(Document):
|
||||
def get_lessons(self):
|
||||
rows = frappe.db.get_all("Lesson",
|
||||
filters={"chapter": self.name},
|
||||
fields='*',
|
||||
order_by="index_")
|
||||
return [frappe.get_doc(dict(row, doctype='Lesson')) for row in rows]
|
||||
pass
|
||||
|
||||
32
community/lms/doctype/chapters/chapters.json
Normal file
32
community/lms/doctype/chapters/chapters.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-07-27 16:25:02.903245",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"chapter"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-27 16:25:02.903245",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Chapters",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CodeRevision(Document):
|
||||
class Chapters(Document):
|
||||
pass
|
||||
@@ -15,7 +15,9 @@
|
||||
"hints",
|
||||
"tests",
|
||||
"image",
|
||||
"lesson"
|
||||
"lesson",
|
||||
"index_",
|
||||
"index_label"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -27,6 +29,7 @@
|
||||
{
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
@@ -73,13 +76,27 @@
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "index_",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-20 13:23:12.340928",
|
||||
"modified": "2021-06-01 05:22:15.656013",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Exercise",
|
||||
@@ -99,8 +116,8 @@
|
||||
}
|
||||
],
|
||||
"search_fields": "title",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"sort_field": "index_label",
|
||||
"sort_order": "ASC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -3,12 +3,8 @@
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ..lms_sketch.livecode import livecode_to_svg
|
||||
|
||||
class Exercise(Document):
|
||||
def before_save(self):
|
||||
self.image = livecode_to_svg(None, self.answer)
|
||||
|
||||
def get_user_submission(self):
|
||||
"""Returns the latest submission for this user.
|
||||
"""
|
||||
@@ -25,7 +21,6 @@ class Exercise(Document):
|
||||
order_by="creation desc",
|
||||
page_length=1)
|
||||
|
||||
print("get_user_submission", result)
|
||||
if result:
|
||||
return result[0]
|
||||
|
||||
@@ -43,8 +38,6 @@ class Exercise(Document):
|
||||
course = frappe.get_doc("LMS Course", self.course)
|
||||
batch = course.get_student_batch(user)
|
||||
|
||||
image = livecode_to_svg(None, code)
|
||||
|
||||
doc = frappe.get_doc(
|
||||
doctype="Exercise Submission",
|
||||
exercise=self.name,
|
||||
@@ -52,8 +45,8 @@ class Exercise(Document):
|
||||
course=self.course,
|
||||
lesson=self.lesson,
|
||||
batch=batch and batch.name,
|
||||
image=image,
|
||||
solution=code)
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
@@ -6,12 +6,17 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"exercise",
|
||||
"solution",
|
||||
"status",
|
||||
"batch",
|
||||
"column_break_4",
|
||||
"exercise_title",
|
||||
"course",
|
||||
"batch",
|
||||
"lesson",
|
||||
"image"
|
||||
"section_break_8",
|
||||
"solution",
|
||||
"image",
|
||||
"test_results",
|
||||
"comments"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -21,12 +26,6 @@
|
||||
"label": "Exercise",
|
||||
"options": "Exercise"
|
||||
},
|
||||
{
|
||||
"fieldname": "solution",
|
||||
"fieldtype": "Code",
|
||||
"in_list_view": 1,
|
||||
"label": "Solution"
|
||||
},
|
||||
{
|
||||
"fetch_from": "exercise.title",
|
||||
"fieldname": "exercise_title",
|
||||
@@ -61,11 +60,41 @@
|
||||
"fieldtype": "Code",
|
||||
"label": "Image",
|
||||
"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,
|
||||
"links": [],
|
||||
"modified": "2021-05-21 11:28:45.833018",
|
||||
"modified": "2021-06-24 16:22:50.570845",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Exercise Submission",
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ..lesson.lesson import update_progress
|
||||
|
||||
class ExerciseSubmission(Document):
|
||||
pass
|
||||
|
||||
def after_insert(self):
|
||||
course_details = frappe.get_doc("LMS Course", self.course)
|
||||
if not (course_details.is_mentor(frappe.session.user) or frappe.flags.in_test):
|
||||
update_progress(self.lesson)
|
||||
|
||||
@@ -30,10 +30,13 @@ class InviteRequest(Document):
|
||||
return user
|
||||
|
||||
def send_email(self):
|
||||
subject = _("Your request has been approved.")
|
||||
site_name = "Mon.School"
|
||||
subject = _("Welcome to {0}!").format(site_name)
|
||||
|
||||
args = {
|
||||
"full_name": self.full_name,
|
||||
"signup_form_link": "/new-sign-up?invite_code={0}".format(self.name),
|
||||
"site_name": site_name,
|
||||
"site_url": frappe.utils.get_url()
|
||||
}
|
||||
frappe.sendmail(
|
||||
@@ -42,7 +45,8 @@ class InviteRequest(Document):
|
||||
subject=subject,
|
||||
header=[subject, "green"],
|
||||
template = "lms_invite_request_approved",
|
||||
args=args)
|
||||
args=args,
|
||||
now=True)
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def create_invite_request(invite_email):
|
||||
@@ -58,7 +62,8 @@ def create_invite_request(invite_email):
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "Invite Request",
|
||||
"invite_email": invite_email
|
||||
"invite_email": invite_email,
|
||||
"status": "Approved"
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestInviteRequest(unittest.TestCase):
|
||||
filters={"invite_email": "test_invite@example.com"},
|
||||
fieldname=["invite_email", "status", "signup_email"],
|
||||
as_dict=True)
|
||||
self.assertEqual(invite.status, "Pending")
|
||||
self.assertEqual(invite.status, "Approved")
|
||||
self.assertEqual(invite.signup_email, None)
|
||||
|
||||
def test_create_invite_request_update(self):
|
||||
|
||||
@@ -2,7 +2,47 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
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,14 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"chapter",
|
||||
"lesson_type",
|
||||
"include_in_preview",
|
||||
"column_break_4",
|
||||
"title",
|
||||
"index_",
|
||||
"index_label",
|
||||
"section_break_6",
|
||||
"body",
|
||||
"sections"
|
||||
"help_section",
|
||||
"help"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -21,41 +24,50 @@
|
||||
"label": "Chapter",
|
||||
"options": "Chapter"
|
||||
},
|
||||
{
|
||||
"default": "Video",
|
||||
"fieldname": "lesson_type",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson Type",
|
||||
"options": "Video\nText\nQuiz"
|
||||
},
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "index_",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index"
|
||||
},
|
||||
{
|
||||
"fieldname": "body",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Body"
|
||||
},
|
||||
{
|
||||
"fieldname": "sections",
|
||||
"fieldtype": "Table",
|
||||
"label": "Sections",
|
||||
"options": "LMS Section"
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "include_in_preview",
|
||||
"fieldtype": "Check",
|
||||
"label": "Include In Preview"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "help_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Help"
|
||||
},
|
||||
{
|
||||
"fieldname": "help",
|
||||
"fieldtype": "HTML"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-13 20:03:51.510605",
|
||||
"modified": "2021-07-27 16:28:29.203624",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Lesson",
|
||||
|
||||
@@ -5,41 +5,128 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ...section_parser import SectionParser
|
||||
from ...md import markdown_to_html, find_macros
|
||||
|
||||
class Lesson(Document):
|
||||
def before_save(self):
|
||||
sections = SectionParser().parse(self.body or "")
|
||||
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
|
||||
for s in self.sections:
|
||||
if s.type == "exercise":
|
||||
e = s.get_exercise()
|
||||
e.lesson = self.name
|
||||
e.save()
|
||||
dynamic_documents = ["Exercise", "Quiz"]
|
||||
for section in dynamic_documents:
|
||||
self.update_lesson_name_in_document(section)
|
||||
|
||||
def get_sections(self):
|
||||
return sorted(self.get('sections'), key=lambda s: s.index)
|
||||
def update_lesson_name_in_document(self, section):
|
||||
doctype_map= {
|
||||
"Exercise": "Exercise",
|
||||
"Quiz": "LMS Quiz"
|
||||
}
|
||||
macros = find_macros(self.body)
|
||||
documents = [value for name, value in macros if name == section]
|
||||
index = 1
|
||||
for name in documents:
|
||||
e = frappe.get_doc(doctype_map[section], name)
|
||||
e.lesson = self.name
|
||||
e.index_ = index
|
||||
e.save()
|
||||
index += 1
|
||||
self.update_orphan_documents(doctype_map[section], documents)
|
||||
|
||||
def make_lms_section(self, index, section):
|
||||
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
|
||||
s.type = section.type
|
||||
s.id = section.id
|
||||
s.label = section.label
|
||||
s.contents = section.contents
|
||||
s.index = index
|
||||
return s
|
||||
|
||||
def get_next(self):
|
||||
"""Returns the number for the next lesson.
|
||||
|
||||
The return value would be like 1.2, 2.1 etc.
|
||||
It will be None if there is no next lesson.
|
||||
def update_orphan_documents(self, doctype, documents):
|
||||
"""Updates the documents that were previously part of this lesson,
|
||||
but not any more.
|
||||
"""
|
||||
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):
|
||||
"""Returns the number for the prev lesson.
|
||||
def get_exercises(self):
|
||||
if not self.body:
|
||||
return []
|
||||
|
||||
The return value would be like 1.2, 2.1 etc.
|
||||
It will be None if there is no next lesson.
|
||||
"""
|
||||
macros = find_macros(self.body)
|
||||
exercises = [value for name, value in macros if name == "Exercise"]
|
||||
return [frappe.get_doc("Exercise", name) for name in exercises]
|
||||
|
||||
def get_progress(self):
|
||||
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
||||
|
||||
def get_slugified_class(self):
|
||||
if self.get_progress():
|
||||
return ("").join([ s for s in self.get_progress().lower().split() ])
|
||||
return
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_progress(lesson, course, status):
|
||||
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,
|
||||
"course": course
|
||||
}):
|
||||
doc = frappe.get_doc("LMS Course Progress",
|
||||
{
|
||||
"lesson": lesson,
|
||||
"owner": frappe.session.user,
|
||||
"course": course
|
||||
})
|
||||
doc.status = status
|
||||
doc.save(ignore_permissions=True)
|
||||
else:
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Progress",
|
||||
"lesson": lesson,
|
||||
"status": status,
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
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
|
||||
|
||||
31
community/lms/doctype/lessons/lessons.json
Normal file
31
community/lms/doctype/lessons/lessons.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-07-27 16:25:48.269536",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"lesson"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-27 16:53:52.732191",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Lessons",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/lessons/lessons.py
Normal file
8
community/lms/doctype/lessons/lessons.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 Lessons(Document):
|
||||
pass
|
||||
@@ -33,8 +33,7 @@
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"label": "Title",
|
||||
"unique": 1
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "description",
|
||||
@@ -120,7 +119,7 @@
|
||||
"link_fieldname": "batch"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-26 16:43:57.399747",
|
||||
"modified": "2021-06-16 10:51:05.403726",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch",
|
||||
|
||||
@@ -19,15 +19,7 @@ class LMSBatch(Document):
|
||||
frappe.throw(_("You are not a mentor of the course {0}").format(course.title))
|
||||
|
||||
def after_insert(self):
|
||||
create_membership(batch=self.name, member_type="Mentor")
|
||||
|
||||
def get_mentors(self):
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
{"batch": self.name, "member_type": "Mentor"},
|
||||
["member"])
|
||||
member_names = [m['member'] for m in memberships]
|
||||
return find_all("User", name=["IN", member_names])
|
||||
create_membership(batch=self.name, course=self.course, member_type="Mentor")
|
||||
|
||||
def is_member(self, email, member_type=None):
|
||||
"""Checks if a person is part of a batch.
|
||||
@@ -43,16 +35,6 @@ class LMSBatch(Document):
|
||||
filters['member_type'] = member_type
|
||||
return frappe.db.exists("LMS Batch Membership", filters)
|
||||
|
||||
def get_students(self):
|
||||
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
|
||||
"""
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
{"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):
|
||||
messages = frappe.get_all("LMS Message", {"batch": self.name}, ["*"], order_by="creation")
|
||||
for message in messages:
|
||||
@@ -80,11 +62,6 @@ class LMSBatch(Document):
|
||||
membership = self.get_membership(user)
|
||||
return membership and membership.current_lesson
|
||||
|
||||
def get_learn_url(self, lesson_number):
|
||||
if not lesson_number:
|
||||
return
|
||||
return f"/courses/{self.course}/{self.name}/learn/{lesson_number}"
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_message(message, batch):
|
||||
doc = frappe.get_doc({
|
||||
@@ -94,3 +71,38 @@ def save_message(message, batch):
|
||||
"message": message
|
||||
})
|
||||
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()
|
||||
|
||||
@@ -10,5 +10,5 @@ frappe.ui.form.on('LMS Batch Membership', {
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"fieldname": "member_type",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Member Type",
|
||||
"options": "\nStudent\nMentor\nStaff"
|
||||
},
|
||||
@@ -44,7 +45,6 @@
|
||||
"default": "Member",
|
||||
"fieldname": "role",
|
||||
"fieldtype": "Select",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Role",
|
||||
"options": "\nMember\nAdmin"
|
||||
},
|
||||
@@ -63,10 +63,10 @@
|
||||
{
|
||||
"fetch_from": "batch.course",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Data",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"read_only": 1
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "current_lesson",
|
||||
@@ -84,7 +84,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-24 12:40:57.125694",
|
||||
"modified": "2021-08-04 17:10:42.708479",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch Membership",
|
||||
|
||||
@@ -14,42 +14,65 @@ class LMSBatchMembership(Document):
|
||||
self.validate_membership_in_different_batch_same_course()
|
||||
|
||||
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",
|
||||
filters={
|
||||
"member": self.member,
|
||||
"batch": self.batch,
|
||||
"name": ["!=", self.name]
|
||||
},
|
||||
filters,
|
||||
fieldname=["member_type","member"],
|
||||
as_dict=1)
|
||||
|
||||
if previous_membership:
|
||||
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):
|
||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||
previous_membership = frappe.get_all("LMS Batch Membership",
|
||||
filters={
|
||||
"member": self.member,
|
||||
"name": ["!=", self.name]
|
||||
},
|
||||
fields=["batch", "member_type", "name"]
|
||||
)
|
||||
"""Ensures that a studnet is only part of one batch.
|
||||
"""
|
||||
# nothing to worry if the member is not a student
|
||||
if self.member_type != "Student":
|
||||
return
|
||||
|
||||
for membership in previous_membership:
|
||||
batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course")
|
||||
if batch_course == course and (membership.member_type == "Student" or self.member_type == "Student"):
|
||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
|
||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
filters={
|
||||
"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()
|
||||
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({
|
||||
"doctype": "LMS Batch Membership",
|
||||
"batch": batch,
|
||||
"course": course,
|
||||
"role": role,
|
||||
"member_type": member_type,
|
||||
"member": member or frappe.session.user
|
||||
}).save(ignore_permissions=True)
|
||||
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)
|
||||
|
||||
@@ -2,7 +2,15 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function (frm) {
|
||||
frm.set_query("chapter", "chapters", function () {
|
||||
return {
|
||||
filters: {
|
||||
"course": frm.doc.name,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
{
|
||||
"actions": [],
|
||||
"actions": [
|
||||
{
|
||||
"action": "community.lms.doctype.lms_course.lms_course.reindex_exercises",
|
||||
"action_type": "Server Action",
|
||||
"group": "Reindex",
|
||||
"label": "Reindex Exercises"
|
||||
}
|
||||
],
|
||||
"allow_guest_to_view": 1,
|
||||
"allow_rename": 1,
|
||||
"creation": "2021-03-01 16:49:33.622422",
|
||||
@@ -8,13 +15,17 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"is_published",
|
||||
"column_break_3",
|
||||
"short_code",
|
||||
"video_link",
|
||||
"image",
|
||||
"column_break_3",
|
||||
"tags",
|
||||
"is_published",
|
||||
"upcoming",
|
||||
"disable_self_learning",
|
||||
"section_break_5",
|
||||
"short_introduction",
|
||||
"description"
|
||||
"description",
|
||||
"chapters"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -37,11 +48,6 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "Published"
|
||||
},
|
||||
{
|
||||
"fieldname": "short_code",
|
||||
"fieldtype": "Data",
|
||||
"label": "Short Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
@@ -60,6 +66,34 @@
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Short Introduction",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "disable_self_learning",
|
||||
"fieldtype": "Check",
|
||||
"label": "Disable Self Learning"
|
||||
},
|
||||
{
|
||||
"fieldname": "image",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Preview Image"
|
||||
},
|
||||
{
|
||||
"fieldname": "tags",
|
||||
"fieldtype": "Data",
|
||||
"label": "Tags"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "upcoming",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is an Upcoming Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "chapters",
|
||||
"fieldtype": "Table",
|
||||
"label": "Chapters",
|
||||
"options": "Chapters"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
@@ -79,14 +113,9 @@
|
||||
"group": "Mentors",
|
||||
"link_doctype": "LMS Course Mentor Mapping",
|
||||
"link_fieldname": "course"
|
||||
},
|
||||
{
|
||||
"group": "Mentors",
|
||||
"link_doctype": "LMS Mentor Request",
|
||||
"link_fieldname": "course"
|
||||
}
|
||||
],
|
||||
"modified": "2021-05-23 18:14:32.602647",
|
||||
"modified": "2021-07-28 19:01:50.677445",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course",
|
||||
@@ -109,6 +138,5 @@
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1,
|
||||
"track_views": 1
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -5,10 +5,46 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from ...utils import slugify
|
||||
from community.query import find, find_all
|
||||
from frappe.utils import flt, cint
|
||||
from ...utils import slugify
|
||||
|
||||
class LMSCourse(Document):
|
||||
|
||||
def on_update(self):
|
||||
if not self.upcoming and self.has_value_changed("upcoming"):
|
||||
self.send_email_to_interested_users()
|
||||
|
||||
def send_email_to_interested_users(self):
|
||||
interested_users = frappe.get_all("LMS Course Interest",
|
||||
{
|
||||
"course": self.name
|
||||
},
|
||||
["name", "user"])
|
||||
subject = self.title + " is available!"
|
||||
args = {
|
||||
"title": self.title,
|
||||
"course_link": "/courses/{0}".format(self.name),
|
||||
"app_name": frappe.db.get_single_value("System Settings", "app_name"),
|
||||
"site_url": frappe.utils.get_url()
|
||||
}
|
||||
|
||||
for user in interested_users:
|
||||
args["first_name"] = frappe.db.get_value("User", user.user, "first_name")
|
||||
email_args = frappe._dict(
|
||||
recipients = user.user,
|
||||
sender = frappe.db.get_single_value("LMS Settings", "email_sender"),
|
||||
subject = subject,
|
||||
header = [subject, "green"],
|
||||
template = "lms_course_interest",
|
||||
args = args,
|
||||
now = True
|
||||
)
|
||||
frappe.enqueue(method=frappe.sendmail, queue='short', timeout=300, is_async=True, **email_args)
|
||||
frappe.db.set_value("LMS Course Interest", user.name, "email_sent", True)
|
||||
|
||||
@staticmethod
|
||||
def find(name):
|
||||
"""Returns the course with specified name.
|
||||
@@ -70,8 +106,11 @@ class LMSCourse(Document):
|
||||
mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name}, ["mentor"])
|
||||
for mentor in mentors:
|
||||
member = frappe.get_doc("User", mentor.mentor)
|
||||
# TODO: change this to count query
|
||||
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
|
||||
member.batch_count = frappe.db.count("LMS Batch Membership",
|
||||
{
|
||||
"member": member.name,
|
||||
"member_type": "Mentor"
|
||||
})
|
||||
course_mentors.append(member)
|
||||
return course_mentors
|
||||
|
||||
@@ -80,11 +119,11 @@ class LMSCourse(Document):
|
||||
"""
|
||||
if not email:
|
||||
return False
|
||||
return frappe.db.exists({
|
||||
"doctype": "LMS Course Mentor Mapping",
|
||||
"course": self.name,
|
||||
"mentor": email
|
||||
})
|
||||
return frappe.db.count("LMS Course Mentor Mapping",
|
||||
{
|
||||
"course": self.name,
|
||||
"mentor": email
|
||||
})
|
||||
|
||||
def get_student_batch(self, email):
|
||||
"""Returns the batch the given student is part of.
|
||||
@@ -110,8 +149,55 @@ class LMSCourse(Document):
|
||||
def get_chapters(self):
|
||||
"""Returns all chapters of this course.
|
||||
"""
|
||||
# TODO: chapters should have a way to specify the order
|
||||
return find_all("Chapter", course=self.name, order_by="creation")
|
||||
chapters = []
|
||||
for row in self.chapters:
|
||||
chapter_details = frappe.db.get_value("Chapter", row.chapter,
|
||||
["name", "title", "description"],
|
||||
as_dict=True)
|
||||
chapter_details.idx = row.idx
|
||||
chapters.append(chapter_details)
|
||||
return chapters
|
||||
|
||||
def get_lessons(self, chapter=None):
|
||||
""" If chapter is passed, returns lessons of only that chapter.
|
||||
Else returns lessons of all chapters of the course """
|
||||
lessons = []
|
||||
|
||||
if chapter:
|
||||
return self.get_lesson_details(chapter)
|
||||
|
||||
for chapter in self.get_chapters():
|
||||
lesson = self.get_lesson_details(chapter)
|
||||
lessons += lesson
|
||||
|
||||
return lessons
|
||||
|
||||
def get_lesson_details(self, chapter):
|
||||
lessons = []
|
||||
lesson_list = frappe.get_all("Lessons", {"parent": chapter.name},
|
||||
["lesson", "idx"], order_by="idx")
|
||||
for row in lesson_list:
|
||||
lesson_details = frappe.get_doc("Lesson", row.lesson)
|
||||
lesson_details.number = flt("{}.{}".format(chapter.idx, row.idx))
|
||||
lessons.append(lesson_details)
|
||||
return lessons
|
||||
|
||||
def get_slugified_chapter_title(self, chapter):
|
||||
return slugify(chapter)
|
||||
|
||||
def get_course_progress(self):
|
||||
""" Returns the course progress of the session user """
|
||||
lesson_count = len(self.get_lessons())
|
||||
completed_lessons = frappe.db.count("LMS Course Progress",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user,
|
||||
"status": "Complete"
|
||||
})
|
||||
precision = cint(frappe.db.get_default("float_precision")) or 3
|
||||
if not lesson_count:
|
||||
return 0
|
||||
return flt(((completed_lessons/lesson_count) * 100), precision)
|
||||
|
||||
def get_batch(self, batch_name):
|
||||
return find("LMS Batch", name=batch_name, course=self.name)
|
||||
@@ -136,66 +222,134 @@ class LMSCourse(Document):
|
||||
visibility="Public")
|
||||
return batches
|
||||
|
||||
def get_chapter(self, index):
|
||||
return find("Chapter", course=self.name, index_=index)
|
||||
|
||||
def get_lesson(self, chapter_index, lesson_index):
|
||||
chapter_name = frappe.get_value(
|
||||
"Chapter",
|
||||
{"course": self.name, "index_": chapter_index},
|
||||
"name")
|
||||
lesson_name = chapter_name and frappe.get_value(
|
||||
"Lesson",
|
||||
{"chapter": chapter_name, "index_": lesson_index},
|
||||
"name")
|
||||
return lesson_name and frappe.get_doc("Lesson", lesson_name)
|
||||
|
||||
def get_lesson_index(self, lesson_name):
|
||||
"""Returns the {chapter_index}.{lesson_index} for the lesson.
|
||||
"""
|
||||
lesson = frappe.get_doc("Lesson", lesson_name)
|
||||
chapter = frappe.get_doc("Chapter", lesson.chapter)
|
||||
return f"{chapter.index_}.{lesson.index_}"
|
||||
|
||||
def get_outline(self):
|
||||
return CourseOutline(self)
|
||||
|
||||
class CourseOutline:
|
||||
def __init__(self, course):
|
||||
self.course = course
|
||||
self.chapters = self.get_chapters()
|
||||
self.lessons = self.get_lessons()
|
||||
|
||||
def get_next(self, current):
|
||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||
try:
|
||||
index = numbers.index(current)
|
||||
return numbers[index+1]
|
||||
except IndexError:
|
||||
lesson = frappe.db.get_value("Lessons", {"lesson": lesson_name}, ["idx", "parent"], as_dict=True)
|
||||
if not lesson:
|
||||
return None
|
||||
|
||||
def get_prev(self, current):
|
||||
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||
try:
|
||||
index = numbers.index(current)
|
||||
if index == 0:
|
||||
return None
|
||||
return numbers[index-1]
|
||||
except IndexError:
|
||||
chapter = frappe.db.get_value("Chapters", {"chapter": lesson.parent}, ["idx"], as_dict=True)
|
||||
if not chapter:
|
||||
return None
|
||||
|
||||
def get_chapters(self):
|
||||
return frappe.db.get_all("Chapter",
|
||||
filters={"course": self.course.name},
|
||||
fields=["name", "title", "index_"])
|
||||
return f"{chapter.idx}.{lesson.idx}"
|
||||
|
||||
def get_lessons(self):
|
||||
chapters = [c['name'] for c in self.chapters]
|
||||
lessons = frappe.db.get_all("Lesson",
|
||||
filters={"chapter": ["IN", chapters]},
|
||||
fields=["name", "title", "chapter", "index_"])
|
||||
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)
|
||||
|
||||
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
|
||||
for lesson in lessons:
|
||||
lesson['number'] = "{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_'])
|
||||
return lessons
|
||||
def _reindex_exercises_in_chapter(self, c):
|
||||
i = 1
|
||||
for lesson in self.get_lessons(c):
|
||||
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", "member_type"],
|
||||
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_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_tags(self):
|
||||
return self.tags.split(",") if self.tags else []
|
||||
|
||||
def get_reviews(self):
|
||||
reviews = frappe.get_all("LMS Course Review",
|
||||
{
|
||||
"course": self.name
|
||||
},
|
||||
["review", "rating", "owner"],
|
||||
order_by= "creation desc")
|
||||
|
||||
for review in reviews:
|
||||
review.owner_details = frappe.get_doc("User", review.owner)
|
||||
|
||||
return reviews
|
||||
|
||||
def is_eligible_to_review(self, membership):
|
||||
""" Checks if user is eligible to review the course """
|
||||
if not membership:
|
||||
return False
|
||||
if frappe.db.count("LMS Course Review",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user
|
||||
}):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_average_rating(self):
|
||||
ratings = [review.rating for review in self.get_reviews()]
|
||||
if not len(ratings):
|
||||
return None
|
||||
return sum(ratings)/len(ratings)
|
||||
|
||||
def get_progress(self, lesson):
|
||||
return frappe.db.get_value("LMS Course Progress",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user,
|
||||
"lesson": lesson
|
||||
},
|
||||
["status"])
|
||||
|
||||
def get_neighbours(self, current, lessons):
|
||||
current = flt(current)
|
||||
numbers = sorted(lesson.number for lesson in lessons)
|
||||
index = numbers.index(current)
|
||||
return {
|
||||
"prev": numbers[index-1] if index-1 >= 0 else None,
|
||||
"next": numbers[index+1] if index+1 < len(numbers) else None
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def reindex_exercises(doc):
|
||||
course_data = json.loads(doc)
|
||||
course = frappe.get_doc("LMS Course", course_data['name'])
|
||||
course.reindex_exercises()
|
||||
frappe.msgprint("All exercises in this course have been re-indexed.")
|
||||
|
||||
@@ -26,7 +26,6 @@ class TestLMSCourse(unittest.TestCase):
|
||||
course = self.new_course("Test Course")
|
||||
assert course.title == "Test Course"
|
||||
assert course.name == "test-course"
|
||||
assert course.get_mentors() == []
|
||||
|
||||
def test_find_all(self):
|
||||
courses = LMSCourse.find_all()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course Interest', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-08-06 17:37:20.184849",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"course",
|
||||
"user",
|
||||
"email_sent"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "User",
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "email_sent",
|
||||
"fieldtype": "Check",
|
||||
"label": "Email Sent",
|
||||
"options": "email_sent"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-08-06 18:06:21.370741",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course Interest",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSCourseInterest(Document):
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def capture_interest(course):
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Interest",
|
||||
"course": course,
|
||||
"user": frappe.session.user
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCodeRevision(unittest.TestCase):
|
||||
class TestLMSCourseInterest(unittest.TestCase):
|
||||
pass
|
||||
@@ -2,7 +2,13 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course Mentor Mapping', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function(frm) {
|
||||
frm.set_query('mentor', function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"ignore_user_type": 1,
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course Progress', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-31 17:20:13.388453",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"status",
|
||||
"column_break_3",
|
||||
"lesson",
|
||||
"chapter",
|
||||
"course"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fetch_from": "chapter.course",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "lesson.chapter",
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"options": "Complete\nPartially Complete\nIncomplete"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-02 13:05:31.114939",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course Progress",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -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 LMSCourseProgress(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSCourseProgress(unittest.TestCase):
|
||||
pass
|
||||
0
community/lms/doctype/lms_course_review/__init__.py
Normal file
0
community/lms/doctype/lms_course_review/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Message', {
|
||||
frappe.ui.form.on('LMS Course Review', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -1,41 +1,41 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-04-07 00:26:28.806520",
|
||||
"creation": "2021-06-28 13:36:36.146718",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"section",
|
||||
"code",
|
||||
"author"
|
||||
"review",
|
||||
"rating",
|
||||
"course"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "section",
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "review",
|
||||
"fieldtype": "Small Text",
|
||||
"in_list_view": 1,
|
||||
"label": "Section",
|
||||
"options": "LMS Section"
|
||||
"label": "Review"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
"fieldname": "rating",
|
||||
"fieldtype": "Rating",
|
||||
"in_list_view": 1,
|
||||
"label": "Rating"
|
||||
},
|
||||
{
|
||||
"fieldname": "author",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Author",
|
||||
"options": "User"
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-14 11:26:19.628317",
|
||||
"modified": "2021-07-05 14:57:03.841430",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Code Revision",
|
||||
"name": "LMS Course Review",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -53,6 +53,5 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "section",
|
||||
"track_changes": 1
|
||||
}
|
||||
18
community/lms/doctype/lms_course_review/lms_course_review.py
Normal file
18
community/lms/doctype/lms_course_review/lms_course_review.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSCourseReview(Document):
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def submit_review(rating, review, course):
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Review",
|
||||
"rating": rating,
|
||||
"review": review,
|
||||
"course": course
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSCourseReview(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,110 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
from frappe.utils import add_days, nowdate
|
||||
|
||||
class LMSMessage(Document):
|
||||
def after_insert(self):
|
||||
self.publish_message()
|
||||
#Todo: Adding email preference field for users
|
||||
#self.send_email()
|
||||
|
||||
def publish_message(self):
|
||||
template = self.get_message_template()
|
||||
message = frappe._dict({
|
||||
"author_name": self.author_name,
|
||||
"message_time": frappe.utils.format_datetime(self.creation, "dd-mm-yyyy HH:mm"),
|
||||
"message": frappe.utils.md_to_html(self.message)
|
||||
})
|
||||
|
||||
js = """
|
||||
$(".msger-input").val("");
|
||||
var template = `{0}`;
|
||||
var message = {1};
|
||||
var session_user = ("{2}" == frappe.session.user) ? true : false;
|
||||
message.author_name = session_user ? "You" : message.author_name
|
||||
message.is_author = session_user;
|
||||
template = frappe.render_template(template, {{
|
||||
"message": message
|
||||
}})
|
||||
$(".messages").append(template);
|
||||
var message_element = document.getElementsByClassName("messages")[0]
|
||||
message_element.scrollTo(0, message_element.scrollHeight);
|
||||
""".format(template, message, self.owner)
|
||||
|
||||
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
||||
|
||||
def get_message_template(self):
|
||||
return """
|
||||
<li class="{% if message.is_author %} ours {% endif %}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="font-weight-bold">
|
||||
{{ message.author_name }}
|
||||
</div>
|
||||
<small class="">
|
||||
{{ message.message_time }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="message-para">
|
||||
{{ message.message }}
|
||||
</div>
|
||||
</li>
|
||||
"""
|
||||
|
||||
def send_email(self):
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.get_doc("User", entry.member)
|
||||
if member.name != self.author:
|
||||
#Todo: wrap sendmail in frappe.enqueue, else messages takes long to display.
|
||||
frappe.sendmail(
|
||||
recipients = member.email,
|
||||
subject = _("New Message on ") + self.batch,
|
||||
header = _("New Message on ") + self.batch,
|
||||
template = "lms_message",
|
||||
args = {
|
||||
"author": self.author,
|
||||
"message": frappe.utils.md_to_html(self.message),
|
||||
"creation": frappe.utils.format_datetime(self.creation, "medium"),
|
||||
"course": frappe.db.get_value("LMS Batch", self.batch, ["course"])
|
||||
}
|
||||
)
|
||||
|
||||
def send_daily_digest():
|
||||
#Todo: Optimize this
|
||||
emails = frappe._dict()
|
||||
messages = frappe.get_all("LMS Message", {"creation": [">=", add_days(nowdate(), -1)]}, ["message", "batch", "author", "creation"])
|
||||
for message in messages:
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": message.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.db.get_value("User", entry.member, ["name", "email"], as_dict=1)
|
||||
if member.name != message.author:
|
||||
if member.name in emails.keys():
|
||||
emails[member.name]["messages"].append(message)
|
||||
else:
|
||||
emails[member.name] = frappe._dict({
|
||||
"email": member.email,
|
||||
"messages": [message]
|
||||
})
|
||||
for email in emails:
|
||||
group_by_batch = frappe._dict()
|
||||
for message in emails[email]["messages"]:
|
||||
if message.batch in group_by_batch.keys():
|
||||
group_by_batch[message.batch].append(message)
|
||||
else:
|
||||
group_by_batch[message.batch] = [message]
|
||||
frappe.sendmail(
|
||||
recipients = frappe.db.get_value("User", email, "email"),
|
||||
subject = _("Message Digest"),
|
||||
header = _("Message Digest"),
|
||||
template = "lms_daily_digest",
|
||||
args = {
|
||||
"batches": group_by_batch
|
||||
},
|
||||
delayed = False
|
||||
)
|
||||
0
community/lms/doctype/lms_option/__init__.py
Normal file
0
community/lms/doctype/lms_option/__init__.py
Normal file
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
|
||||
0
community/lms/doctype/lms_quiz/__init__.py
Normal file
0
community/lms/doctype/lms_quiz/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Sketch', {
|
||||
frappe.ui.form.on('LMS Quiz', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -1,45 +1,42 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "format:SKETCH-{#}",
|
||||
"creation": "2021-03-09 16:31:50.523524",
|
||||
"autoname": "field:title",
|
||||
"creation": "2021-06-07 10:50:17.893625",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"runtime",
|
||||
"code",
|
||||
"svg"
|
||||
"questions",
|
||||
"lesson"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"label": "Title"
|
||||
"label": "Title",
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "runtime",
|
||||
"fieldtype": "Data",
|
||||
"label": "Runtime"
|
||||
"fieldname": "questions",
|
||||
"fieldtype": "Table",
|
||||
"label": "Questions",
|
||||
"options": "LMS Quiz Question"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "svg",
|
||||
"fieldtype": "Code",
|
||||
"label": "SVG",
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"label": "Lesson",
|
||||
"options": "Lesson",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-03-12 08:42:56.671658",
|
||||
"modified": "2021-07-23 19:06:12.551633",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Sketch",
|
||||
"name": "LMS Quiz",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -57,6 +54,5 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_views": 1
|
||||
"track_changes": 1
|
||||
}
|
||||
75
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
75
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# 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 quiz_summary(quiz, results):
|
||||
score = 0
|
||||
results = json.loads(results)
|
||||
|
||||
for result in results:
|
||||
correct = result["is_correct"][0]
|
||||
result["question"] = frappe.db.get_value("LMS Quiz Question",
|
||||
{"parent": quiz, "idx": result["question_index"]},
|
||||
["question"])
|
||||
|
||||
for point in result["is_correct"]:
|
||||
correct = correct and point
|
||||
|
||||
result["result"] = "Right" if correct else "Wrong"
|
||||
score += correct
|
||||
|
||||
del result["is_correct"]
|
||||
del result["question_index"]
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Quiz Submission",
|
||||
"quiz": quiz,
|
||||
"result": results,
|
||||
"score": score
|
||||
}).save(ignore_permissions=True)
|
||||
|
||||
return score
|
||||
41
community/lms/doctype/lms_quiz/test_lms_quiz.py
Normal file
41
community/lms/doctype/lms_quiz/test_lms_quiz.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
import frappe
|
||||
|
||||
class TestLMSQuiz(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Quiz",
|
||||
"title": "Test Quiz"
|
||||
}).save()
|
||||
|
||||
def test_with_multiple_options(self):
|
||||
quiz = frappe.get_doc("LMS Quiz", "Test Quiz")
|
||||
quiz.append("questions", {
|
||||
"question": "Question multiple",
|
||||
"option_1": "Option 1",
|
||||
"is_correct_1": 1,
|
||||
"option_2": "Option 2",
|
||||
"is_correct_2": 1
|
||||
})
|
||||
quiz.save()
|
||||
self.assertTrue(quiz.questions[0].multiple)
|
||||
|
||||
def test_with_no_correct_option(self):
|
||||
quiz = frappe.get_doc("LMS Quiz", "Test Quiz")
|
||||
quiz.append("questions", {
|
||||
"question": "Question no correct option",
|
||||
"option_1": "Option 1",
|
||||
"option_2": "Option 2",
|
||||
})
|
||||
self.assertRaises(frappe.ValidationError, quiz.save)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
frappe.db.delete("LMS Quiz", "Test Quiz")
|
||||
frappe.db.delete("LMS Quiz Question", {"parent": "Test Quiz"})
|
||||
0
community/lms/doctype/lms_quiz_question/__init__.py
Normal file
0
community/lms/doctype/lms_quiz_question/__init__.py
Normal file
166
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
166
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
@@ -0,0 +1,166 @@
|
||||
{
|
||||
"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",
|
||||
"column_break_5",
|
||||
"explanation_1",
|
||||
"section_break_5",
|
||||
"option_2",
|
||||
"is_correct_2",
|
||||
"column_break_10",
|
||||
"explanation_2",
|
||||
"column_break_4",
|
||||
"option_3",
|
||||
"is_correct_3",
|
||||
"column_break_15",
|
||||
"explanation_3",
|
||||
"section_break_11",
|
||||
"option_4",
|
||||
"is_correct_4",
|
||||
"column_break_20",
|
||||
"explanation_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"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_1",
|
||||
"fieldname": "explanation_1",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_2",
|
||||
"fieldname": "explanation_2",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_3",
|
||||
"fieldname": "explanation_3",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_4",
|
||||
"fieldname": "explanation_4",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_5",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_10",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_15",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_20",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-19 19:35:28.446236",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Question",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizQuestion(Document):
|
||||
pass
|
||||
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 14:19:23.683323",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"question",
|
||||
"answer",
|
||||
"result"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "question",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Question"
|
||||
},
|
||||
{
|
||||
"fieldname": "result",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Result",
|
||||
"options": "Right\nWrong"
|
||||
},
|
||||
{
|
||||
"fieldname": "answer",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Users Response"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-22 18:32:28.813159",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Result",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizResult(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Quiz Submission', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 14:19:54.958989",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"quiz",
|
||||
"result",
|
||||
"score"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "quiz",
|
||||
"fieldtype": "Link",
|
||||
"label": "Quiz",
|
||||
"options": "LMS Quiz"
|
||||
},
|
||||
{
|
||||
"fieldname": "result",
|
||||
"fieldtype": "Table",
|
||||
"label": "Result",
|
||||
"options": "LMS Quiz Result"
|
||||
},
|
||||
{
|
||||
"fieldname": "score",
|
||||
"fieldtype": "Data",
|
||||
"label": "Score"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-07 14:19:54.958989",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Submission",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizSubmission(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSQuizSubmission(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,66 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-03-05 15:10:53.906006",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"label",
|
||||
"type",
|
||||
"contents",
|
||||
"code",
|
||||
"attrs",
|
||||
"index",
|
||||
"id"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Label"
|
||||
},
|
||||
{
|
||||
"fieldname": "type",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Type"
|
||||
},
|
||||
{
|
||||
"fieldname": "contents",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Contents"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "attrs",
|
||||
"fieldtype": "Long Text",
|
||||
"label": "attrs"
|
||||
},
|
||||
{
|
||||
"fieldname": "index",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index"
|
||||
},
|
||||
{
|
||||
"fieldname": "id",
|
||||
"fieldtype": "Data",
|
||||
"label": "id"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-19 18:55:26.019625",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Section",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -14,6 +14,10 @@ class LMSSection(Document):
|
||||
if self.type == "exercise":
|
||||
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):
|
||||
"""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)
|
||||
|
||||
112
community/lms/md.py
Normal file
112
community/lms/md.py
Normal file
@@ -0,0 +1,112 @@
|
||||
"""
|
||||
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), macro)
|
||||
e = etree.fromstring(html)
|
||||
return e, m.start(0), m.end(0)
|
||||
|
||||
def sanitize_html(html, macro):
|
||||
"""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
|
||||
classname = ""
|
||||
if macro == "YouTubeVideo":
|
||||
classname = "lesson-video"
|
||||
return "<div class='" + classname + "'>" + "\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.
|
||||
"""
|
||||
from .doctype.lms_course.lms_course import LMSCourse as Course
|
||||
from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch
|
||||
|
||||
from .doctype.lms_batch_membership.lms_batch_membership import LMSBatchMembership as Membership
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
"""Utility to split the text in the topic into multiple sections.
|
||||
|
||||
{{ section(type="example", id="foo") }}
|
||||
circle(100, 100, 50)
|
||||
{{ end }}
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
import re
|
||||
from typing import List, Tuple, Dict, Iterator
|
||||
|
||||
RE_SECTION = re.compile(r"^\{\{\s(\w+)\s*(?:\((.*)\))?\s*\}\}\s*")
|
||||
class SectionParser:
|
||||
def parse(self, text: str) -> Iterator[Section]:
|
||||
"""Parses given text into sections and return an iterator over sections.
|
||||
"""
|
||||
lines = text.splitlines()
|
||||
marked_lines = self.parse_lines(lines)
|
||||
return self.group_sections(marked_lines)
|
||||
|
||||
def parse_lines(self, lines: List[str]) -> List[Tuple[str, str, str]]:
|
||||
for line in lines:
|
||||
m = RE_SECTION.match(line)
|
||||
if m:
|
||||
yield m.group(1), self.parse_attrs(m.group(2)), None
|
||||
else:
|
||||
yield None, None, line
|
||||
|
||||
def parse_attrs(self, attrs_str: str) -> Dict[str, str]:
|
||||
# XXX-Anand: Hack
|
||||
code = "dict({})".format(attrs_str or "")
|
||||
return eval(code)
|
||||
|
||||
def group_sections(self, marked_lines) -> Iterator[Section]:
|
||||
index = 0
|
||||
|
||||
def make_section(type='text', id=None, label=None, **attrs):
|
||||
nonlocal index
|
||||
index += 1
|
||||
|
||||
id = id or f"section-{index}"
|
||||
label = label or id
|
||||
return Section(
|
||||
type=type,
|
||||
id=id,
|
||||
label=label,
|
||||
attrs=attrs)
|
||||
|
||||
section = make_section("text")
|
||||
|
||||
for mark, attrs, line in marked_lines:
|
||||
if not mark:
|
||||
section.append(line)
|
||||
continue
|
||||
|
||||
yield section
|
||||
|
||||
if mark == 'end':
|
||||
section = make_section(type='text')
|
||||
else:
|
||||
section = make_section(**attrs)
|
||||
|
||||
yield section
|
||||
|
||||
@dataclass
|
||||
class Section:
|
||||
"""One section of the Topic.
|
||||
"""
|
||||
type: str
|
||||
id: str
|
||||
label: str
|
||||
contents: str = ""
|
||||
attrs: dict = None
|
||||
|
||||
def append(self, line):
|
||||
if not line.endswith("\n"):
|
||||
line = line + "\n"
|
||||
self.contents += line
|
||||
|
||||
def __repr__(self):
|
||||
attrs = dict(type=self.type, id=self.id, label=self.label, **self.attrs)
|
||||
attrs_str = ", ".join(f'{k}="{v}"' for k, v in attrs.items())
|
||||
return f'<Section({attrs_str})>'
|
||||
@@ -11,7 +11,7 @@
|
||||
"apply_document_permissions": 0,
|
||||
"button_label": "Save",
|
||||
"creation": "2021-04-20 11:37:49.135114",
|
||||
"custom_css": ".datepicker.active {\n background-color: white;\n}",
|
||||
"custom_css": ".datepicker.active {\n background-color: white;\n}\n\n[data-doctype=\"Web Form\"] {\n max-width: 720px;\n margin: 6rem auto;\n}",
|
||||
"doc_type": "LMS Batch",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
@@ -19,7 +19,7 @@
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-04-30 11:22:18.188712",
|
||||
"modified": "2021-06-15 18:49:50.530001",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "add-a-new-batch",
|
||||
@@ -39,12 +39,12 @@
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hidden": 1,
|
||||
"label": "Course",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "",
|
||||
"read_only": 1,
|
||||
"options": "LMS Course",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
@@ -111,4 +111,4 @@
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
frappe.ready(function() {
|
||||
// bind events here
|
||||
})
|
||||
@@ -1,48 +0,0 @@
|
||||
{
|
||||
"accept_payment": 0,
|
||||
"allow_comments": 0,
|
||||
"allow_delete": 0,
|
||||
"allow_edit": 0,
|
||||
"allow_incomplete": 0,
|
||||
"allow_multiple": 0,
|
||||
"allow_print": 0,
|
||||
"amount": 0.0,
|
||||
"amount_based_on_field": 0,
|
||||
"apply_document_permissions": 0,
|
||||
"button_label": "Save",
|
||||
"creation": "2021-04-15 13:32:14.171328",
|
||||
"doc_type": "LMS Batch Membership",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-04-15 13:32:14.171328",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "join-a-batch",
|
||||
"owner": "Administrator",
|
||||
"payment_button_label": "Buy Now",
|
||||
"published": 1,
|
||||
"route": "join-a-batch",
|
||||
"route_to_success_link": 0,
|
||||
"show_attachments": 0,
|
||||
"show_in_grid": 0,
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_url": "/join-a-batch",
|
||||
"title": "Join a Batch",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldtype": "Attach",
|
||||
"hidden": 0,
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
0
community/lms/web_form/profile/__init__.py
Normal file
0
community/lms/web_form/profile/__init__.py
Normal file
14
community/lms/web_form/profile/profile.js
Normal file
14
community/lms/web_form/profile/profile.js
Normal file
@@ -0,0 +1,14 @@
|
||||
frappe.ready(function () {
|
||||
|
||||
frappe.web_form.after_load = () => {
|
||||
if (!frappe.utils.get_url_arg("name")) {
|
||||
window.location.href = `/edit-profile?name=${frappe.session.user}`;
|
||||
}
|
||||
}
|
||||
|
||||
frappe.web_form.after_save = () => {
|
||||
setTimeout(() => {
|
||||
window.location.href = `/${frappe.web_form.get_value(["username"])}`;
|
||||
})
|
||||
}
|
||||
})
|
||||
212
community/lms/web_form/profile/profile.json
Normal file
212
community/lms/web_form/profile/profile.json
Normal file
@@ -0,0 +1,212 @@
|
||||
{
|
||||
"accept_payment": 0,
|
||||
"allow_comments": 0,
|
||||
"allow_delete": 0,
|
||||
"allow_edit": 1,
|
||||
"allow_incomplete": 0,
|
||||
"allow_multiple": 0,
|
||||
"allow_print": 0,
|
||||
"amount": 0.0,
|
||||
"amount_based_on_field": 0,
|
||||
"apply_document_permissions": 0,
|
||||
"breadcrumbs": "",
|
||||
"button_label": "Save",
|
||||
"client_script": "",
|
||||
"creation": "2021-06-30 13:48:13.682851",
|
||||
"custom_css": "[data-doctype=\"Web Form\"] {\n max-width: 720px;\n margin: 6rem auto;\n}",
|
||||
"doc_type": "User",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-08-06 14:40:39.013776",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "profile",
|
||||
"owner": "Administrator",
|
||||
"payment_button_label": "Buy Now",
|
||||
"published": 1,
|
||||
"route": "edit-profile",
|
||||
"route_to_success_link": 0,
|
||||
"show_attachments": 0,
|
||||
"show_in_grid": 0,
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_url": "/profile",
|
||||
"title": "Profile",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "first_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "First Name",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "middle_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Middle Name (Optional)",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "last_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Last Name",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "username",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Username",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"description": "Get your globally recognized avatar from Gravatar.com",
|
||||
"fieldname": "user_image",
|
||||
"fieldtype": "Attach Image",
|
||||
"hidden": 0,
|
||||
"label": "User Image",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "mobile_no",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Mobile No",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "Phone",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "bio",
|
||||
"fieldtype": "Small Text",
|
||||
"hidden": 0,
|
||||
"label": "Bio",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "linkedin",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "LinkedIn ID",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "github",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Github ID",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "medium",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Medium ID",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "city",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "City",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "college",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "College Name",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"depends_on": "college",
|
||||
"fieldname": "branch",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Branch",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "profession",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Profession",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
@@ -1,39 +0,0 @@
|
||||
<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 %}
|
||||
</div>
|
||||
<ul class="nav nav-tabs mt-4">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="home" href="/courses/{{course.name}}/{{batch.name}}/home">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="learn" href="/courses/{{course.name}}/{{batch.name}}/learn">Learn</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/{{batch.name}}/schedule">Schedule</a>
|
||||
</li> -->
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="members" href="/courses/{{course.name}}/{{batch.name}}/members">Members</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/{{batch.name}}/discuss">Discussion</a>
|
||||
</li>
|
||||
<!-- <li class="nav-item">
|
||||
<a class="nav-link" id="about" href="/courses/{{course.name}}/{{batch.name}}/about">About</a>
|
||||
</li> -->
|
||||
{% if batch.is_member(frappe.session.user, member_type="Mentor") %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="progress" href="/courses/{{course.name}}/{{batch.name}}/progress">Progress</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}"]`)
|
||||
if (selector) {
|
||||
selector.classList.add('active');
|
||||
}
|
||||
else {
|
||||
$("#learn").addClass('active')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
21
community/lms/widgets/BreadCrumb.html
Normal file
21
community/lms/widgets/BreadCrumb.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<div class="breadcrumb">
|
||||
|
||||
|
||||
{% if course %}
|
||||
<a class="dark-links" href="/courses">All Courses</a>
|
||||
<img class="ml-1 mr-1" src="/assets/community/icons/chevron-right.svg">
|
||||
{% if lesson %}
|
||||
<a class="dark-links" href="/courses/{{ course.name }}">{{ course.title }}</a>
|
||||
<img class="ml-1 mr-1" src="/assets/community/icons/chevron-right.svg">
|
||||
<span class="muted-text"> {{ lesson.title }}</span>
|
||||
{% else %}
|
||||
<span class="muted-text">{{ course.title }}</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if thread %}
|
||||
<a class="dark-links" href="/discussions">Discussions</a>
|
||||
<img class="ml-1 mr-1" src="/assets/community/icons/chevron-right.svg">
|
||||
<span class="muted-text">{{ thread.title }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -1,15 +1,100 @@
|
||||
<div class="chapter-teaser">
|
||||
<div class="teaser-body">
|
||||
<h3 class="chapter-title"><span class="mr-1">{{index}}.</span> {{ chapter.title }}</h3>
|
||||
<div class="chapter-description">
|
||||
{{ chapter.description or "" }}
|
||||
<div>
|
||||
|
||||
<div class="chapter-title small-title" data-target="#{{ course.get_slugified_chapter_title(chapter.title) }}"
|
||||
data-toggle="collapse" aria-expanded="false">
|
||||
<img class="chapter-icon" src="/assets/community/icons/chevron-right.svg">
|
||||
{{ index }}. {{ chapter.title }}
|
||||
</div>
|
||||
|
||||
<div class="chapter-content collapse navbar-collapse" id="{{ course.get_slugified_chapter_title(chapter.title) }}">
|
||||
|
||||
{% if chapter.description %}
|
||||
<div class="chapter-description muted-text">
|
||||
{{ chapter.description }}
|
||||
</div>
|
||||
<div class="chapter-lessons">
|
||||
{% for lesson in chapter.get_lessons() %}
|
||||
<div class="lesson-teaser">
|
||||
<a {% if show_link %} class="anchor_style" href="{{ batch.get_learn_url(course.get_lesson_index(lesson.name)) }}" {% endif %}>{{ lesson.title }}</a>
|
||||
{% endif %}
|
||||
|
||||
<div class="lessons">
|
||||
|
||||
{% for lesson in course.get_lessons(chapter) %}
|
||||
|
||||
<div class="lesson-info{% if membership.current_lesson == lesson.name %} active-lesson {% endif %}">
|
||||
|
||||
{% if membership or lesson.include_in_preview %}
|
||||
<a class="lesson-links"
|
||||
href="{{ course.get_learn_url(lesson.number) }}{{course.query_parameter}}"
|
||||
data-course="{{ course.name }}">
|
||||
{{ lesson.title }}
|
||||
|
||||
{% if membership %}
|
||||
<img class="ml-1 lesson-progress-tick {{ course.get_progress(lesson.name) != 'Complete' and 'hide' }}"
|
||||
src="/assets/community/icons/check.svg">
|
||||
{% endif %}
|
||||
|
||||
</a>
|
||||
|
||||
{% else %}
|
||||
<div class="no-preview" title="This lesson is not available for preview">
|
||||
<div class="lesson-links">
|
||||
{{ lesson.title }}
|
||||
<img class="ml-2" src="/assets/community/icons/lock.svg">
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if index != course.get_chapters() | length %}
|
||||
<div class="card-divider"></div>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
expand_the_active_chapter();
|
||||
})
|
||||
|
||||
var expand_the_first_chapter = () => {
|
||||
var elements = $(".collapse");
|
||||
elements.each((i, element) => {
|
||||
if (i <= 1) {
|
||||
show_section(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var expand_the_active_chapter = () => {
|
||||
|
||||
/* Find anchor matching the URL for course details page */
|
||||
var selector = $(`a[href="${decodeURIComponent(window.location.pathname)}"]`).parent();
|
||||
if (!selector.length) {
|
||||
selector = $(`a[href^="${decodeURIComponent(window.location.pathname)}"]`).parent();
|
||||
}
|
||||
if (selector.length && $(".course-details-page").length) {
|
||||
$(".lesson-info").removeClass("active-lesson")
|
||||
selector.addClass("active-lesson");
|
||||
show_section(selector.parent().parent());
|
||||
}
|
||||
|
||||
/* For course home page */
|
||||
else if ($(".active-lesson").length) {
|
||||
selector = $(".active-lesson")
|
||||
show_section(selector.parent().parent());
|
||||
}
|
||||
|
||||
/* If no active chapter then exapand the first chapter */
|
||||
else {
|
||||
expand_the_first_chapter();
|
||||
}
|
||||
}
|
||||
|
||||
var show_section = (element) => {
|
||||
$(element).addClass("show");
|
||||
$(element).siblings(".chapter-title").children(".chapter-icon").css("transform", "rotate(90deg)");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
90
community/lms/widgets/CourseCard.html
Normal file
90
community/lms/widgets/CourseCard.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<div class="common-card-style course-card">
|
||||
<div class="course-image {% if not course.image %}default-image{% endif %}"
|
||||
{% if course.image %} style="background-image: url( {{ course.image }} );" {% endif %}>
|
||||
<div class="course-tags">
|
||||
{% for tag in course.get_tags() %}
|
||||
<div class="course-card-pills">{{ tag }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if not course.image %}
|
||||
<div class="default-image-text">{{ course.title[0] }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="course-card-content">
|
||||
<div class="course-card-meta muted-text">
|
||||
{% if course.get_chapters() | length %}
|
||||
<span>
|
||||
{{ course.get_chapters() | length }} Chapters
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if course.get_chapters() | length and course.get_upcoming_batches() | length %}
|
||||
<span class="font-weight-bold ml-3 mr-3"> . </span>
|
||||
{% endif %}
|
||||
{% if course.get_upcoming_batches() | length %}
|
||||
<span class="">
|
||||
{{ course.get_upcoming_batches() | length }} Open Batches
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="course-card-title">{{ course.title }}</div>
|
||||
<div class="card-divider"></div>
|
||||
<div class="course-card-meta-2">
|
||||
{{ widgets.Avatar(member=course.get_instructor(), avatar_class="avatar-small") }}
|
||||
<span class="course-instructor">
|
||||
{{ course.get_instructor().full_name }}
|
||||
</span>
|
||||
<span class="course-student-count">
|
||||
{% if course.get_students() | length %}
|
||||
<span class="mr-4">
|
||||
<img class="icon-background" src="/assets/community/icons/user.svg" />
|
||||
{{ course.get_students() | length }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% set avg_rating = course.get_average_rating() %}
|
||||
{% if avg_rating %}
|
||||
<span>
|
||||
<img class="icon-background" src="/assets/community/icons/rating.svg" />
|
||||
{{ avg_rating }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% set membership = course.get_membership(frappe.session.user) %}
|
||||
|
||||
{% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and
|
||||
membership.current_lesson
|
||||
else '1.1' %}
|
||||
|
||||
{% set query_parameter = "?batch=" + membership.batch if membership and membership.batch else "" %}
|
||||
|
||||
{% if course.upcoming %}
|
||||
<div class="view-course-link is-secondary border">
|
||||
Upcoming Course <img class="ml-3" src="/assets/community/icons/black-arrow.svg" />
|
||||
</div>
|
||||
<a class="stretched-link" href="/courses/{{ course.name }}"></a>
|
||||
|
||||
{% elif membership %}
|
||||
<div class="view-course-link is-primary">
|
||||
Continue Course <img class="ml-3" src="/assets/community/icons/white-arrow.svg" />
|
||||
</div>
|
||||
<a class="stretched-link" href="{{ course.get_learn_url(lesson_index) }}{{ query_parameter }}"></a>
|
||||
|
||||
{% else %}
|
||||
<div class="view-course-link">
|
||||
View Course <img class="ml-3" src="/assets/community/icons/black-arrow.svg" />
|
||||
</div>
|
||||
<a class="stretched-link" href="/courses/{{ course.name }}"></a>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
frappe.ready(() => {
|
||||
$(".course-card-title").each((i, element) => {
|
||||
var title = $(element).text();
|
||||
var length = $(window).width() <= 375 ? 60 : 65;
|
||||
var suffix = title.length > length ? "..." : "";
|
||||
$(element).text(title.substring(0, length) + suffix);
|
||||
})
|
||||
})
|
||||
</script>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user