Compare commits

..

115 Commits

Author SHA1 Message Date
pateljannat
d7e1745c09 fix: added back update progress code 2021-08-18 18:17:40 +05:30
pateljannat
ef238c1b25 fix: export label 2021-08-18 18:08:33 +05:30
pateljannat
cb60d97bb7 feat: certification 2021-08-18 18:04:47 +05:30
Jannat Patel
f0ee8d7b88 Merge pull request #173 from fossunited/sketch-redesign
fix: sketch cards
2021-08-16 13:47:05 +05:30
Jannat Patel
7e5203f058 Merge pull request #179 from fossunited/discussions
feat: Discussions
2021-08-16 13:45:00 +05:30
pateljannat
a3672e9d91 feat: discussions 2021-08-16 13:33:08 +05:30
pateljannat
7017382451 fix: removed sketch card 2021-08-11 11:40:57 +05:30
pateljannat
6c9d49bf8c discussion doctypes 2021-08-11 11:14:40 +05:30
pateljannat
2de058246b Merge branch 'main' of https://github.com/frappe/community into main 2021-08-11 10:46:11 +05:30
pateljannat
798ea30382 fix: chapter teaser jerk issue 2021-08-11 10:46:01 +05:30
pateljannat
3e2c6b3343 fix: sketch image call 2021-08-10 17:08:32 +05:30
pateljannat
5ea744de5c fix: removed unused file 2021-08-10 16:46:48 +05:30
pateljannat
aedb3d3d45 fix: sketch cards 2021-08-10 16:39:17 +05:30
Jannat Patel
83a2f42df9 Merge pull request #171 from fossunited/username-fixes
fix: username issues
2021-08-10 13:19:29 +05:30
pateljannat
66aace247c fix: conditions and tests 2021-08-10 10:28:59 +05:30
pateljannat
bc3db06960 fix: username issues 2021-08-09 16:54:02 +05:30
Jannat Patel
ddaa063587 Merge pull request #170 from fossunited/upcoming-course-notify
feat: notify me
2021-08-09 15:39:04 +05:30
pateljannat
f9b4fe468e fix: removed unused import 2021-08-09 13:27:09 +05:30
pateljannat
6cbca8d1bb feat: notify me 2021-08-09 13:13:48 +05:30
Jannat Patel
d5067a4bcd Merge pull request #169 from fossunited/username-validations
fix: Username validations
2021-08-06 15:05:36 +05:30
pateljannat
04d44510de fix: redirect after edit profile save 2021-08-06 14:41:37 +05:30
pateljannat
844fcc9bca fix: username validations 2021-08-06 14:41:11 +05:30
Jannat Patel
145b5efab0 Merge pull request #168 from fossunited/minor-issues
fix: quiz, course outline, and lesson indexing
2021-08-05 18:41:15 +05:30
pateljannat
4079ed97b9 fix: quiz, course outline, and lesson indexing 2021-08-05 18:26:41 +05:30
pateljannat
63d70fc037 fix: username space and empty validations 2021-08-05 15:51:21 +05:30
Jannat Patel
ce86b5deda Merge pull request #167 from fossunited/issues
fix: cleanup
2021-08-04 19:18:45 +05:30
pateljannat
037e946bbe fix: mentors cleanup 2021-08-04 19:07:14 +05:30
pateljannat
a51c8de1eb fix: profile progress and review links 2021-08-04 14:01:52 +05:30
Jannat Patel
53dc517180 Merge pull request #165 from fossunited/quiz-cleanup
refactor: Quiz cleanup
2021-08-03 19:04:37 +05:30
pateljannat
44ca940c6b fix: quiz enhancements and tests 2021-08-03 18:30:52 +05:30
pateljannat
c0b688c720 Merge branch 'main' of https://github.com/frappe/community into quiz-cleanup 2021-07-30 18:35:23 +05:30
Jannat Patel
861d5f231d Merge pull request #164 from fossunited/issues
fix: default image, meta, reviews, lesson headers
2021-07-30 17:07:19 +05:30
pateljannat
d14b4f55a6 fix: default image, meta, reviews, lesson headers 2021-07-30 16:24:56 +05:30
Jannat Patel
db9a6c3eda Merge pull request #163 from fossunited/chapter-lesson-patch-fix
fix: chapter lesson patch
2021-07-29 13:48:23 +05:30
pateljannat
a667643681 fix: chapter lesson patch 2021-07-29 13:43:31 +05:30
Jannat Patel
f278e4b6a5 Merge pull request #162 from fossunited/lesson-enhancements
fix: lesson indexing
2021-07-29 12:12:14 +05:30
pateljannat
33a12c2dec fix: lesson indexing 2021-07-29 11:54:30 +05:30
Jannat Patel
508f90f459 Merge pull request #161 from fossunited/upcoming-courses
fix: upcoming course and doctype cleanup
2021-07-26 12:22:02 +05:30
pateljannat
709f0c2274 fix: profile profession section width 2021-07-26 11:42:30 +05:30
pateljannat
be47700e7c Merge branch 'main' of https://github.com/frappe/community into upcoming-courses 2021-07-26 11:14:38 +05:30
pateljannat
40842830a4 fix: profile page social icons position 2021-07-26 11:14:32 +05:30
pateljannat
11d070fa0d fix: condition for chapter description 2021-07-23 19:16:36 +05:30
pateljannat
dd2f830a33 fix: upcoming course and doctype cleanup 2021-07-23 19:07:26 +05:30
pateljannat
5431fcb450 fix: quiz ui change 2021-07-23 17:55:41 +05:30
Jannat Patel
324033e9ee Merge pull request #160 from fossunited/only-show-published-courses
fix: minor issues
2021-07-20 17:35:18 +05:30
pateljannat
86596d0cfe fix: minor issues 2021-07-20 17:19:18 +05:30
Jannat Patel
9323cfd748 Merge pull request #159 from rmehta/fix-global-container
fix(style): max-width on container padding
2021-07-20 13:06:36 +05:30
Jannat Patel
d125b02cec fix: added max width to container padding 2021-07-20 13:05:15 +05:30
pateljannat
282c4c5351 feat: explanation field in quiz 2021-07-20 09:36:22 +05:30
Rushabh Mehta
276d64a66a fix(style): don't mess with global container styles 2021-07-20 09:30:58 +05:30
Rushabh Mehta
79eb381a41 Merge pull request #157 from rmehta/remove-old-styles
fix(cleanup): remove old styles
2021-07-19 17:19:54 +05:30
Rushabh Mehta
44f9c0dfd3 fix(minor): remove old styles 2021-07-19 17:14:52 +05:30
Jannat Patel
0ca4cd724e Merge pull request #156 from fossunited/fix-only-show-published-courses
fix: only show the published courses on All Courses page
2021-07-19 17:11:03 +05:30
Anand Chitipothu
8a3e31f021 fix: only show the published courses on All Courses page
Closes #155
2021-07-19 17:03:38 +05:30
Jannat Patel
9be8a1af0b Merge pull request #154 from fossunited/fix-invite-email
Fix invite email
2021-07-19 13:43:36 +05:30
Anand Chitipothu
b9cac20613 fix: the delay in sending signup email 2021-07-19 13:32:18 +05:30
Anand Chitipothu
e6d5e6d37b fix: "Hello None" in the signup email
We were trying to show the full_name, but invite request only knows the email.
2021-07-19 13:31:44 +05:30
Jannat Patel
0abfcac7da Merge pull request #153 from fossunited/improve-email-templates
fix: fixed the email message sent out on signup
2021-07-19 13:23:55 +05:30
Anand Chitipothu
b70e8b9acc fix: fixed the email message sent out on signup
Currently updated keeping Mon.School in mind.
2021-07-19 13:14:13 +05:30
Jannat Patel
3b1e1aa3c3 Merge pull request #152 from fossunited/cleanup
fix: Cleanup
2021-07-19 12:49:22 +05:30
pateljannat
8f74c74d50 fix: removed unused styles and folders 2021-07-19 10:55:06 +05:30
pateljannat
d2f435016c fix: layout cleanup 2021-07-16 20:24:35 +05:30
pateljannat
389b35802b Merge branch 'main' of https://github.com/frappe/community into cleanup 2021-07-15 17:36:31 +05:30
Jannat Patel
a9192a74f9 Merge pull request #151 from fossunited/redesign-fixes
fix: Profile page, course card ratings, lesson completion tick
2021-07-15 17:36:17 +05:30
pateljannat
1366c7cf75 fix: removed unwanted image 2021-07-15 17:16:49 +05:30
pateljannat
eaa9e8e3ea fix: added linkedin icon 2021-07-15 17:05:54 +05:30
pateljannat
5ecae0df61 fix: removed unused pages 2021-07-15 17:01:15 +05:30
pateljannat
4891be1d8c fix: profile page fixes and course completion tick 2021-07-15 11:16:01 +05:30
pateljannat
ec852fc255 fix: rating on course card and profile page responsive 2021-07-13 16:54:45 +05:30
Jannat Patel
47f2d3cb7b Merge pull request #148 from fossunited/redesign
feat: Redesign
2021-07-13 15:22:59 +05:30
pateljannat
37820c1e19 Merge branch 'redesign' of https://github.com/frappe/community into redesign 2021-07-13 15:15:29 +05:30
pateljannat
230fab3bb2 fix: responsive design 2021-07-13 15:15:23 +05:30
Jannat Patel
d292d2d093 Merge pull request #149 from fossunited/disable-exercises-for-non-members
feat: include membership info in page context
2021-07-12 10:59:28 +05:30
Anand Chitipothu
51d5db01e9 feat: include membership info in page context
Added `is_member` field to page_context of learn page. This is required to
disable exercises to non-members.
2021-07-11 12:55:26 +05:30
pateljannat
0fd760df81 fix: pre tag overflow 2021-07-09 18:32:51 +05:30
pateljannat
71d0a89968 fix: made image non mandatory, remove unnecessary code 2021-07-09 15:05:46 +05:30
pateljannat
d939a63412 responsive fixes 2021-07-09 13:24:38 +05:30
pateljannat
daaa2d2fe2 responsive fixes 2021-07-09 13:03:42 +05:30
pateljannat
6dd7cb19df Merge branch 'main' of https://github.com/frappe/community into redesign 2021-07-09 09:50:38 +05:30
pateljannat
b1de2481a8 feat: profile page and other issues 2021-07-09 09:48:08 +05:30
pateljannat
27c01b3b0c fix: course details interactions 2021-07-08 10:55:03 +05:30
Jannat Patel
b7aa9aff51 Merge pull request #147 from fossunited/fix-profile
fix: error on profile page
2021-07-08 10:41:08 +05:30
Anand Chitipothu
524a041fb9 fix: error on profile page
Profile page was importing Sketch which was removed recently, even
though it was not using that. Removed it to fix the issue.
2021-07-08 10:33:12 +05:30
Jannat Patel
9de0203914 Merge pull request #145 from fossunited/sketch-cleanup
Sketch cleanup
2021-07-07 11:22:05 +05:30
pateljannat
0ed5309b97 feat: course details page structure 2021-07-06 20:51:20 +05:30
pateljannat
68fd32d536 fix: links and breadcrumbs 2021-07-06 18:13:09 +05:30
pateljannat
5ea3b25d21 feat: course home 2021-07-06 17:58:36 +05:30
Anand Chitipothu
2c24412633 refactor: removed the unused dashboard portal page 2021-07-06 14:20:00 +05:30
Anand Chitipothu
1b8a45ba4a refactor: removed sketch doctype and portal page for home
Both of these will be moved to mon_school.
2021-07-06 13:20:41 +05:30
Jannat Patel
3dd4adbc1f Merge pull request #143 from fossunited/switch-batch
feat: added a utililty to switch a student from one batch to another
2021-07-05 19:04:52 +05:30
Jannat Patel
0c52c9c4bc Merge pull request #144 from fossunited/page-context
feat: make it possible to enable tracking for livecode execution
2021-07-05 19:03:47 +05:30
Anand Chitipothu
9caf44cdbd feat: make it possible to enable tracking for livecode execution
Tracking of livecode execution is made possible by making the page
context with course, batch and lesson available in js.

Added a global page_context variable in js and the data for that gets
initialzied in the learn.py.
2021-07-02 23:58:59 +05:30
pateljannat
45d88bdc08 feat: course header wide 2021-07-02 15:43:21 +05:30
Anand Chitipothu
94b3ccd3d9 feat: added a utililty to switch a student from one batch to another 2021-07-01 17:29:02 +05:30
pateljannat
ee8273fd30 feat: new fields in user doctype and new web form 2021-06-30 16:16:22 +05:30
pateljannat
60c1449f40 Merge branch 'main' of https://github.com/frappe/community into redesign 2021-06-29 19:28:50 +05:30
Jannat Patel
67708325ae Merge pull request #141 from fossunited/workspace
feat: lms workspace
2021-06-29 15:24:22 +05:30
pateljannat
3e99577401 feat: lms workspace 2021-06-29 15:15:49 +05:30
pateljannat
5e916dc2c8 feat: review card style 2021-06-29 12:58:12 +05:30
pateljannat
0c64d46e99 feat: reviews 2021-06-28 20:27:17 +05:30
pateljannat
3aa974f8bd fix: removed review doctype 2021-06-28 13:26:29 +05:30
Jannat Patel
621d01d502 Merge pull request #140 from fossunited/exercise-refactor
fix: enabled livecode on community
2021-06-28 13:11:26 +05:30
pateljannat
aa20136223 fix: undo status change on livecode 2021-06-28 13:05:20 +05:30
pateljannat
9bc5408a44 feat: course card redesign 2021-06-28 12:52:10 +05:30
pateljannat
5a7afb3092 fix: added livecode editor in community 2021-06-24 16:38:02 +05:30
Jannat Patel
f8948ac2ef Merge pull request #138 from fossunited/learn-page-fix
fix: learn page
2021-06-24 12:28:34 +05:30
pateljannat
8b1576a028 fix: learn page 2021-06-24 12:21:25 +05:30
Jannat Patel
56d8a72a7d Merge pull request #136 from fossunited/quiz
feat: Quizzes, Youtube Video integration and Other Minor Fixes
2021-06-24 10:34:36 +05:30
pateljannat
f6c11ce52f fix: conflicts 2021-06-24 10:27:01 +05:30
pateljannat
0284c9305c fix: quiz progress and youtube video integration 2021-06-24 10:25:23 +05:30
Jannat Patel
d785fb7562 Merge pull request #127 from fossunited/livecode-cleanup
refactor: removed the portal pages for showing sketches
2021-06-23 13:09:26 +05:30
Anand Chitipothu
9f50af4ebd refactor: removed the portal pages for showing sketches
Moved them to mon_school.
2021-06-23 12:53:35 +05:30
Jannat Patel
4c3645f0d4 Merge pull request #133 from fossunited/mon-fixes-01
Various fixes from mon.school
2021-06-23 11:44:35 +05:30
pateljannat
5d96bf544d fix: conflicts 2021-06-22 12:28:12 +05:30
pateljannat
1cb81de5c0 feat: lms quizzes 2021-06-09 13:17:42 +05:30
194 changed files with 13642 additions and 2781 deletions

3
.gitignore vendored
View File

@@ -5,3 +5,6 @@
tags tags
community/docs/current community/docs/current
community/public/dist community/public/dist
__pycache__/
*.py[cod]
*$py.class

View File

@@ -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) {
// }
});

View File

@@ -1,67 +1,53 @@
{ {
"actions": [], "actions": [],
"creation": "2021-03-19 12:19:32.355307", "creation": "2021-08-11 10:59:38.597046",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"author", "thread",
"batch", "column_break_2",
"column_break_3", "parent_message",
"author_name", "section_break_4",
"pin",
"section_break_6",
"message" "message"
], ],
"fields": [ "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", "fieldname": "message",
"fieldtype": "Markdown Editor", "fieldtype": "Long Text",
"in_list_view": 1, "in_list_view": 1,
"label": "Message" "label": "Message"
}, },
{ {
"default": "0", "fieldname": "thread",
"fieldname": "pin", "fieldtype": "Link",
"fieldtype": "Check", "in_list_view": 1,
"label": "Pin" "in_standard_filter": 1,
"label": "Thread",
"options": "Discussion Thread"
}, },
{ {
"fetch_from": "author.full_name", "fieldname": "column_break_2",
"fieldname": "author_name",
"fieldtype": "Data",
"label": "Author Name",
"read_only": 1
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break" "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" "fieldtype": "Section Break"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-05-21 11:49:34.911479", "modified": "2021-08-12 15:59:04.811286",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "Community",
"name": "LMS Message", "name": "Discussion Message",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
@@ -77,9 +63,7 @@
"write": 1 "write": 1
} }
], ],
"quick_entry": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"title_field": "author",
"track_changes": 1 "track_changes": 1
} }

View File

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

View File

@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and Contributors # Copyright (c) 2021, FOSS United and Contributors
# See license.txt # See license.txt
from __future__ import unicode_literals
# import frappe # import frappe
import unittest import unittest
class TestLMSSketch(unittest.TestCase): class TestDiscussionMessage(unittest.TestCase):
pass pass

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2021, FOSS United and contributors // Copyright (c) 2021, FOSS United and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('LMS Message', { frappe.ui.form.on('Discussion Thread', {
// refresh: function(frm) { // refresh: function(frm) {
// } // }

View File

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

View File

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

View File

@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and Contributors # Copyright (c) 2021, FOSS United and Contributors
# See license.txt # See license.txt
from __future__ import unicode_literals
# import frappe # import frappe
import unittest import unittest
class TestLMSMessage(unittest.TestCase): class TestDiscussionThread(unittest.TestCase):
pass pass

View File

@@ -1,5 +1,5 @@
{% set color = member.get_palette() %} {% 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 }}"> <span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
{% if member.user_image %} {% if member.user_image %}
<img class="avatar-frame standard-image" style="object-fit: cover;" src="{{ member.user_image }}" title="{{ member.full_name }}"> <img class="avatar-frame standard-image" style="object-fit: cover;" src="{{ member.user_image }}" title="{{ member.full_name }}">

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

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

View 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
}
]

View File

@@ -104,6 +104,8 @@ doc_events = {
# ] # ]
#} #}
fixtures = ["Custom Field"]
# Testing # Testing
# ------- # -------
@@ -131,10 +133,9 @@ doc_events = {
primary_rules = [ primary_rules = [
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"}, {"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
{"from_route": "/courses/<course>", "to_route": "courses/course"}, {"from_route": "/courses/<course>", "to_route": "courses/course"},
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"}, {"from_route": "/courses/<course>/<certificate>", "to_route": "courses/certificate"},
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"}, {"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"}, {"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
{"from_route": "/dashboard", "to_route": ""},
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"}, {"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
{"from_route": "/courses/<course>/home", "to_route": "batch/home"}, {"from_route": "/courses/<course>/home", "to_route": "batch/home"},
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"}, {"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
@@ -144,7 +145,8 @@ primary_rules = [
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"}, {"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
{"from_route": "/courses/<course>/about", "to_route": "batch/about"}, {"from_route": "/courses/<course>/about", "to_route": "batch/about"},
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"}, {"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
{"from_route": "/courses/<course>/join", "to_route": "batch/join"} {"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 # Any frappe default URL is blocked by profile-rules, add it here to unblock it
@@ -161,11 +163,13 @@ whitelist = [
"/socket.io", "/socket.io",
"/hackathons", "/hackathons",
"/dashboard", "/dashboard",
"/join-request" "/join-request",
"/add-a-new-batch", "/add-a-new-batch",
"/new-sign-up", "/new-sign-up",
"/message" "/message",
"/about" "/about",
"/edit-profile",
"/discussions"
] ]
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist] whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
@@ -176,6 +180,10 @@ profile_rules = [
website_route_rules = primary_rules + whitelist_rules + 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' update_website_context = 'community.widgets.update_website_context'
## Specify the additional tabs to be included in the user profile page. ## Specify the additional tabs to be included in the user profile page.
@@ -187,5 +195,13 @@ update_website_context = 'community.widgets.update_website_context'
## subclass of community.community.plugins.PageExtension ## subclass of community.community.plugins.PageExtension
# community_lesson_page_extension = None # community_lesson_page_extension = None
community_lesson_page_extensions = [
"community.plugins.LiveCodeExtension"
]
## Markdown Macros for Lessons ## Markdown Macros for Lessons
# community_markdown_macro_renderers = {"Exercise": "myapp.mymodule.plugins.render_exercise"} community_markdown_macro_renderers = {
"Exercise": "community.plugins.exercise_renderer",
"Quiz": "community.plugins.quiz_renderer",
"YouTubeVideo": "community.plugins.youtube_video_renderer",
}

View File

@@ -2,7 +2,15 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('Chapter', { frappe.ui.form.on('Chapter', {
// refresh: function(frm) {
// } onload: function (frm) {
frm.set_query("lesson", "lessons", function () {
return {
filters: {
"chapter": frm.doc.name,
}
};
});
}
}); });

View File

@@ -9,8 +9,7 @@
"course", "course",
"title", "title",
"description", "description",
"locked", "lessons"
"index_"
], ],
"fields": [ "fields": [
{ {
@@ -24,12 +23,6 @@
"fieldtype": "Markdown Editor", "fieldtype": "Markdown Editor",
"label": "Description" "label": "Description"
}, },
{
"default": "0",
"fieldname": "locked",
"fieldtype": "Check",
"label": "Locked"
},
{ {
"fieldname": "course", "fieldname": "course",
"fieldtype": "Link", "fieldtype": "Link",
@@ -38,10 +31,10 @@
"options": "LMS Course" "options": "LMS Course"
}, },
{ {
"default": "1", "fieldname": "lessons",
"fieldname": "index_", "fieldtype": "Table",
"fieldtype": "Int", "label": "Lessons",
"label": "Index" "options": "Lessons"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
@@ -52,7 +45,7 @@
"link_fieldname": "chapter" "link_fieldname": "chapter"
} }
], ],
"modified": "2021-05-13 21:05:20.531890", "modified": "2021-07-27 16:28:08.667964",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Chapter", "name": "Chapter",

View File

@@ -7,9 +7,4 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
class Chapter(Document): class Chapter(Document):
def get_lessons(self): pass
rows = frappe.db.get_all("Lesson",
filters={"chapter": self.name},
fields='name',
order_by="index_")
return [frappe.get_doc('Lesson', row['name']) for row in rows]

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

View 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 Chapters(Document):
pass

View File

@@ -3,7 +3,6 @@
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
# from ..lms_sketch.livecode import livecode_to_svg
class Exercise(Document): class Exercise(Document):
def get_user_submission(self): def get_user_submission(self):

View File

@@ -6,12 +6,17 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"exercise", "exercise",
"solution", "status",
"batch",
"column_break_4",
"exercise_title", "exercise_title",
"course", "course",
"batch",
"lesson", "lesson",
"image" "section_break_8",
"solution",
"image",
"test_results",
"comments"
], ],
"fields": [ "fields": [
{ {
@@ -21,12 +26,6 @@
"label": "Exercise", "label": "Exercise",
"options": "Exercise" "options": "Exercise"
}, },
{
"fieldname": "solution",
"fieldtype": "Code",
"in_list_view": 1,
"label": "Solution"
},
{ {
"fetch_from": "exercise.title", "fetch_from": "exercise.title",
"fieldname": "exercise_title", "fieldname": "exercise_title",
@@ -61,11 +60,41 @@
"fieldtype": "Code", "fieldtype": "Code",
"label": "Image", "label": "Image",
"read_only": 1 "read_only": 1
},
{
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Correct\nIncorrect"
},
{
"fieldname": "test_results",
"fieldtype": "Small Text",
"label": "Test Results"
},
{
"fieldname": "comments",
"fieldtype": "Small Text",
"label": "Comments"
},
{
"fieldname": "solution",
"fieldtype": "Code",
"in_list_view": 1,
"label": "Solution"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fieldname": "section_break_8",
"fieldtype": "Section Break"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-05-21 11:28:45.833018", "modified": "2021-06-24 16:22:50.570845",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Exercise Submission", "name": "Exercise Submission",

View File

@@ -30,10 +30,13 @@ class InviteRequest(Document):
return user return user
def send_email(self): def send_email(self):
subject = _("Your request has been approved.") site_name = "Mon.School"
subject = _("Welcome to {0}!").format(site_name)
args = { args = {
"full_name": self.full_name, "full_name": self.full_name,
"signup_form_link": "/new-sign-up?invite_code={0}".format(self.name), "signup_form_link": "/new-sign-up?invite_code={0}".format(self.name),
"site_name": site_name,
"site_url": frappe.utils.get_url() "site_url": frappe.utils.get_url()
} }
frappe.sendmail( frappe.sendmail(
@@ -42,7 +45,8 @@ class InviteRequest(Document):
subject=subject, subject=subject,
header=[subject, "green"], header=[subject, "green"],
template = "lms_invite_request_approved", template = "lms_invite_request_approved",
args=args) args=args,
now=True)
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def create_invite_request(invite_email): def create_invite_request(invite_email):

View File

@@ -2,7 +2,47 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('Lesson', { frappe.ui.form.on('Lesson', {
// refresh: function(frm) { setup: function (frm) {
frm.trigger('setup_help');
},
setup_help(frm) {
frm.get_field('help').html(`
<p>You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p>
<div class="row font-weight-bold mb-3">
<div class="col-sm-4">
Content Type
</div>
<div class="col-sm-4">
Syntax
</div>
</div>
// } <div class="row mb-3">
<div class="col-sm-4">
YouTube Video
</div>
<div class="col-sm-4">
{{ YouTubeVideo("unique_embed_id") }}
</div>
</div>
<div class="row mb-3">
<div class="col-sm-4">
Exercise
</div>
<div class="col-sm-4">
{{ Exercise("exercise_name") }}
</div>
</div>
<div class="row mb-3">
<div class="col-sm-4">
Quiz
</div>
<div class="col-sm-4">
{{ Quiz("lms_quiz_name") }}
</div>
</div>
`);
}
}); });

View File

@@ -7,14 +7,14 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"chapter", "chapter",
"lesson_type",
"include_in_preview", "include_in_preview",
"column_break_4", "column_break_4",
"title", "title",
"index_",
"index_label", "index_label",
"section_break_6", "section_break_6",
"body" "body",
"help_section",
"help"
], ],
"fields": [ "fields": [
{ {
@@ -24,26 +24,12 @@
"label": "Chapter", "label": "Chapter",
"options": "Chapter" "options": "Chapter"
}, },
{
"default": "Video",
"fieldname": "lesson_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Lesson Type",
"options": "Video\nText\nQuiz"
},
{ {
"fieldname": "title", "fieldname": "title",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1, "in_list_view": 1,
"label": "Title" "label": "Title"
}, },
{
"default": "1",
"fieldname": "index_",
"fieldtype": "Int",
"label": "Index"
},
{ {
"fieldname": "body", "fieldname": "body",
"fieldtype": "Markdown Editor", "fieldtype": "Markdown Editor",
@@ -52,7 +38,6 @@
{ {
"fieldname": "index_label", "fieldname": "index_label",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1,
"label": "Index Label", "label": "Index Label",
"read_only": 1 "read_only": 1
}, },
@@ -69,11 +54,20 @@
{ {
"fieldname": "column_break_4", "fieldname": "column_break_4",
"fieldtype": "Column Break" "fieldtype": "Column Break"
},
{
"fieldname": "help_section",
"fieldtype": "Section Break",
"label": "Help"
},
{
"fieldname": "help",
"fieldtype": "HTML"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-06-11 19:03:23.138165", "modified": "2021-07-27 16:28:29.203624",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Lesson", "name": "Lesson",

View File

@@ -9,27 +9,35 @@ from ...md import markdown_to_html, find_macros
class Lesson(Document): class Lesson(Document):
def before_save(self): def before_save(self):
macros = find_macros(self.body) dynamic_documents = ["Exercise", "Quiz"]
exercises = [value for name, value in macros if name == "Exercise"] for section in dynamic_documents:
self.update_lesson_name_in_document(section)
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 index = 1
for name in exercises: for name in documents:
e = frappe.get_doc("Exercise", name) e = frappe.get_doc(doctype_map[section], name)
e.lesson = self.name e.lesson = self.name
e.index_ = index e.index_ = index
e.save() e.save()
index += 1 index += 1
self.update_orphan_exercises(exercises) self.update_orphan_documents(doctype_map[section], documents)
def update_orphan_exercises(self, active_exercises): def update_orphan_documents(self, doctype, documents):
"""Updates the exercises that were previously part of this lesson, """Updates the documents that were previously part of this lesson,
but not any more. but not any more.
""" """
linked_exercises = {row['name'] for row in frappe.get_all('Exercise', {"lesson": self.name})} linked_documents = {row['name'] for row in frappe.get_all(doctype, {"lesson": self.name})}
active_exercises = set(active_exercises) active_documents = set(documents)
orphan_exercises = linked_exercises - active_exercises orphan_documents = linked_documents - active_documents
for name in orphan_exercises: for name in orphan_documents:
ex = frappe.get_doc("Exercise", name) ex = frappe.get_doc(doctype, name)
ex.lesson = None ex.lesson = None
ex.index_ = 0 ex.index_ = 0
ex.index_label = "" ex.index_label = ""
@@ -55,32 +63,36 @@ class Lesson(Document):
return return
@frappe.whitelist() @frappe.whitelist()
def save_progress(lesson, course): def save_progress(lesson, course, status):
if not frappe.db.exists("LMS Batch Membership", if not frappe.db.exists("LMS Batch Membership",
{ {
"member": frappe.session.user, "member": frappe.session.user,
"course": course "course": course
}): }):
return return
if frappe.db.exists("LMS Course Progress", if frappe.db.exists("LMS Course Progress",
{ {
"lesson": lesson, "lesson": lesson,
"owner": frappe.session.user "owner": frappe.session.user,
"course": course
}): }):
return doc = frappe.get_doc("LMS Course Progress",
{
lesson_details = frappe.get_doc("Lesson", lesson) "lesson": lesson,
dynamic_content = find_macros(lesson_details.body) "owner": frappe.session.user,
"course": course
status = "Complete" })
if dynamic_content: doc.status = status
status = "Partially Complete" doc.save(ignore_permissions=True)
else:
frappe.get_doc({ frappe.get_doc({
"doctype": "LMS Course Progress", "doctype": "LMS Course Progress",
"lesson": lesson_details.name, "lesson": lesson,
"status": status "status": status,
}).save(ignore_permissions=True) }).save(ignore_permissions=True)
course_details = frappe.get_doc("LMS Course", course)
return course_details.get_course_progress()
def update_progress(lesson): def update_progress(lesson):
user = frappe.session.user user = frappe.session.user
@@ -92,13 +104,30 @@ def update_progress(lesson):
course_progress.save(ignore_permissions=True) course_progress.save(ignore_permissions=True)
def all_dynamic_content_submitted(lesson, user): 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) exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, pluck="name", ignore_permissions=True)
all_exercises_submitted = False if not len(exercise_names):
return True
query = { query = {
"exercise": ["in", exercise_names], "exercise": ["in", exercise_names],
"owner": user "owner": user
} }
if frappe.db.count("Exercise Submission", query) == len(exercise_names): if frappe.db.count("Exercise Submission", query) == len(exercise_names):
all_exercises_submitted = True return True
return False
return all_exercises_submitted def check_all_quiz_submitted(lesson, user):
quizzes = frappe.get_list("LMS Quiz", {"lesson": lesson}, pluck="name", ignore_permissions=True)
if not len(quizzes):
return True
query = {
"quiz": ["in", quizzes],
"owner": user
}
if frappe.db.count("LMS Quiz Submission", query) == len(quizzes):
return True
return False

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

View 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

View File

@@ -71,3 +71,38 @@ def save_message(message, batch):
"message": message "message": message
}) })
doc.save(ignore_permissions=True) doc.save(ignore_permissions=True)
def switch_batch(course_name, email, batch_name):
"""Switches the user from the current batch of the course to a new batch.
"""
membership = frappe.get_last_doc(
"LMS Batch Membership",
filters={"course": course_name, "member": email})
batch = frappe.get_doc("LMS Batch", batch_name)
if not batch:
raise ValueError(f"Invalid Batch: {batch_name}")
if batch.course != course_name:
raise ValueError("Can not switch batches across courses")
if batch.is_member(email):
print(f"{email} is already a member of {batch.title}")
return
old_batch = frappe.get_doc("LMS Batch", membership.batch)
print("updating membership", membership.name)
membership.batch = batch_name
membership.save()
# update exercise submissions
filters = {
"owner": email,
"batch": old_batch.name
}
for name in frappe.db.get_all("Exercise Submission", filters=filters, pluck='name'):
doc = frappe.get_doc("Exercise Submission", name)
print("updating exercise submission", name)
doc.batch = batch_name
doc.save()

View File

@@ -10,5 +10,5 @@ frappe.ui.form.on('LMS Batch Membership', {
} }
}; };
}); });
}, }
}); });

View File

@@ -37,6 +37,7 @@
"fieldname": "member_type", "fieldname": "member_type",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1,
"label": "Member Type", "label": "Member Type",
"options": "\nStudent\nMentor\nStaff" "options": "\nStudent\nMentor\nStaff"
}, },
@@ -44,7 +45,6 @@
"default": "Member", "default": "Member",
"fieldname": "role", "fieldname": "role",
"fieldtype": "Select", "fieldtype": "Select",
"in_standard_filter": 1,
"label": "Role", "label": "Role",
"options": "\nMember\nAdmin" "options": "\nMember\nAdmin"
}, },
@@ -63,10 +63,10 @@
{ {
"fetch_from": "batch.course", "fetch_from": "batch.course",
"fieldname": "course", "fieldname": "course",
"fieldtype": "Data", "fieldtype": "Link",
"in_list_view": 1, "in_list_view": 1,
"label": "Course", "label": "Course",
"read_only": 1 "options": "LMS Course"
}, },
{ {
"fieldname": "current_lesson", "fieldname": "current_lesson",
@@ -84,7 +84,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-06-21 12:10:28.808803", "modified": "2021-08-04 17:10:42.708479",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Batch Membership", "name": "LMS Batch Membership",

View File

@@ -0,0 +1,14 @@
// Copyright (c) 2021, FOSS United and contributors
// For license information, please see license.txt
frappe.ui.form.on('LMS Certification', {
onload: function (frm) {
frm.set_query("student", function (doc) {
return {
filters: {
"ignore_user_type": 1,
}
};
});
}
});

View File

@@ -0,0 +1,70 @@
{
"actions": [],
"creation": "2021-08-16 15:47:19.494055",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"student",
"issue_date",
"column_break_3",
"course",
"expiry_date"
],
"fields": [
{
"fieldname": "student",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Student",
"options": "User"
},
{
"fieldname": "issue_date",
"fieldtype": "Date",
"label": "Issue Date"
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "course",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Course",
"options": "LMS Course"
},
{
"fieldname": "expiry_date",
"fieldtype": "Date",
"label": "Expiry Date"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-08-16 15:47:19.494055",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Certification",
"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
}

View File

@@ -0,0 +1,41 @@
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
import frappe
from frappe.model.document import Document
from frappe.utils import nowdate, add_years
from frappe import _
from frappe.utils.pdf import get_pdf
class LMSCertification(Document):
def validate(self):
certificates = frappe.get_all("LMS Certification", {
"student": self.student,
"course": self.course,
"expiry_date": [">", nowdate()]
})
if len(certificates):
full_name = frappe.db.get_value("User", self.student, "full_name")
course_name = frappe.db.get_value("LMS Course", self.course, "title")
frappe.throw(_("There is already a valid certificate for user {0} for the course {1}").format(full_name, course_name))
@frappe.whitelist()
def create_certificate(course):
course_details = frappe.get_doc("LMS Course", course)
certificate = course_details.is_certified()
if certificate:
return certificate
else:
expires_after_yrs = course_details.expiry
certificate = frappe.get_doc({
"doctype": "LMS Certification",
"student": frappe.session.user,
"course": course,
"issue_date": nowdate(),
"expiry_date": add_years(nowdate(), int(expires_after_yrs))
})
certificate.save(ignore_permissions=True)
return certificate.name

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
# import frappe
import unittest
class TestLMSCertification(unittest.TestCase):
pass

View File

@@ -2,7 +2,15 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('LMS Course', { frappe.ui.form.on('LMS Course', {
// refresh: function(frm) {
// } onload: function (frm) {
frm.set_query("chapter", "chapters", function () {
return {
filters: {
"course": frm.doc.name,
}
};
});
}
}); });

View File

@@ -1,11 +1,5 @@
{ {
"actions": [ "actions": [
{
"action": "community.lms.doctype.lms_course.lms_course.reindex_lessons",
"action_type": "Server Action",
"group": "Reindex",
"label": "Reindex Lessons"
},
{ {
"action": "community.lms.doctype.lms_course.lms_course.reindex_exercises", "action": "community.lms.doctype.lms_course.lms_course.reindex_exercises",
"action_type": "Server Action", "action_type": "Server Action",
@@ -21,14 +15,20 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"title", "title",
"is_published",
"disable_self_learning",
"column_break_3",
"short_code",
"video_link", "video_link",
"image",
"column_break_3",
"tags",
"is_published",
"upcoming",
"disable_self_learning",
"section_break_5", "section_break_5",
"short_introduction", "short_introduction",
"description" "description",
"chapters",
"certification_section",
"enable_certification",
"expiry"
], ],
"fields": [ "fields": [
{ {
@@ -51,11 +51,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Published" "label": "Published"
}, },
{
"fieldname": "short_code",
"fieldtype": "Data",
"label": "Short Code"
},
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break"
@@ -80,6 +75,47 @@
"fieldname": "disable_self_learning", "fieldname": "disable_self_learning",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Disable Self Learning" "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"
},
{
"fieldname": "certification_section",
"fieldtype": "Section Break",
"label": "Certification"
},
{
"default": "0",
"fieldname": "enable_certification",
"fieldtype": "Check",
"label": "Enable Certification"
},
{
"default": "0",
"depends_on": "enable_certification",
"fieldname": "expiry",
"fieldtype": "Select",
"label": "Certification Expires After Years",
"options": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
@@ -99,14 +135,9 @@
"group": "Mentors", "group": "Mentors",
"link_doctype": "LMS Course Mentor Mapping", "link_doctype": "LMS Course Mentor Mapping",
"link_fieldname": "course" "link_fieldname": "course"
},
{
"group": "Mentors",
"link_doctype": "LMS Mentor Request",
"link_fieldname": "course"
} }
], ],
"modified": "2021-06-21 11:34:04.552376", "modified": "2021-08-18 18:02:12.623807",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Course", "name": "LMS Course",
@@ -129,6 +160,5 @@
"sort_field": "creation", "sort_field": "creation",
"sort_order": "DESC", "sort_order": "DESC",
"title_field": "title", "title_field": "title",
"track_changes": 1, "track_changes": 1
"track_views": 1
} }

View File

@@ -8,9 +8,43 @@ from frappe.model.document import Document
import json import json
from ...utils import slugify from ...utils import slugify
from community.query import find, find_all from community.query import find, find_all
from frappe.utils import flt from frappe.utils import flt, cint
from ...utils import slugify
class LMSCourse(Document): 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 @staticmethod
def find(name): def find(name):
"""Returns the course with specified name. """Returns the course with specified name.
@@ -72,8 +106,11 @@ class LMSCourse(Document):
mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name}, ["mentor"]) mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name}, ["mentor"])
for mentor in mentors: for mentor in mentors:
member = frappe.get_doc("User", mentor.mentor) member = frappe.get_doc("User", mentor.mentor)
# TODO: change this to count query member.batch_count = frappe.db.count("LMS Batch Membership",
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"})) {
"member": member.name,
"member_type": "Mentor"
})
course_mentors.append(member) course_mentors.append(member)
return course_mentors return course_mentors
@@ -112,8 +149,55 @@ class LMSCourse(Document):
def get_chapters(self): def get_chapters(self):
"""Returns all chapters of this course. """Returns all chapters of this course.
""" """
# TODO: chapters should have a way to specify the order chapters = []
return find_all("Chapter", course=self.name, order_by="index_") 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): def get_batch(self, batch_name):
return find("LMS Batch", name=batch_name, course=self.name) return find("LMS Batch", name=batch_name, course=self.name)
@@ -138,38 +222,18 @@ class LMSCourse(Document):
visibility="Public") visibility="Public")
return batches 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): def get_lesson_index(self, lesson_name):
"""Returns the {chapter_index}.{lesson_index} for the lesson. """Returns the {chapter_index}.{lesson_index} for the lesson.
""" """
lesson = frappe.get_doc("Lesson", lesson_name) lesson = frappe.db.get_value("Lessons", {"lesson": lesson_name}, ["idx", "parent"], as_dict=True)
chapter = frappe.get_doc("Chapter", lesson.chapter) if not lesson:
return f"{chapter.index_}.{lesson.index_}" return None
def reindex_lessons(self): chapter = frappe.db.get_value("Chapters", {"chapter": lesson.parent}, ["idx"], as_dict=True)
for i, c in enumerate(self.get_chapters(), start=1): if not chapter:
c.index_ = i return None
c.save()
self._reindex_lessons_in_chapter(c)
def _reindex_lessons_in_chapter(self, c): return f"{chapter.idx}.{lesson.idx}"
for i, lesson in enumerate(c.get_lessons(), start=1):
lesson.index = i
lesson.index_label = f"{c.index_}.{i}"
lesson.save()
def reindex_exercises(self): def reindex_exercises(self):
for i, c in enumerate(self.get_chapters(), start=1): for i, c in enumerate(self.get_chapters(), start=1):
@@ -180,7 +244,7 @@ class LMSCourse(Document):
def _reindex_exercises_in_chapter(self, c): def _reindex_exercises_in_chapter(self, c):
i = 1 i = 1
for lesson in c.get_lessons(): for lesson in self.get_lessons(c):
for exercise in lesson.get_exercises(): for exercise in lesson.get_exercises():
exercise.index_ = i exercise.index_ = i
exercise.index_label = f"{c.index_}.{i}" exercise.index_label = f"{c.index_}.{i}"
@@ -199,30 +263,22 @@ class LMSCourse(Document):
} }
if batch: if batch:
filters["batch"] = batch filters["batch"] = batch
return frappe.db.get_value("LMS Batch Membership", filters, ["name","batch", "current_lesson"], as_dict=True)
def get_all_memberships(self, member=frappe.session.user): 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"]) all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch"])
for membership in all_memberships: for membership in all_memberships:
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title") membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
print(all_memberships)
return all_memberships return all_memberships
def get_mentors(self, batch=None):
filters = {
"course": self.name,
"member_type": "Mentor"
}
if batch:
filters["batch"] = batch
memberships = frappe.get_all(
"LMS Batch Membership",
filters,
["member"])
member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names])
def get_students(self, batch=None): def get_students(self, batch=None):
"""Returns (email, full_name, username) of all the students of this batch as a list of dict. """Returns (email, full_name, username) of all the students of this batch as a list of dict.
""" """
@@ -239,58 +295,67 @@ class LMSCourse(Document):
member_names = [m['member'] for m in memberships] member_names = [m['member'] for m in memberships]
return find_all("User", name=["IN", member_names]) return find_all("User", name=["IN", member_names])
def get_outline(self): def get_tags(self):
return CourseOutline(self) return self.tags.split(",") if self.tags else []
class CourseOutline: def get_reviews(self):
def __init__(self, course): reviews = frappe.get_all("LMS Course Review",
self.course = course {
self.chapters = self.get_chapters() "course": self.name
self.lessons = self.get_lessons() },
["review", "rating", "owner"],
order_by= "creation desc")
def get_next(self, current): for review in reviews:
current = flt(current) review.owner_details = frappe.get_doc("User", review.owner)
numbers = sorted(lesson['number'] for lesson in self.lessons)
try: return reviews
index = numbers.index(current)
return numbers[index+1] def is_eligible_to_review(self, membership):
except IndexError: """ 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 None
return sum(ratings)/len(ratings)
def get_prev(self, current): 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) current = flt(current)
numbers = sorted(lesson['number'] for lesson in self.lessons) numbers = sorted(lesson.number for lesson in lessons)
try: index = numbers.index(current)
index = numbers.index(current) return {
if index == 0: "prev": numbers[index-1] if index-1 >= 0 else None,
return None "next": numbers[index+1] if index+1 < len(numbers) else None
return numbers[index-1] }
except IndexError:
return None
def get_chapters(self): def is_certified(self):
return frappe.db.get_all("Chapter", certificate = frappe.get_all("LMS Certification",
filters={"course": self.course.name}, {
fields=["name", "title", "index_"], "student": frappe.session.user,
order_by="index_") "course": self.name
})
def get_lessons(self): if len(certificate):
chapters = [c['name'] for c in self.chapters] return certificate[0].name
lessons = frappe.db.get_all("Lesson", return
filters={"chapter": ["IN", chapters]},
fields=["name", "title", "chapter", "index_"])
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
for lesson in lessons:
lesson['number'] = flt("{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_']))
return lessons
@frappe.whitelist()
def reindex_lessons(doc):
course_data = json.loads(doc)
course = frappe.get_doc("LMS Course", course_data['name'])
course.reindex_lessons()
frappe.msgprint("All lessons in this course have been re-indexed.")
@frappe.whitelist() @frappe.whitelist()
def reindex_exercises(doc): def reindex_exercises(doc):

View File

@@ -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) {
// }
});

View File

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

View File

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

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
# import frappe
import unittest
class TestLMSCourseInterest(unittest.TestCase):
pass

View File

@@ -2,7 +2,13 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('LMS Course Mentor Mapping', { 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,
}
};
});
},
}); });

View File

@@ -0,0 +1,8 @@
// Copyright (c) 2021, FOSS United and contributors
// For license information, please see license.txt
frappe.ui.form.on('LMS Course Review', {
// refresh: function(frm) {
// }
});

View File

@@ -0,0 +1,57 @@
{
"actions": [],
"creation": "2021-06-28 13:36:36.146718",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"review",
"rating",
"course"
],
"fields": [
{
"fieldname": "review",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Review"
},
{
"fieldname": "rating",
"fieldtype": "Rating",
"in_list_view": 1,
"label": "Rating"
},
{
"fieldname": "course",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Course",
"options": "LMS Course"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-07-05 14:57:03.841430",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course Review",
"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
}

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

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
# import frappe
import unittest
class TestLMSCourseReview(unittest.TestCase):
pass

View File

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

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

View 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

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2021, FOSS United and contributors // Copyright (c) 2021, FOSS United and contributors
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('LMS Sketch', { frappe.ui.form.on('LMS Quiz', {
// refresh: function(frm) { // refresh: function(frm) {
// } // }

View File

@@ -1,45 +1,42 @@
{ {
"actions": [], "actions": [],
"autoname": "format:SKETCH-{#}", "autoname": "field:title",
"creation": "2021-03-09 16:31:50.523524", "creation": "2021-06-07 10:50:17.893625",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"title", "title",
"runtime", "questions",
"code", "lesson"
"svg"
], ],
"fields": [ "fields": [
{ {
"fieldname": "title", "fieldname": "title",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Title" "label": "Title",
"unique": 1
}, },
{ {
"fieldname": "runtime", "fieldname": "questions",
"fieldtype": "Data", "fieldtype": "Table",
"label": "Runtime" "label": "Questions",
"options": "LMS Quiz Question"
}, },
{ {
"fieldname": "code", "fieldname": "lesson",
"fieldtype": "Code", "fieldtype": "Link",
"label": "Code" "label": "Lesson",
}, "options": "Lesson",
{
"fieldname": "svg",
"fieldtype": "Code",
"label": "SVG",
"read_only": 1 "read_only": 1
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-03-12 08:42:56.671658", "modified": "2021-07-23 19:06:12.551633",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Sketch", "name": "LMS Quiz",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
@@ -57,6 +54,5 @@
], ],
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"track_changes": 1, "track_changes": 1
"track_views": 1
} }

View 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

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

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

View 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 LMSQuizQuestion(Document):
pass

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

View 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

View File

@@ -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) {
// }
});

View File

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

View 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 LMSQuizSubmission(Document):
pass

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
# import frappe
import unittest
class TestLMSQuizSubmission(unittest.TestCase):
pass

View File

@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class LMSSection(Document):
def __repr__(self):
return f"<LMSSection {self.label!r}>"
def get_exercise(self):
if self.type == "exercise":
return frappe.get_doc("Exercise", self.id)
def get_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.
"""
if not frappe.session.user or frappe.session.user == "Guest":
return self.contents
result = frappe.get_all('Code Revision',
fields=["code"],
filters={
"author": frappe.session.user,
"section": self.name
},
order_by="creation desc",
page_length=1)
if result:
return result[0]['code']
else:
return self.contents

View File

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

View File

@@ -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,
}

View File

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

View File

@@ -93,11 +93,11 @@ class MacroInlineProcessor(InlineProcessor):
macro = m.group(1) macro = m.group(1)
arg = m.group(2) arg = m.group(2)
html = render_macro(macro, arg) html = render_macro(macro, arg)
html = sanitize_html(str(html)) html = sanitize_html(str(html), macro)
e = etree.fromstring(html) e = etree.fromstring(html)
return e, m.start(0), m.end(0) return e, m.start(0), m.end(0)
def sanitize_html(html): def sanitize_html(html, macro):
"""Sanotize the html using BeautifulSoup. """Sanotize the html using BeautifulSoup.
The markdown processor request the correct markup and crashes on The markdown processor request the correct markup and crashes on
@@ -106,4 +106,7 @@ def sanitize_html(html):
""" """
soup = BeautifulSoup(html, features="lxml") soup = BeautifulSoup(html, features="lxml")
nodes = soup.body.children nodes = soup.body.children
return "<div>" + "\n".join(str(node) for node in nodes) + "</div>" classname = ""
if macro == "YouTubeVideo":
classname = "lesson-video"
return "<div class='" + classname + "'>" + "\n".join(str(node) for node in nodes) + "</div>"

View File

@@ -1,5 +1,4 @@
"""Handy module to make access to all doctypes from a single place. """Handy module to make access to all doctypes from a single place.
""" """
from .doctype.lms_course.lms_course import LMSCourse as Course from .doctype.lms_course.lms_course import LMSCourse as Course
from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch
from .doctype.lms_batch_membership.lms_batch_membership import LMSBatchMembership as Membership from .doctype.lms_batch_membership.lms_batch_membership import LMSBatchMembership as Membership

View 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"])}`;
})
}
})

View 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
}
]
}

View File

@@ -0,0 +1,5 @@
import frappe
def get_context(context):
# do your magic here
pass

View File

@@ -1,65 +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 %}
{% set all_memberships = course.get_all_memberships() %}
{% if all_memberships | length > 1 %}
<a class="nav-link pull-right" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
Switch Batch
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for data in all_memberships %}
{% if data.batch != membership.batch %}
<a class="dropdown-item switch-batch" href="/courses/{{ course.name }}/home?batch={{ data.batch }}">{{ data.batch_title }}</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
{% if not membership %}
{% set display_class = "hide" %}
{% else %}
{% set display_class = "" %}
{% endif %}
<ul class="nav nav-tabs mt-4">
<li class="nav-item">
<a class="nav-link" id="home" href="/courses/{{course.name}}/home{{ course.query_parameter }}">Home</a>
</li>
<li class="nav-item">
{% set lesson_index = course.get_lesson_index(membership.current_lesson) if membership and membership.current_lesson else '1.1' %}
<a class="nav-link" id="learn"
href="{{ course.get_learn_url(lesson_index) }}{{ course.query_parameter }}">Lessons</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link" id="schedule" href="/courses/{{course.name}}/schedule">Schedule</a>
</li> -->
<li class="nav-item {{ display_class }}">
<a class="nav-link" id="members" href="/courses/{{course.name}}/members{{ course.query_parameter }}">Members</a>
</li>
<!-- <li class="nav-item {{ display_class }}">
<a class="nav-link" id="discussion" href="/courses/{{course.name}}/discuss">Discussion</a>
</li> -->
<!-- <li class="nav-item">
<a class="nav-link" id="about" href="/courses/{{course.name}}/about">About</a>
</li> -->
{% if membership and membership.batch and course.is_mentor(frappe.session.user) %}
<li class="nav-item">
<a class="nav-link" id="progress" href="/courses/{{course.name}}/progress{{ course.query_parameter }}">Progress</a>
</li>
{% endif %}
</ul>
{% block script %}
<script>
frappe.ready(() => {
var selector = document.querySelector(`a[href="${decodeURIComponent(window.location.pathname)}{{ course.query_parameter }}"]`)
if (selector) {
selector.classList.add('active');
}
else {
$("#learn").addClass('active')
}
})
</script>
{% endblock %}

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

View File

@@ -1,53 +1,100 @@
<div class="chapter-teaser"> <div>
<div class="teaser-body">
<div class="chapter-title mb-5 font-weight-bold"><span class="mr-1">{{index}}.</span> {{ chapter.title }}</div> <div class="chapter-title small-title" data-target="#{{ course.get_slugified_chapter_title(chapter.title) }}"
<div class="chapter-description"> data-toggle="collapse" aria-expanded="false">
{{ chapter.description or "" }} <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>
<div class="chapter-lessons"> {% endif %}
{% for lesson in chapter.get_lessons() %}
<div class="lesson-teaser"> <div class="lessons">
<a {% if show_link or lesson.include_in_preview %}
href="{{ course.get_learn_url(course.get_lesson_index(lesson.name)) }}{{course.query_parameter}}" {% else %} href="" class="no-preview" {% for lesson in course.get_lessons(chapter) %}
{% endif %} data-course="{{ course.name }}">{{ lesson.title }}</a>
{% if show_progress and not course.is_mentor(frappe.session.user) and lesson.get_progress() %} <div class="lesson-info{% if membership.current_lesson == lesson.name %} active-lesson {% endif %}">
<span class="ml-5 badge p-2 {{ lesson.get_slugified_class() }}"> {{ lesson.get_progress() }}</span>
{% 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 %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
</div> </div>
{% if index != course.get_chapters() | length %}
<div class="card-divider"></div>
{% endif %}
<script> <script>
frappe.ready(() => { frappe.ready(() => {
var d; expand_the_active_chapter();
$(".no-preview").click((e) => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
var message = __("Please enroll for this course to access the lesson.");
var label = __("Checkout Upcoming Batches");
var action = "checkout_upcoming_batches";
d = frappe.msgprint({
title: __("This lesson is not available for preview!"),
message: message,
primary_action: {
"label": label,
"client_action": action,
}
});
})
window.redirect_to_login = () => {
window.location.href = `/login?redirect-to=/courses/${$(".no-preview").attr("data-course")}`
}
window.checkout_upcoming_batches = () => {
if ($(".upcoming").length > 0) {
$('html,body').animate({ scrollTop: $(".upcoming").offset().top }, 300);
}
frappe.hide_msgprint();
}
}) })
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> </script>

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

View File

@@ -1,7 +1,12 @@
<div class="mt-5"> {% if course.get_chapters() | length %}
<h3> Course Outline </h3> <div class="">
<div class="course-home-headings">
{% for chapter in course.get_chapters() %} Course Outline
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, show_link=show_link, show_progress=show_progress)}} </div>
{% endfor %} <div class="coure-outline">
{% for chapter in course.get_chapters() %}
{{ widgets.ChapterTeaser(index=loop.index, chapter=chapter, course=course, batch=batch, membership=membership) }}
{% endfor %}
</div>
</div> </div>
{% endif %}

View File

@@ -0,0 +1,15 @@
<div class="common-card-style member-card {{dimension_class}} ">
{% set avatar_class = "avatar-large" if not dimension_class else "avatar-large"%}
{{ widgets.Avatar(member=member, avatar_class=avatar_class) }}
<div class="small-title member-card-title">
{{ member.full_name }}
</div>
{% set course_count = member.get_authored_courses() | length %}
{% if show_course_count and course_count > 0 %}
{% set suffix = "Courses" if course_count > 1 else "Course" %}
<div class="small-title">
Created {{ course_count }} {{ suffix }}
</div>
{% endif %}
<a class="stretched-link" href="/{{ member.username }}"></a>
</div>

View File

@@ -1,30 +0,0 @@
<div class="batch">
<div class="batch-details">
<div class="">Session every {{batch.sessions_on}}</div>
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
{{frappe.utils.format_time(batch.end_time, "short")}}
</div>
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
{% for m in course.get_mentors(batch.name) %}
<div>
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
<span class="instructor-title">{{m.full_name}}</span>
</div>
{% endfor %}
</div>
{% if can_manage or can_join %}
<div class="cta">
<div class="">
{% if can_manage %}
<a href="/courses/{{ course.name }}/home?batch={{ batch.name }}" class="btn btn-primary manage-batch" data-batch="{{ batch.name | urlencode }}"
data-course="{{ course.name | urlencode }}">Manage</a>
{% elif can_join %}
<button class="join-batch btn btn-secondary" data-batch="{{ batch.name | urlencode }}"
data-course="{{ course.name | urlencode }}">Join this Batch</button>
{% endif %}
</div>
</div>
{% endif %}
</div>

View File

@@ -0,0 +1,91 @@
<div class="reviews-parent">
{% set reviews = course.get_reviews() %}
{% if reviews | length or course.is_eligible_to_review(membership) %}
<div class="mb-5">
<span class="course-home-headings">Reviews</span>
{% if course.is_eligible_to_review(membership) %}
<span class="review-link button is-secondary pull-right">
Write a review
</span>
{% endif %}
</div>
{% endif %}
{% if reviews | length %}
<div class="reviews-section">
{% for review in reviews %}
<div class="review-card">
<div class="common-card-style review-content small-title"> {{ review.review }} </div>
<div class="review-card-footer">
<div>
{{ widgets.Avatar(member=review.owner_details, avatar_class="avatar-medium") }}
<a class="button-links" href="/{{review.owner_details.username}}">
<span class="course-instructor">
{{ review.owner_details.full_name }}
</span>
</a>
</div>
<div class="rating">
{% for i in [1, 2, 3, 4, 5] %}
<svg class="icon icon-md {% if i <= review.rating %} star-click {% endif %}" data-rating="{{ i }}">
<use href="#icon-star"></use>
</svg>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>
{% endif %}
</div>
<div class="modal fade review-modal" id="review-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="course-home-headings modal-headings">Review</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="review-form" id="review-form">
<div class="form-group">
<div class="clearfix">
<label class="control-label reqd" style="padding-right: 0px;">Rating</label>
</div>
<div class="control-input-wrapper">
<div class="control-input">
<div class="rating rating-field" id="rating">
{% for i in [1, 2, 3, 4, 5] %}
<svg class="icon icon-md icon-rating" data-rating="{{ i }}">
<use href="#icon-star"></use>
</svg>
{% endfor %}
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="clearfix">
<label class="control-label reqd" style="padding-right: 0px;">Review</label>
</div>
<div class="control-input-wrapper">
<div class="control-input">
<textarea type="text" autocomplete="off" class="input-with-feedback form-control review-field"
data-fieldtype="Text" data-fieldname="feedback_comments" placeholder="" style="height: 300px;"
spellcheck="false"></textarea>
</div>
</div>
</div>
<p class="error-field muted-text"></p>
</form>
</div>
<div class="modal-footer">
<div class="button submit-review is-primary" data-course="{{ course.name | urlencode}}" id="submit-review">
Submit</div>
</div>
</div>
</div>
</div>

View File

@@ -1,16 +0,0 @@
<div class="sketch-teaser">
<div class="sketch-image">
<a href="/sketches/{{sketch.sketch_id}}">
{{ sketch.to_svg() }}
</a>
</div>
<div class="sketch-footer">
<div class="sketch-title">
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
</div>
<div class="sketch-author">
{% set owner = sketch.get_owner() %}
by <a href="/{{owner.username}}">{{owner.full_name}}</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,160 @@
{
"category": "Modules",
"charts": [],
"creation": "2021-06-29 13:05:28.741459",
"developer_mode_only": 0,
"disable_user_customization": 0,
"docstatus": 0,
"doctype": "Workspace",
"extends_another_page": 0,
"hide_custom": 0,
"icon": "education",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"label": "LMS",
"links": [
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Course",
"link_to": "LMS Course",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Batch",
"link_to": "LMS Batch",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Batch Membership",
"link_to": "LMS Batch Membership",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Course Mentor Mapping",
"link_to": "LMS Course Mentor Mapping",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Content",
"link_type": "DocType",
"onboard": 0,
"type": "Card Break"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Chapter",
"link_to": "Chapter",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Lesson",
"link_to": "Lesson",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Exercise",
"link_to": "Exercise",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "Exercise Submission",
"link_to": "Exercise Submission",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Quiz",
"link_to": "LMS Quiz",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
},
{
"hidden": 0,
"is_query_report": 0,
"label": "LMS Quiz Submission",
"link_to": "LMS Quiz Submission",
"link_type": "DocType",
"onboard": 0,
"type": "Link"
}
],
"modified": "2021-06-29 15:11:07.324651",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS",
"owner": "Administrator",
"pin_to_bottom": 0,
"pin_to_top": 1,
"shortcuts": [
{
"color": "#29CD42",
"doc_view": "List",
"format": "{} Published",
"label": "Courses",
"link_to": "LMS Course",
"stats_filter": "{\"is_published\": 1}",
"type": "DocType"
},
{
"color": "#29CD42",
"doc_view": "List",
"format": "{} Active ",
"label": "Batches",
"link_to": "LMS Batch",
"stats_filter": "{\"status\": \"Active\"}",
"type": "DocType"
},
{
"color": "#39E4A5",
"doc_view": "List",
"format": "{} Students",
"label": "Memberships",
"link_to": "LMS Batch Membership",
"stats_filter": "{\"member_type\": \"Student\"}",
"type": "DocType"
}
]
}

View File

@@ -0,0 +1,63 @@
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
# import frappe
import unittest
import frappe
class TestCustomUser(unittest.TestCase):
def test_with_basic_username(self):
new_user = frappe.get_doc({
"doctype": "User",
"email": "test_with_basic_username@example.com",
"first_name": "Username"
}).insert()
self.assertEqual(new_user.username, "username")
def test_without_username(self):
""" The user in this test has the same first name as the user of the test test_with_basic_username.
In such cases frappe makes the username of the second user empty.
The condition in community app should override this and save a username. """
new_user = frappe.get_doc({
"doctype": "User",
"email": "test-without-username@example.com",
"first_name": "Username"
}).insert()
self.assertTrue(new_user.username)
def test_with_illegal_characters(self):
new_user = frappe.get_doc({
"doctype": "User",
"email": "test_with_illegal_characters@example.com",
"first_name": "Username$$"
}).insert()
self.assertEqual(new_user.username[:8], "username")
def test_with_underscore_at_end(self):
new_user = frappe.get_doc({
"doctype": "User",
"email": "test_with_underscore_at_end@example.com",
"first_name": "Username___"
}).insert()
self.assertNotEqual(new_user.username[-1], "_")
def test_with_short_first_name(self):
new_user = frappe.get_doc({
"doctype": "User",
"email": "test_with_short_first_name@example.com",
"first_name": "USN"
}).insert()
self.assertGreaterEqual(len(new_user.username), 4)
@classmethod
def tearDownClass(cls) -> None:
users = [
"test_with_basic_username@example.com",
"test-without-username@example.com",
"test_with_illegal_characters@example.com",
"test_with_underscore_at_end@example.com",
"test_with_short_first_name@example.com"
]
frappe.db.delete("User", {"name": ["in", users]})

View File

@@ -2,18 +2,70 @@ import frappe
from frappe.core.doctype.user.user import User from frappe.core.doctype.user.user import User
from frappe.utils import cint from frappe.utils import cint
import hashlib import hashlib
import random
import re
from frappe import _
class CustomUser(User): class CustomUser(User):
def get_course_count(self) -> int: def validate(self):
super(CustomUser, self).validate()
self.validate_username_characters()
def validate_username_characters(self):
if len(self.username):
underscore_condition = self.username[0] == "_" or self.username[-1] == "_"
else:
underscore_condition = ''
if self.is_new():
if not self.username:
self.username = self.get_username_from_first_name()
if self.username.find(" "):
self.username.replace(" ", "")
if not re.match("^[A-Za-z0-9_]*$", self.username) or underscore_condition:
self.username = self.remove_illegal_characters()
if len(self.username) < 4:
self.username = self.email.replace("@", "").replace(".", "")
while self.username_exists():
self.username = self.remove_illegal_characters() + str(random.randint(0, 99))
else:
if not self.username:
frappe.throw(_("Username already exists."))
if not re.match("^[A-Za-z0-9_]*$", self.username):
frappe.throw(_("Username can only contain alphabets, numbers and unedrscore."))
if underscore_condition:
frappe.throw(_("First and Last character of username cannot be Underscore(_)."))
if len(self.username) < 4:
frappe.throw(_("Username cannot be less than 4 characters"))
def get_username_from_first_name(self):
return frappe.scrub(self.first_name) + str(random.randint(0, 99))
def remove_illegal_characters(self):
return re.sub("[^\w]+", "", self.username).strip("_")
def get_authored_courses(self) -> int:
"""Returns the number of courses authored by this user. """Returns the number of courses authored by this user.
""" """
return frappe.db.count( return frappe.get_all(
'LMS Course', { 'LMS Course', {
'owner': self.email 'owner': self.name,
'is_published': True
}) })
def get_palette(self): def get_palette(self):
"""
Returns a color unique to each member for Avatar """
palette = [ palette = [
['--orange-avatar-bg', '--orange-avatar-color'], ['--orange-avatar-bg', '--orange-avatar-color'],
['--pink-avatar-bg', '--pink-avatar-color'], ['--pink-avatar-bg', '--pink-avatar-color'],
@@ -40,3 +92,35 @@ class CustomUser(User):
'member_type': 'Mentor' 'member_type': 'Mentor'
}) })
def get_user_reviews(self):
""" Returns the reviews created by user """
return frappe.get_all("LMS Course Review",
{
"owner": self.name
})
def get_course_membership(self, member_type=None):
""" Returns all memberships of the user """
filters = {
"member": self.name
}
if member_type:
filters["member_type"] = member_type
return frappe.get_all("LMS Batch Membership", filters, ["name", "course"])
def get_mentored_courses(self):
""" Returns all courses mentored by this user """
mentored_courses = []
mapping = frappe.get_all("LMS Course Mentor Mapping",
{
"mentor": self.name,
},
["name", "course"]
)
for map in mapping:
if frappe.db.get_value("LMS Course", map.course, "is_published"):
mentored_courses.append(map)
return mentored_courses

View File

@@ -6,3 +6,5 @@ community.patches.replace_member_with_user_in_batch_membership
community.patches.replace_member_with_user_in_course_mentor_mapping community.patches.replace_member_with_user_in_course_mentor_mapping
community.patches.replace_member_with_user_in_lms_message community.patches.replace_member_with_user_in_lms_message
community.patches.replace_member_with_user_in_mentor_request community.patches.replace_member_with_user_in_mentor_request
community.patches.v0_0.chapter_lesson_index_table
execute:frappe.delete_doc("DocType", "LMS Message")

View File

@@ -0,0 +1,50 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("lms", "doctype", "lms_course")
frappe.reload_doc("lms", "doctype", "chapter")
frappe.reload_doc("lms", "doctype", "lesson")
frappe.reload_doc("lms", "doctype", "lessons")
frappe.reload_doc("lms", "doctype", "chapters")
update_chapters()
update_lessons()
def update_chapters():
courses = frappe.get_all("LMS Course", pluck="name")
for course in courses:
course_details = frappe.get_doc("LMS Course", course)
chapters = frappe.get_all("Chapter",
{
"course": course
},
["name"],
order_by= "index_"
)
for chapter in chapters:
course_details.append("chapters",
{
"chapter": chapter.name
})
course_details.save()
def update_lessons():
chapters = frappe.get_all("Chapter", pluck="name")
for chapter in chapters:
chapter_details = frappe.get_doc("Chapter", chapter)
lessons = frappe.get_all("Lesson",
{
"chapter": chapter
},
["name"],
order_by= "index_"
)
for lesson in lessons:
chapter_details.append("lessons",
{
"lesson": lesson.name
})
chapter_details.save()

View File

@@ -14,6 +14,8 @@ The PageExtension is used to load additinal stylesheets and scripts to
be loaded in a webpage. be loaded in a webpage.
""" """
import frappe
class PageExtension: class PageExtension:
"""PageExtension is a plugin to inject custom styles and scripts """PageExtension is a plugin to inject custom styles and scripts
into a web page. into a web page.
@@ -64,3 +66,43 @@ class ProfileTab:
Every subclass must implement this. Every subclass must implement this.
""" """
raise NotImplementedError() raise NotImplementedError()
class LiveCodeExtension(PageExtension):
def render_header(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {
"livecode_url": livecode_url
}
return frappe.render_template(
"templates/livecode/extension_header.html",
context)
def render_footer(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {
"livecode_url": livecode_url
}
return frappe.render_template(
"templates/livecode/extension_footer.html",
context)
def quiz_renderer(quiz_name):
quiz = frappe.get_doc("LMS Quiz", quiz_name)
context = dict(quiz=quiz)
return frappe.render_template("templates/quiz.html", context)
def exercise_renderer(argument):
exercise = frappe.get_doc("Exercise", argument)
context = dict(exercise=exercise)
return frappe.render_template("templates/exercise.html", context)
def youtube_video_renderer(video_id):
return f"""
<iframe width="100%" height="315"
src="https://www.youtube.com/embed/{video_id}"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
"""

View File

@@ -1,4 +1,3 @@
@import "./style.css"; @import "./style.css";
@import "./vars.css"; @import "./vars.css";
@import "./style.less";

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More