Compare commits
57 Commits
course-pag
...
mentor-das
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c77835b81f | ||
|
|
e04bbb633d | ||
|
|
a2b856aaf8 | ||
|
|
632693c9f8 | ||
|
|
463aec01f8 | ||
|
|
e7d116f31c | ||
|
|
f1b3ee19b6 | ||
|
|
9cb9fad05c | ||
|
|
0859afdf34 | ||
|
|
6407b24324 | ||
|
|
34e993cf86 | ||
|
|
8c889ffb92 | ||
|
|
a67ad67be1 | ||
|
|
646a7b723f | ||
|
|
6f7011ca58 | ||
|
|
d61acb552a | ||
|
|
265c78e76e | ||
|
|
7d180e141c | ||
|
|
29f9141ad8 | ||
|
|
e6f58f56e0 | ||
|
|
9e0476fd00 | ||
|
|
d9ea02667d | ||
|
|
bdabf32124 | ||
|
|
8b657f2f40 | ||
|
|
49b41749e8 | ||
|
|
1cf57c4823 | ||
|
|
5cfb72a731 | ||
|
|
49d5ca4292 | ||
|
|
a3e53efcc1 | ||
|
|
be7814b4fe | ||
|
|
c40ab9a726 | ||
|
|
64cf14ed92 | ||
|
|
dbaa896fcc | ||
|
|
911c85bfc8 | ||
|
|
5edceb2562 | ||
|
|
5d14dce320 | ||
|
|
eec9e57dd2 | ||
|
|
503b922074 | ||
|
|
d4c19932d5 | ||
|
|
3c8cffc5ad | ||
|
|
b3c67a3f34 | ||
|
|
84b4833fed | ||
|
|
28ef7e5def | ||
|
|
9981baa13b | ||
|
|
c764aa6c20 | ||
|
|
bc11730697 | ||
|
|
92c4a86e8b | ||
|
|
358724bf1c | ||
|
|
bb80d988d7 | ||
|
|
0ad03a3fb5 | ||
|
|
3382de0ecb | ||
|
|
08bb7b4490 | ||
|
|
15203f6bcc | ||
|
|
cbfb0d6761 | ||
|
|
11cc03849d | ||
|
|
5e5395658e | ||
|
|
8a242a69fb |
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- name: setup node
|
- name: setup node
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '12'
|
node-version: '14'
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- name: setup cache for bench
|
- name: setup cache for bench
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v2
|
||||||
@@ -69,6 +69,9 @@ jobs:
|
|||||||
- name: allow tests
|
- name: allow tests
|
||||||
working-directory: /home/runner/frappe-bench
|
working-directory: /home/runner/frappe-bench
|
||||||
run: bench --site frappe.local set-config allow_tests true
|
run: bench --site frappe.local set-config allow_tests true
|
||||||
|
- name: bench build
|
||||||
|
working-directory: /home/runner/frappe-bench
|
||||||
|
run: bench --site frappe.local build
|
||||||
- name: run tests
|
- name: run tests
|
||||||
working-directory: /home/runner/frappe-bench
|
working-directory: /home/runner/frappe-bench
|
||||||
run: bench --site frappe.local run-tests --app community
|
run: bench --site frappe.local run-tests --app community
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ class CommunityMember(Document):
|
|||||||
'member_type': 'Mentor'
|
'member_type': 'Mentor'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def get_photo_url(self):
|
||||||
|
return frappe.db.get_value("User", self.email, ["user_image"])
|
||||||
|
|
||||||
def get_palette(self):
|
def get_palette(self):
|
||||||
palette = [
|
palette = [
|
||||||
['--orange-avatar-bg', '--orange-avatar-color'],
|
['--orange-avatar-bg', '--orange-avatar-color'],
|
||||||
@@ -74,7 +77,7 @@ def create_member_from_user(doc, method):
|
|||||||
if ( doc.username and username_exists(doc.username)) or not doc.username:
|
if ( doc.username and username_exists(doc.username)) or not doc.username:
|
||||||
username = create_username_from_email(doc.email)
|
username = create_username_from_email(doc.email)
|
||||||
|
|
||||||
elif len(doc.username) < 4:
|
elif len(doc.username) < 4 and doc.send_welcome_email == 1:
|
||||||
username = adjust_username(doc.username)
|
username = adjust_username(doc.username)
|
||||||
|
|
||||||
if username_exists(username):
|
if username_exists(username):
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{% set color = member.get_palette() %}
|
{% set color = member.get_palette() %}
|
||||||
|
<a href="/{{member.username}}">
|
||||||
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
||||||
{% if member.photo %}
|
{% if member.get_photo_url() %}
|
||||||
<img class="avatar-frame standard-image" src="{{ member.photo }}" title="{{ member.full_name }}">
|
<img class="avatar-frame standard-image" src="{{ member.get_photo_url() }}" title="{{ member.full_name }}">
|
||||||
</img>
|
</img>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="avatar-frame standard-image" title="{{ member.full_name }}"
|
<span class="avatar-frame standard-image" title="{{ member.full_name }}"
|
||||||
@@ -9,4 +10,5 @@
|
|||||||
{{ member.abbr }}
|
{{ member.abbr }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from . import __version__ as app_version
|
from . import __version__ as app_version
|
||||||
from .install import APP_LOGO_URL
|
|
||||||
|
|
||||||
app_name = "community"
|
app_name = "community"
|
||||||
app_title = "Community"
|
app_title = "Community"
|
||||||
@@ -12,17 +11,15 @@ app_color = "grey"
|
|||||||
app_email = "jannat@erpnext.com"
|
app_email = "jannat@erpnext.com"
|
||||||
app_license = "AGPL"
|
app_license = "AGPL"
|
||||||
|
|
||||||
app_logo_url = APP_LOGO_URL
|
|
||||||
|
|
||||||
# Includes in <head>
|
# Includes in <head>
|
||||||
# ------------------
|
# ------------------
|
||||||
|
|
||||||
# include js, css files in header of desk.html
|
# include js, css files in header of desk.html
|
||||||
app_include_css = "/assets/community/css/community.css"
|
# app_include_css = "/assets/community/css/community.css"
|
||||||
app_include_js = "/assets/community/js/community.js"
|
# app_include_js = "/assets/community/js/community.js"
|
||||||
|
|
||||||
# include js, css files in header of web template
|
# include js, css files in header of web template
|
||||||
web_include_css = "/assets/css/community.css"
|
web_include_css = "community.bundle.css"
|
||||||
# web_include_css = "/assets/community/css/community.css"
|
# web_include_css = "/assets/community/css/community.css"
|
||||||
# web_include_js = "/assets/community/js/community.js"
|
# web_include_js = "/assets/community/js/community.js"
|
||||||
|
|
||||||
@@ -63,7 +60,7 @@ web_include_css = "/assets/css/community.css"
|
|||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
# before_install = "community.install.before_install"
|
# before_install = "community.install.before_install"
|
||||||
after_install = "community.install.after_install"
|
# after_install = "community.install.after_install"
|
||||||
|
|
||||||
# Desk Notifications
|
# Desk Notifications
|
||||||
# ------------------
|
# ------------------
|
||||||
@@ -144,11 +141,13 @@ primary_rules = [
|
|||||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||||
{"from_route": "/dashboard", "to_route": ""},
|
{"from_route": "/dashboard", "to_route": ""},
|
||||||
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
||||||
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "courses/learn"},
|
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "courses/schedule"},
|
{"from_route": "/courses/<course>/<batch>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "courses/members"},
|
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "batch/schedule"},
|
||||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "courses/discuss"},
|
{"from_route": "/courses/<course>/<batch>/members", "to_route": "batch/members"},
|
||||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "courses/about"}
|
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "batch/discuss"},
|
||||||
|
{"from_route": "/courses/<course>/<batch>/about", "to_route": "batch/about"},
|
||||||
|
{"from_route": "/courses/<course>/<batch>/progress", "to_route": "batch/progress"}
|
||||||
]
|
]
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
"""Hooks that are executed during and after install.
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import frappe
|
|
||||||
|
|
||||||
APP_LOGO_URL = os.getenv("APP_LOGO_URL") or "/files/logo.png"
|
|
||||||
|
|
||||||
def after_install():
|
|
||||||
set_app_name()
|
|
||||||
disable_signup()
|
|
||||||
add_header_items()
|
|
||||||
add_footer_items()
|
|
||||||
|
|
||||||
def set_app_name():
|
|
||||||
app_name = os.getenv("FRAPPE_APP_NAME")
|
|
||||||
if app_name:
|
|
||||||
frappe.db.set_value('System Settings', None, 'app_name', app_name)
|
|
||||||
|
|
||||||
def disable_signup():
|
|
||||||
frappe.db.set_value("Website Settings", None, "disable_signup", 1)
|
|
||||||
|
|
||||||
def add_header_items():
|
|
||||||
items = [
|
|
||||||
{"label": "Sketches", "url": "/sketches"},
|
|
||||||
]
|
|
||||||
doc = frappe.get_doc("Website Settings", None)
|
|
||||||
doc.update({
|
|
||||||
"top_bar_items": items
|
|
||||||
})
|
|
||||||
doc.save()
|
|
||||||
|
|
||||||
def add_footer_items():
|
|
||||||
items = [
|
|
||||||
{"label": "About", "url": "/about"},
|
|
||||||
{"label": "Blog", "url": "/blog"},
|
|
||||||
{"label": "Github", "url": "https://github.com/fossunited/community"}
|
|
||||||
]
|
|
||||||
doc = frappe.get_doc("Website Settings", None)
|
|
||||||
doc.update({
|
|
||||||
"footer_items": items
|
|
||||||
})
|
|
||||||
doc.save()
|
|
||||||
@@ -21,3 +21,16 @@ def get_section(name):
|
|||||||
"""
|
"""
|
||||||
doc = frappe.get_doc("LMS Section", name)
|
doc = frappe.get_doc("LMS Section", name)
|
||||||
return doc and doc.as_dict()
|
return doc and doc.as_dict()
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def submit_solution(exercise, code):
|
||||||
|
"""Submits a solution.
|
||||||
|
|
||||||
|
@exerecise: name of the exercise to submit
|
||||||
|
@code: solution to the exercise
|
||||||
|
"""
|
||||||
|
ex = frappe.get_doc("Exercise", exercise)
|
||||||
|
if not ex:
|
||||||
|
return
|
||||||
|
doc = ex.submit(code)
|
||||||
|
return {"name": doc.name, "creation": doc.creation}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
"course",
|
"course",
|
||||||
"title",
|
"title",
|
||||||
"description",
|
"description",
|
||||||
"locked"
|
"locked",
|
||||||
|
"index_"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -35,6 +36,12 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Course",
|
"label": "Course",
|
||||||
"options": "LMS Course"
|
"options": "LMS Course"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "1",
|
||||||
|
"fieldname": "index_",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Index"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
@@ -45,7 +52,7 @@
|
|||||||
"link_fieldname": "chapter"
|
"link_fieldname": "chapter"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-03 06:52:10.894328",
|
"modified": "2021-05-13 21:05:20.531890",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Chapter",
|
"name": "Chapter",
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ class Chapter(Document):
|
|||||||
def get_lessons(self):
|
def get_lessons(self):
|
||||||
rows = frappe.db.get_all("Lesson",
|
rows = frappe.db.get_all("Lesson",
|
||||||
filters={"chapter": self.name},
|
filters={"chapter": self.name},
|
||||||
fields='*')
|
fields='*',
|
||||||
|
order_by="index_")
|
||||||
return [frappe.get_doc(dict(row, doctype='Lesson')) for row in rows]
|
return [frappe.get_doc(dict(row, doctype='Lesson')) for row in rows]
|
||||||
|
|||||||
@@ -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 Topic', {
|
frappe.ui.form.on('Exercise', {
|
||||||
// refresh: function(frm) {
|
// refresh: function(frm) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
106
community/lms/doctype/exercise/exercise.json
Normal file
106
community/lms/doctype/exercise/exercise.json
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"allow_rename": 1,
|
||||||
|
"creation": "2021-05-19 17:43:39.923430",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"code",
|
||||||
|
"answer",
|
||||||
|
"column_break_4",
|
||||||
|
"course",
|
||||||
|
"hints",
|
||||||
|
"tests",
|
||||||
|
"image",
|
||||||
|
"lesson"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "title",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Title"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "course",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Course",
|
||||||
|
"options": "LMS Course"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 4,
|
||||||
|
"fieldname": "description",
|
||||||
|
"fieldtype": "Small Text",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 4,
|
||||||
|
"fieldname": "answer",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"label": "Answer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "tests",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"label": "Tests"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_4",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 4,
|
||||||
|
"fieldname": "hints",
|
||||||
|
"fieldtype": "Small Text",
|
||||||
|
"label": "Hints"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 4,
|
||||||
|
"fieldname": "code",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"label": "Code"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "image",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"label": "Image",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "lesson",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Lesson",
|
||||||
|
"options": "Lesson"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-05-20 13:23:12.340928",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "Exercise",
|
||||||
|
"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
|
||||||
|
}
|
||||||
59
community/lms/doctype/exercise/exercise.py
Normal file
59
community/lms/doctype/exercise/exercise.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
from ..lms_sketch.livecode import livecode_to_svg
|
||||||
|
|
||||||
|
class Exercise(Document):
|
||||||
|
def before_save(self):
|
||||||
|
self.image = livecode_to_svg(None, self.answer)
|
||||||
|
|
||||||
|
def get_user_submission(self):
|
||||||
|
"""Returns the latest submission for this user.
|
||||||
|
"""
|
||||||
|
user = frappe.session.user
|
||||||
|
if not user or user == "Guest":
|
||||||
|
return
|
||||||
|
|
||||||
|
result = frappe.get_all('Exercise Submission',
|
||||||
|
fields="*",
|
||||||
|
filters={
|
||||||
|
"owner": user,
|
||||||
|
"exercise": self.name
|
||||||
|
},
|
||||||
|
order_by="creation desc",
|
||||||
|
page_length=1)
|
||||||
|
|
||||||
|
print("get_user_submission", result)
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
|
||||||
|
def submit(self, code):
|
||||||
|
"""Submits the given code as solution to exercise.
|
||||||
|
"""
|
||||||
|
user = frappe.session.user
|
||||||
|
if not user or user == "Guest":
|
||||||
|
return
|
||||||
|
|
||||||
|
old_submission = self.get_user_submission()
|
||||||
|
if old_submission and old_submission.solution == code:
|
||||||
|
return old_submission
|
||||||
|
|
||||||
|
course = frappe.get_doc("LMS Course", self.course)
|
||||||
|
batch = course.get_student_batch(user)
|
||||||
|
|
||||||
|
image = livecode_to_svg(None, code)
|
||||||
|
|
||||||
|
doc = frappe.get_doc(
|
||||||
|
doctype="Exercise Submission",
|
||||||
|
exercise=self.name,
|
||||||
|
exercise_title=self.title,
|
||||||
|
course=self.course,
|
||||||
|
lesson=self.lesson,
|
||||||
|
batch=batch and batch.name,
|
||||||
|
image=image,
|
||||||
|
solution=code)
|
||||||
|
doc.insert(ignore_permissions=True)
|
||||||
|
return doc
|
||||||
|
|
||||||
47
community/lms/doctype/exercise/test_exercise.py
Normal file
47
community/lms/doctype/exercise/test_exercise.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and Contributors
|
||||||
|
# See license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestExercise(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
frappe.db.sql('delete from `tabExercise Submission`')
|
||||||
|
frappe.db.sql('delete from `tabExercise`')
|
||||||
|
frappe.db.sql('delete from `tabLMS Course`')
|
||||||
|
|
||||||
|
def new_exercise(self):
|
||||||
|
course = frappe.get_doc({
|
||||||
|
"doctype": "LMS Course",
|
||||||
|
"name": "test-course",
|
||||||
|
"title": "Test Course"
|
||||||
|
})
|
||||||
|
course.insert()
|
||||||
|
e = frappe.get_doc({
|
||||||
|
"doctype": "Exercise",
|
||||||
|
"name": "test-problem",
|
||||||
|
"course": course.name,
|
||||||
|
"title": "Test Problem",
|
||||||
|
"description": "draw a circle",
|
||||||
|
"code": "# draw a single cicle",
|
||||||
|
"answer": (
|
||||||
|
"# draw a single circle\n" +
|
||||||
|
"circle(100, 100, 50)")
|
||||||
|
})
|
||||||
|
e.insert()
|
||||||
|
return e
|
||||||
|
|
||||||
|
def test_exercise(self):
|
||||||
|
e = self.new_exercise()
|
||||||
|
assert e.get_user_submission() is None
|
||||||
|
|
||||||
|
def test_exercise_submission(self):
|
||||||
|
e = self.new_exercise()
|
||||||
|
submission = e.submit("circle(100, 100, 50)")
|
||||||
|
assert submission is not None
|
||||||
|
assert submission.exercise == e.name
|
||||||
|
assert submission.course == e.course
|
||||||
|
|
||||||
|
user_submission = e.get_user_submission()
|
||||||
|
assert user_submission is not None
|
||||||
|
assert user_submission.name == submission.name
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright (c) 2021, FOSS United and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.ui.form.on('Exercise Submission', {
|
||||||
|
// refresh: function(frm) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
});
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"creation": "2021-05-19 11:41:18.108316",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"exercise",
|
||||||
|
"solution",
|
||||||
|
"exercise_title",
|
||||||
|
"course",
|
||||||
|
"batch",
|
||||||
|
"lesson",
|
||||||
|
"image"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "exercise",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Exercise",
|
||||||
|
"options": "Exercise"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "solution",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Solution"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "exercise.title",
|
||||||
|
"fieldname": "exercise_title",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Exercise Title",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "exercise.course",
|
||||||
|
"fieldname": "course",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Course",
|
||||||
|
"options": "LMS Course",
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "batch",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Batch",
|
||||||
|
"options": "LMS Batch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "exercise.lesson",
|
||||||
|
"fieldname": "lesson",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Lesson",
|
||||||
|
"options": "Lesson"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "image",
|
||||||
|
"fieldtype": "Code",
|
||||||
|
"label": "Image",
|
||||||
|
"read_only": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2021-05-21 11:28:45.833018",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "LMS",
|
||||||
|
"name": "Exercise Submission",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"create": 1,
|
||||||
|
"delete": 1,
|
||||||
|
"email": 1,
|
||||||
|
"export": 1,
|
||||||
|
"print": 1,
|
||||||
|
"read": 1,
|
||||||
|
"report": 1,
|
||||||
|
"role": "System Manager",
|
||||||
|
"share": 1,
|
||||||
|
"write": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sort_field": "modified",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"track_changes": 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Copyright (c) 2021, FOSS United and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
# import frappe
|
||||||
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
class ExerciseSubmission(Document):
|
||||||
|
pass
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (c) 2021, FOSS United and Contributors
|
# Copyright (c) 2021, FOSS United and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
# import frappe
|
# import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestLMSTopic(unittest.TestCase):
|
class TestExerciseSubmission(unittest.TestCase):
|
||||||
pass
|
pass
|
||||||
@@ -47,6 +47,9 @@ class InviteRequest(Document):
|
|||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def create_invite_request(invite_email):
|
def create_invite_request(invite_email):
|
||||||
|
|
||||||
|
if not frappe.utils.validate_email_address(invite_email):
|
||||||
|
return "invalid email"
|
||||||
|
|
||||||
if frappe.db.exists("User", invite_email):
|
if frappe.db.exists("User", invite_email):
|
||||||
return "user"
|
return "user"
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,10 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"chapter",
|
"chapter",
|
||||||
"lesson_type",
|
"lesson_type",
|
||||||
"title"
|
"title",
|
||||||
|
"index_",
|
||||||
|
"body",
|
||||||
|
"sections"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -31,11 +34,28 @@
|
|||||||
"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",
|
||||||
|
"fieldtype": "Markdown Editor",
|
||||||
|
"label": "Body"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "sections",
|
||||||
|
"fieldtype": "Table",
|
||||||
|
"label": "Sections",
|
||||||
|
"options": "LMS Section"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-03 06:51:43.588969",
|
"modified": "2021-05-13 20:03:51.510605",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Lesson",
|
"name": "Lesson",
|
||||||
|
|||||||
@@ -3,8 +3,43 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
# import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from ...section_parser import SectionParser
|
||||||
|
|
||||||
class Lesson(Document):
|
class Lesson(Document):
|
||||||
pass
|
def before_save(self):
|
||||||
|
sections = SectionParser().parse(self.body or "")
|
||||||
|
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
|
||||||
|
for s in self.sections:
|
||||||
|
if s.type == "exercise":
|
||||||
|
e = s.get_exercise()
|
||||||
|
e.lesson = self.name
|
||||||
|
e.save()
|
||||||
|
|
||||||
|
def get_sections(self):
|
||||||
|
return sorted(self.get('sections'), key=lambda s: s.index)
|
||||||
|
|
||||||
|
def make_lms_section(self, index, section):
|
||||||
|
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
|
||||||
|
s.type = section.type
|
||||||
|
s.id = section.id
|
||||||
|
s.label = section.label
|
||||||
|
s.contents = section.contents
|
||||||
|
s.index = index
|
||||||
|
return s
|
||||||
|
|
||||||
|
def get_next(self):
|
||||||
|
"""Returns the number for the next lesson.
|
||||||
|
|
||||||
|
The return value would be like 1.2, 2.1 etc.
|
||||||
|
It will be None if there is no next lesson.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def get_prev(self):
|
||||||
|
"""Returns the number for the prev lesson.
|
||||||
|
|
||||||
|
The return value would be like 1.2, 2.1 etc.
|
||||||
|
It will be None if there is no next lesson.
|
||||||
|
"""
|
||||||
|
|||||||
@@ -6,20 +6,30 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from community.www.courses.utils import get_member_with_email
|
from community.www.courses.utils import get_member_with_email
|
||||||
|
from frappe import _
|
||||||
|
from community.lms.doctype.lms_batch_membership.lms_batch_membership import create_membership
|
||||||
from community.query import find, find_all
|
from community.query import find, find_all
|
||||||
|
|
||||||
class LMSBatch(Document):
|
class LMSBatch(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_if_mentor()
|
||||||
if not self.code:
|
if not self.code:
|
||||||
self.generate_code()
|
self.generate_code()
|
||||||
|
|
||||||
|
def validate_if_mentor(self):
|
||||||
|
course = frappe.get_doc("LMS Course", self.course)
|
||||||
|
if not course.is_mentor(frappe.session.user):
|
||||||
|
frappe.throw(_("You are not a mentor of the course {0}").format(course.title))
|
||||||
|
|
||||||
|
def after_insert(self):
|
||||||
|
create_membership(batch=self.name, member_type="Mentor")
|
||||||
|
|
||||||
def generate_code(self):
|
def generate_code(self):
|
||||||
short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
|
short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
|
||||||
course_batches = frappe.get_all("LMS Batch",{"course":self.course})
|
course_batches = frappe.get_all("LMS Batch",{"course":self.course})
|
||||||
self.code = short_code + str(len(course_batches) + 1)
|
self.code = short_code + str(len(course_batches) + 1)
|
||||||
|
|
||||||
def get_mentors(self):
|
def get_mentors(self):
|
||||||
mentors = []
|
|
||||||
memberships = frappe.get_all(
|
memberships = frappe.get_all(
|
||||||
"LMS Batch Membership",
|
"LMS Batch Membership",
|
||||||
{"batch": self.name, "member_type": "Mentor"},
|
{"batch": self.name, "member_type": "Mentor"},
|
||||||
@@ -27,13 +37,37 @@ class LMSBatch(Document):
|
|||||||
member_names = [m['member'] for m in memberships]
|
member_names = [m['member'] for m in memberships]
|
||||||
return find_all("Community Member", name=["IN", member_names])
|
return find_all("Community Member", name=["IN", member_names])
|
||||||
|
|
||||||
def is_member(self, email):
|
def is_member(self, email, member_type=None):
|
||||||
"""Checks if a person is part of a batch.
|
"""Checks if a person is part of a batch.
|
||||||
|
|
||||||
|
If member_type is specified, checks if the person is a Student/Mentor.
|
||||||
"""
|
"""
|
||||||
member = find("Community Member", email=email)
|
member = find("Community Member", email=email)
|
||||||
return member and frappe.db.exists(
|
if not member:
|
||||||
|
return
|
||||||
|
|
||||||
|
filters = {
|
||||||
|
"batch": self.name,
|
||||||
|
"member": member.name
|
||||||
|
}
|
||||||
|
if member_type:
|
||||||
|
filters['member_type'] = member_type
|
||||||
|
return frappe.db.exists("LMS Batch Membership", filters)
|
||||||
|
|
||||||
|
def get_students(self):
|
||||||
|
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
|
||||||
|
"""
|
||||||
|
memberships = frappe.get_all(
|
||||||
"LMS Batch Membership",
|
"LMS Batch Membership",
|
||||||
{"batch": self.name, "member": member.name})
|
{"batch": self.name, "member_type": "Student"},
|
||||||
|
["member"])
|
||||||
|
member_names = [m['member'] for m in memberships]
|
||||||
|
members = frappe.get_all(
|
||||||
|
"Community Member",
|
||||||
|
{"name": ["IN", member_names]},
|
||||||
|
["email", "full_name", "username"])
|
||||||
|
return members
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_messages(batch):
|
def get_messages(batch):
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ class LMSBatchMembership(Document):
|
|||||||
member_name = frappe.db.get_value("Community Member", self.member, "full_name")
|
member_name = frappe.db.get_value("Community Member", self.member, "full_name")
|
||||||
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
|
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
|
||||||
|
|
||||||
@frappe.whitelist()
|
def create_membership(batch, member=None, member_type="Student", role="Member"):
|
||||||
def create_membership(batch, course=None, member=None, member_type="Student", role="Member"):
|
|
||||||
if not member:
|
if not member:
|
||||||
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
|
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
@@ -39,7 +38,4 @@ def create_membership(batch, course=None, member=None, member_type="Student", ro
|
|||||||
"member_type": member_type,
|
"member_type": member_type,
|
||||||
"member": member
|
"member": member
|
||||||
}).save(ignore_permissions=True)
|
}).save(ignore_permissions=True)
|
||||||
if course:
|
|
||||||
course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["name"])
|
|
||||||
return course_slug
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"title",
|
"title",
|
||||||
"slug",
|
|
||||||
"is_published",
|
"is_published",
|
||||||
"column_break_3",
|
"column_break_3",
|
||||||
"short_code",
|
"short_code",
|
||||||
@@ -42,14 +41,6 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Short Code"
|
"label": "Short Code"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"description": "The slug of the course. Autogenerated from the title if not specified.",
|
|
||||||
"fieldname": "slug",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Slug",
|
|
||||||
"unique": 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_3",
|
"fieldname": "column_break_3",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
@@ -86,9 +77,14 @@
|
|||||||
"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-05-06 11:15:45.728976",
|
"modified": "2021-05-06 13:37:03.318829",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Course",
|
"name": "LMS Course",
|
||||||
@@ -107,7 +103,7 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"search_fields": "slug",
|
"search_fields": "title",
|
||||||
"sort_field": "creation",
|
"sort_field": "creation",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"title_field": "title",
|
"title_field": "title",
|
||||||
|
|||||||
@@ -28,24 +28,13 @@ class LMSCourse(Document):
|
|||||||
def generate_slug(self, title):
|
def generate_slug(self, title):
|
||||||
result = frappe.get_all(
|
result = frappe.get_all(
|
||||||
'LMS Course',
|
'LMS Course',
|
||||||
fields=['slug'])
|
fields=['name'])
|
||||||
slugs = set([row['slug'] for row in result])
|
slugs = set([row['name'] for row in result])
|
||||||
return slugify(title, used_slugs=slugs)
|
return slugify(title, used_slugs=slugs)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<Course#{self.name}>"
|
return f"<Course#{self.name}>"
|
||||||
|
|
||||||
def get_topic(self, slug):
|
|
||||||
"""Returns the topic with given slug in this course as a Document.
|
|
||||||
"""
|
|
||||||
result = frappe.get_all(
|
|
||||||
"LMS Topic",
|
|
||||||
filters={"course": self.name, "slug": slug})
|
|
||||||
|
|
||||||
if result:
|
|
||||||
row = result[0]
|
|
||||||
return frappe.get_doc('LMS Topic', row['name'])
|
|
||||||
|
|
||||||
def has_mentor(self, email):
|
def has_mentor(self, email):
|
||||||
"""Checks if this course has a mentor with given email.
|
"""Checks if this course has a mentor with given email.
|
||||||
"""
|
"""
|
||||||
@@ -114,6 +103,35 @@ class LMSCourse(Document):
|
|||||||
"mentor": member
|
"mentor": member
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def get_student_batch(self, email):
|
||||||
|
"""Returns the batch the given student is part of.
|
||||||
|
|
||||||
|
Returns None if the student is not part of any batch.
|
||||||
|
"""
|
||||||
|
if not email:
|
||||||
|
return False
|
||||||
|
member = self.get_community_member(email)
|
||||||
|
result = frappe.db.get_all(
|
||||||
|
"LMS Batch Membership",
|
||||||
|
filters={
|
||||||
|
"member": member,
|
||||||
|
"member_type": "Student",
|
||||||
|
},
|
||||||
|
fields=['batch']
|
||||||
|
)
|
||||||
|
batches = [row['batch'] for row in result]
|
||||||
|
|
||||||
|
# filter the batches that are for this course
|
||||||
|
result = frappe.db.get_all(
|
||||||
|
"LMS Batch",
|
||||||
|
filters={
|
||||||
|
"course": self.name,
|
||||||
|
"name": ["IN", batches]
|
||||||
|
})
|
||||||
|
batches = [row['name'] for row in result]
|
||||||
|
if batches:
|
||||||
|
return frappe.get_doc("LMS Batch", batches[0])
|
||||||
|
|
||||||
def get_instructor(self):
|
def get_instructor(self):
|
||||||
member_name = self.get_community_member(self.owner)
|
member_name = self.get_community_member(self.owner)
|
||||||
return frappe.get_doc("Community Member", member_name)
|
return frappe.get_doc("Community Member", member_name)
|
||||||
@@ -148,3 +166,59 @@ 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_outline(self):
|
||||||
|
return CourseOutline(self)
|
||||||
|
|
||||||
|
class CourseOutline:
|
||||||
|
def __init__(self, course):
|
||||||
|
self.course = course
|
||||||
|
self.chapters = self.get_chapters()
|
||||||
|
self.lessons = self.get_lessons()
|
||||||
|
|
||||||
|
def get_next(self, current):
|
||||||
|
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||||
|
try:
|
||||||
|
index = numbers.index(current)
|
||||||
|
return numbers[index+1]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_prev(self, current):
|
||||||
|
numbers = sorted(lesson['number'] for lesson in self.lessons)
|
||||||
|
try:
|
||||||
|
index = numbers.index(current)
|
||||||
|
if index == 0:
|
||||||
|
return None
|
||||||
|
return numbers[index-1]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_chapters(self):
|
||||||
|
return frappe.db.get_all("Chapter",
|
||||||
|
filters={"course": self.course.name},
|
||||||
|
fields=["name", "title", "index_"])
|
||||||
|
|
||||||
|
def get_lessons(self):
|
||||||
|
chapters = [c['name'] for c in self.chapters]
|
||||||
|
lessons = frappe.db.get_all("Lesson",
|
||||||
|
filters={"chapter": ["IN", chapters]},
|
||||||
|
fields=["name", "title", "chapter", "index_"])
|
||||||
|
|
||||||
|
chapter_numbers = {c['name']: c['index_'] for c in self.chapters}
|
||||||
|
for lesson in lessons:
|
||||||
|
lesson['number'] = "{}.{}".format(chapter_numbers[lesson['chapter']], lesson['index_'])
|
||||||
|
return lessons
|
||||||
|
|||||||
@@ -8,86 +8,119 @@ from frappe.model.document import Document
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
|
|
||||||
class LMSMentorRequest(Document):
|
class LMSMentorRequest(Document):
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
if self.has_value_changed('status'):
|
if self.has_value_changed('status'):
|
||||||
template = frappe.db.get_single_value('LMS Settings', 'mentor_request_status_update')
|
|
||||||
if not template:
|
|
||||||
return
|
|
||||||
|
|
||||||
email_template = frappe.get_doc('Email Template', template)
|
if self.status == "Approved":
|
||||||
message = frappe.render_template(email_template.response, {'member_name': self.member_name, 'status': self.status})
|
self.create_course_mentor_mapping()
|
||||||
subject = _('The status of your application has changed.')
|
|
||||||
member_email = frappe.db.get_value("Community Member", self.member, "email")
|
if self.status != "Pending":
|
||||||
|
self.send_status_change_email()
|
||||||
if self.status == 'Approved' or self.status == 'Rejected':
|
|
||||||
reviewed_by = frappe.db.get_value('Community Member', self.reviewed_by, 'email')
|
def create_course_mentor_mapping(self):
|
||||||
send_email(member_email, [get_course_author(self.course), reviewed_by], subject, message)
|
mapping = frappe.get_doc({
|
||||||
|
"doctype": "LMS Course Mentor Mapping",
|
||||||
elif self.status == 'Withdrawn':
|
"mentor": self.member,
|
||||||
send_email([member_email, get_course_author(self.course)], None, subject, message)
|
"course": self.course
|
||||||
|
})
|
||||||
|
mapping.save()
|
||||||
|
|
||||||
|
def send_creation_email(self, member):
|
||||||
|
email_template = self.get_email_template('mentor_request_creation')
|
||||||
|
if not email_template:
|
||||||
|
return
|
||||||
|
|
||||||
|
course_details = frappe.db.get_value("LMS Course", self.course, ["owner", "slug", "title"], as_dict=True)
|
||||||
|
message = frappe.render_template(email_template.response,
|
||||||
|
{
|
||||||
|
'member_name': member.full_name,
|
||||||
|
'course_url': '/courses/' + course_details.slug,
|
||||||
|
'course': course_details.title
|
||||||
|
})
|
||||||
|
|
||||||
|
email_args = {
|
||||||
|
"recipients": [frappe.session.user, course_details.owner],
|
||||||
|
"subject": email_template.subject,
|
||||||
|
"header": email_template.subject,
|
||||||
|
"message": message
|
||||||
|
}
|
||||||
|
frappe.enqueue(method=frappe.sendmail, queue="short", timeout=300, is_async=True, **email_args)
|
||||||
|
|
||||||
|
def send_status_change_email(self):
|
||||||
|
email_template = self.get_email_template('mentor_request_status_update')
|
||||||
|
if not email_template:
|
||||||
|
return
|
||||||
|
|
||||||
|
course_details = frappe.db.get_value("LMS Course", self.course, ["owner", "title"], as_dict=True)
|
||||||
|
message = frappe.render_template(email_template.response,
|
||||||
|
{
|
||||||
|
'member_name': self.member_name,
|
||||||
|
'status': self.status,
|
||||||
|
'course': course_details.title
|
||||||
|
})
|
||||||
|
|
||||||
|
member_email = frappe.db.get_value("Community Member", self.member, "email")
|
||||||
|
if self.status == 'Approved' or self.status == 'Rejected':
|
||||||
|
reviewed_by = frappe.db.get_value('Community Member', self.reviewed_by, 'email')
|
||||||
|
email_args = {
|
||||||
|
"recipients": member_email,
|
||||||
|
"cc": [course_details.owner, reviewed_by],
|
||||||
|
"subject": email_template.subject,
|
||||||
|
"header": email_template.subject,
|
||||||
|
"message": message
|
||||||
|
}
|
||||||
|
frappe.enqueue(method=frappe.sendmail, queue="short", timeout=300, is_async=True, **email_args)
|
||||||
|
|
||||||
|
elif self.status == 'Withdrawn':
|
||||||
|
email_args = {
|
||||||
|
"recipients": [member_email, course_details.owner],
|
||||||
|
"subject": email_template.subject,
|
||||||
|
"header": email_template.subject,
|
||||||
|
"message": message
|
||||||
|
}
|
||||||
|
frappe.enqueue(method=frappe.sendmail, queue="short", timeout=300, is_async=True, **email_args)
|
||||||
|
|
||||||
|
def get_email_template(self, template_name):
|
||||||
|
template = frappe.db.get_single_value('LMS Settings', template_name)
|
||||||
|
if template:
|
||||||
|
return frappe.get_doc('Email Template', template)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def has_requested(course):
|
def has_requested(course):
|
||||||
return len(frappe.get_all('LMS Mentor Request',
|
return frappe.db.count('LMS Mentor Request',
|
||||||
filters = {
|
filters = {
|
||||||
'member': get_member().name,
|
'member': get_member().name,
|
||||||
'course': course,
|
'course': course,
|
||||||
'status': ['in', ('Pending', 'Approved')]
|
'status': ['in', ('Pending', 'Approved')]
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_request(course):
|
def create_request(course):
|
||||||
if not has_requested(course):
|
if not has_requested(course):
|
||||||
member = get_member()
|
member = get_member()
|
||||||
frappe.get_doc({
|
request = frappe.get_doc({
|
||||||
'doctype': 'LMS Mentor Request',
|
'doctype': 'LMS Mentor Request',
|
||||||
'member': member.name,
|
'member': member.name,
|
||||||
'course': course,
|
'course': course,
|
||||||
'status': 'Pending'
|
'status': 'Pending'
|
||||||
}).save(ignore_permissions=True)
|
})
|
||||||
send_creation_email(course, member)
|
request.save(ignore_permissions=True)
|
||||||
return 'OK'
|
request.send_creation_email(member)
|
||||||
else:
|
return 'OK'
|
||||||
return 'Already Applied'
|
|
||||||
|
else:
|
||||||
|
return 'Already Applied'
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def cancel_request(course):
|
def cancel_request(course):
|
||||||
request = frappe.get_doc('LMS Mentor Request', {'member': get_member().name, 'course': course, 'status': ['in', ('Pending', 'Approved')]})
|
request = frappe.get_doc('LMS Mentor Request', {'member': get_member().name, 'course': course, 'status': ['in', ('Pending', 'Approved')]})
|
||||||
request.status = 'Withdrawn'
|
request.status = 'Withdrawn'
|
||||||
request.save(ignore_permissions=True)
|
request.save(ignore_permissions=True)
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
def get_member():
|
def get_member():
|
||||||
try:
|
try:
|
||||||
return frappe.get_doc('Community Member', {'email': frappe.session.user})
|
return frappe.get_doc('Community Member', {'email': frappe.session.user})
|
||||||
except frappe.DoesNotExistError:
|
except frappe.DoesNotExistError:
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_course_author(course):
|
|
||||||
return frappe.db.get_value('LMS Course', course, 'owner')
|
|
||||||
|
|
||||||
def send_creation_email(course, member):
|
|
||||||
template = frappe.db.get_single_value('LMS Settings', 'mentor_request_creation')
|
|
||||||
if not template:
|
|
||||||
return
|
|
||||||
|
|
||||||
email_template = frappe.get_doc('Email Template', template)
|
|
||||||
member_name = member.full_name
|
|
||||||
message = frappe.render_template(email_template.response, {'member_name': member_name})
|
|
||||||
subject = _('Request for Mentorship')
|
|
||||||
send_email([frappe.session.user, get_course_author(course)], None, subject, message)
|
|
||||||
|
|
||||||
def send_email(recipients, cc=None, subject=None, message=None, template=None, args=None):
|
|
||||||
frappe.sendmail(
|
|
||||||
recipients = recipients,
|
|
||||||
cc = cc,
|
|
||||||
sender = frappe.db.get_single_value('LMS Settings', 'email_sender'),
|
|
||||||
subject = subject,
|
|
||||||
send_priority = 0,
|
|
||||||
queue_separately = True,
|
|
||||||
message = message,
|
|
||||||
template=template,
|
|
||||||
args=args
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
"contents",
|
"contents",
|
||||||
"code",
|
"code",
|
||||||
"attrs",
|
"attrs",
|
||||||
"index"
|
"index",
|
||||||
|
"id"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -43,12 +44,17 @@
|
|||||||
"fieldname": "index",
|
"fieldname": "index",
|
||||||
"fieldtype": "Int",
|
"fieldtype": "Int",
|
||||||
"label": "Index"
|
"label": "Index"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "id",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "id"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-03-12 17:56:23.118854",
|
"modified": "2021-05-19 18:55:26.019625",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Section",
|
"name": "LMS Section",
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ class LMSSection(Document):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<LMSSection {self.label!r}>"
|
return f"<LMSSection {self.label!r}>"
|
||||||
|
|
||||||
|
def get_exercise(self):
|
||||||
|
if self.type == "exercise":
|
||||||
|
return frappe.get_doc("Exercise", self.id)
|
||||||
|
|
||||||
def get_latest_code_for_user(self):
|
def get_latest_code_for_user(self):
|
||||||
"""Returns the latest code for the logged in user.
|
"""Returns the latest code for the logged in user.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -3,26 +3,102 @@
|
|||||||
import websocket
|
import websocket
|
||||||
import json
|
import json
|
||||||
from .svg import SVG
|
from .svg import SVG
|
||||||
|
import frappe
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
def livecode_to_svg(livecode_ws_url, code, *, timeout=1):
|
# 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.
|
"""Renders the code as svg.
|
||||||
"""
|
"""
|
||||||
print("livecode_to_svg")
|
if livecode_ws_url is None:
|
||||||
ws = websocket.WebSocket()
|
livecode_ws_url = get_livecode_ws_url()
|
||||||
ws.settimeout(timeout)
|
|
||||||
ws.connect(livecode_ws_url)
|
|
||||||
|
|
||||||
msg = {
|
try:
|
||||||
"msgtype": "exec",
|
ws = websocket.WebSocket()
|
||||||
"runtime": "python-canvas",
|
ws.settimeout(timeout)
|
||||||
"code": code
|
ws.connect(livecode_ws_url)
|
||||||
}
|
|
||||||
ws.send(json.dumps(msg))
|
|
||||||
|
|
||||||
messages = _read_messages(ws)
|
msg = {
|
||||||
commands = [m['cmd'] for m in messages if m['msgtype'] == 'draw']
|
"msgtype": "exec",
|
||||||
img = draw_image(commands)
|
"runtime": "python",
|
||||||
return img.tostring()
|
"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):
|
def _read_messages(ws):
|
||||||
messages = []
|
messages = []
|
||||||
@@ -32,17 +108,19 @@ def _read_messages(ws):
|
|||||||
if not msg:
|
if not msg:
|
||||||
break
|
break
|
||||||
messages.append(json.loads(msg))
|
messages.append(json.loads(msg))
|
||||||
except websocket.WebSocketTimeoutException:
|
except websocket.WebSocketTimeoutException as e:
|
||||||
|
print("Error:", e)
|
||||||
pass
|
pass
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def draw_image(commands):
|
def draw_image(commands):
|
||||||
img = SVG(width=300, height=300, viewBox="0 0 300 300", fill='none', stroke='black')
|
img = SVG(width=300, height=300, viewBox="0 0 300 300", fill='none', stroke='black')
|
||||||
for c in commands:
|
for c in commands:
|
||||||
|
args = c['args']
|
||||||
if c['function'] == 'circle':
|
if c['function'] == 'circle':
|
||||||
img.circle(cx=c['x'], cy=c['y'], r=c['d']/2)
|
img.circle(cx=args['x'], cy=args['y'], r=args['d']/2)
|
||||||
elif c['function'] == 'line':
|
elif c['function'] == 'line':
|
||||||
img.line(x1=c['x1'], y1=c['y1'], x2=c['x2'], y2=c['y2'])
|
img.line(x1=args['x1'], y1=args['y1'], x2=args['x2'], y2=args['y2'])
|
||||||
elif c['function'] == 'rect':
|
elif c['function'] == 'rect':
|
||||||
img.rect(x=c['x'], y=c['y'], width=c['w'], height=c['h'])
|
img.rect(x=args['x'], y=args['y'], width=args['w'], height=args['h'])
|
||||||
return img
|
return img
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import frappe
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from . import livecode
|
from . import livecode
|
||||||
|
|
||||||
|
DEFAULT_IMAGE = """
|
||||||
|
<svg viewBox="0 0 300 300" width="300" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
</svg>
|
||||||
|
"""
|
||||||
|
|
||||||
class LMSSketch(Document):
|
class LMSSketch(Document):
|
||||||
@property
|
@property
|
||||||
def sketch_id(self):
|
def sketch_id(self):
|
||||||
@@ -48,8 +53,9 @@ class LMSSketch(Document):
|
|||||||
else:
|
else:
|
||||||
ws_url = self.get_livecode_ws_url()
|
ws_url = self.get_livecode_ws_url()
|
||||||
value = livecode.livecode_to_svg(ws_url, self.code)
|
value = livecode.livecode_to_svg(ws_url, self.code)
|
||||||
cache.set(key, value)
|
if value:
|
||||||
return value
|
cache.set(key, value)
|
||||||
|
return value or DEFAULT_IMAGE
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_recent_sketches(limit=100, owner=None):
|
def get_recent_sketches(limit=100, owner=None):
|
||||||
@@ -77,7 +83,7 @@ def save_sketch(name, title, code):
|
|||||||
doc.title = title
|
doc.title = title
|
||||||
doc.code = code
|
doc.code = code
|
||||||
doc.runtime = 'python-canvas'
|
doc.runtime = 'python-canvas'
|
||||||
doc.insert()
|
doc.insert(ignore_permissions=True)
|
||||||
status = "created"
|
status = "created"
|
||||||
else:
|
else:
|
||||||
doc = frappe.get_doc("LMS Sketch", name)
|
doc = frappe.get_doc("LMS Sketch", name)
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
{
|
|
||||||
"actions": [],
|
|
||||||
"allow_guest_to_view": 1,
|
|
||||||
"creation": "2021-03-02 07:20:41.686573",
|
|
||||||
"doctype": "DocType",
|
|
||||||
"editable_grid": 1,
|
|
||||||
"engine": "InnoDB",
|
|
||||||
"field_order": [
|
|
||||||
"course",
|
|
||||||
"title",
|
|
||||||
"slug",
|
|
||||||
"preview",
|
|
||||||
"description",
|
|
||||||
"order",
|
|
||||||
"sections"
|
|
||||||
],
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldname": "title",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Title",
|
|
||||||
"reqd": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "description",
|
|
||||||
"fieldtype": "Markdown Editor",
|
|
||||||
"label": "Description"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "course",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"in_list_view": 1,
|
|
||||||
"label": "Course",
|
|
||||||
"options": "LMS Course",
|
|
||||||
"reqd": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "order",
|
|
||||||
"fieldtype": "Int",
|
|
||||||
"label": "Order"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "preview",
|
|
||||||
"fieldtype": "Markdown Editor",
|
|
||||||
"label": "Preview"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "sections",
|
|
||||||
"fieldtype": "Table",
|
|
||||||
"label": "Sections",
|
|
||||||
"options": "LMS Section"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "The slug of the topic. Autogenerated from the title if not specified.",
|
|
||||||
"fieldname": "slug",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"label": "Slug"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"index_web_pages_for_search": 1,
|
|
||||||
"links": [],
|
|
||||||
"modified": "2021-04-06 14:12:48.514062",
|
|
||||||
"modified_by": "Administrator",
|
|
||||||
"module": "LMS",
|
|
||||||
"name": "LMS Topic",
|
|
||||||
"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": "creation",
|
|
||||||
"sort_order": "ASC",
|
|
||||||
"title_field": "title",
|
|
||||||
"track_changes": 1,
|
|
||||||
"track_seen": 1,
|
|
||||||
"track_views": 1
|
|
||||||
}
|
|
||||||
@@ -1,43 +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 .section_parser import SectionParser
|
|
||||||
from ...utils import slugify
|
|
||||||
|
|
||||||
class LMSTopic(Document):
|
|
||||||
def before_save(self):
|
|
||||||
course = self.get_course()
|
|
||||||
if not self.slug:
|
|
||||||
self.slug = self.generate_slug(title=self.title)
|
|
||||||
|
|
||||||
sections = SectionParser().parse(self.description or "")
|
|
||||||
self.sections = [self.make_lms_section(i, s) for i, s in enumerate(sections)]
|
|
||||||
|
|
||||||
def get_course(self):
|
|
||||||
return frappe.get_doc("LMS Course", self.course)
|
|
||||||
|
|
||||||
def generate_slug(self, title):
|
|
||||||
result = frappe.get_all(
|
|
||||||
'LMS Topic',
|
|
||||||
filters={'course': self.course},
|
|
||||||
fields=['slug'])
|
|
||||||
slugs = set([row['slug'] for row in result])
|
|
||||||
return slugify(title, used_slugs=slugs)
|
|
||||||
|
|
||||||
def get_sections(self):
|
|
||||||
return sorted(self.sections, key=lambda s: s.index)
|
|
||||||
|
|
||||||
def make_lms_section(self, index, section):
|
|
||||||
s = frappe.new_doc('LMS Section', parent_doc=self, parentfield='sections')
|
|
||||||
s.type = section.type
|
|
||||||
s.label = section.label
|
|
||||||
s.contents = section.contents
|
|
||||||
s.index = index
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
"""Utility to split the text in the topic into multiple sections.
|
"""Utility to split the text in the topic into multiple sections.
|
||||||
|
|
||||||
|
{{ section(type="example", id="foo") }}
|
||||||
|
circle(100, 100, 50)
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@@ -1,19 +1,14 @@
|
|||||||
frappe.ready(function () {
|
frappe.ready(function () {
|
||||||
frappe.web_form.after_save = () => {
|
frappe.web_form.after_save = () => {
|
||||||
let data = frappe.web_form.get_values();
|
let data = frappe.web_form.get_values();
|
||||||
frappe.call({
|
let slug = new URLSearchParams(window.location.search).get("slug")
|
||||||
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
|
frappe.msgprint({
|
||||||
"args": {
|
message: __("Batch {0} has been successfully created!", [data.title]),
|
||||||
"batch": data.title,
|
clear: true
|
||||||
"member_type": "Mentor",
|
});
|
||||||
"course": data.course
|
setTimeout(function () {
|
||||||
},
|
window.location.href = `courses/${slug}`;
|
||||||
"callback": (data) => {
|
}, 2000);
|
||||||
if (data.message) {
|
|
||||||
window.location.href = `courses/${data.message}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.web_form.validate = () => {
|
frappe.web_form.validate = () => {
|
||||||
@@ -21,8 +16,13 @@ frappe.ready(function () {
|
|||||||
let time_format = sysdefaults && sysdefaults.time_format ? sysdefaults.time_format : 'HH:mm:ss';
|
let time_format = sysdefaults && sysdefaults.time_format ? sysdefaults.time_format : 'HH:mm:ss';
|
||||||
let data = frappe.web_form.get_values();
|
let data = frappe.web_form.get_values();
|
||||||
|
|
||||||
data.start_time = moment(data.start_time,time_format).format(time_format)
|
data.start_time = moment(data.start_time, time_format).format(time_format)
|
||||||
data.end_time = moment(data.end_time,time_format).format(time_format)
|
data.end_time = moment(data.end_time, time_format).format(time_format)
|
||||||
|
|
||||||
|
if (data.start_date < frappe.datetime.nowdate()) {
|
||||||
|
frappe.msgprint(__('Start date cannot be a past date.'))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!frappe.datetime.validate(data.start_time) || !frappe.datetime.validate(data.end_time)) {
|
if (!frappe.datetime.validate(data.start_time) || !frappe.datetime.validate(data.end_time)) {
|
||||||
frappe.msgprint(__('Invalid Start or End Time.'));
|
frappe.msgprint(__('Invalid Start or End Time.'));
|
||||||
@@ -34,10 +34,6 @@ frappe.ready(function () {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.start_date < date.nowdate()) {
|
|
||||||
frappe.msgprint(__('Start date cannot be a past date.'))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="course-footer">
|
<div class="course-footer">
|
||||||
<div class="course-author">
|
<div class="course-author">
|
||||||
<img class="course-author-avatar" src="{{ course.get_instructor().avatar }}" />{{ course.get_instructor().full_name }}
|
{% with author = course.get_instructor() %}
|
||||||
|
{{ widgets.Avatar(member=author, avatar_class="avatar-medium") }} <a href="/{{author.username}}">{{ author.full_name }}</a>
|
||||||
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
18
community/lms/widgets/Exercise.html
Normal file
18
community/lms/widgets/Exercise.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
|
|
||||||
|
<div class="exercise">
|
||||||
|
<h2>{{ exercise.title }}</h2>
|
||||||
|
<div class="exercise-description">{{frappe.utils.md_to_html(exercise.description)}}</div>
|
||||||
|
|
||||||
|
{% if exercise.image %}
|
||||||
|
<div class="exercise-image">{{exercise.image}}</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% set submission = exercise.get_user_submission() %}
|
||||||
|
|
||||||
|
{{ LiveCodeEditor(exercise.name,
|
||||||
|
code=submission.solution if submission else exercise.code,
|
||||||
|
reset_code=exercise.code,
|
||||||
|
is_exercise=True,
|
||||||
|
last_submitted=submission and submission.creation) }}
|
||||||
|
</div>
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
<form id="invite-request-form">
|
<form id="invite-request-form">
|
||||||
<input class="form-control field-width mr-5" id="invite_email" type="email" placeholder="Email Address">
|
<div class="row">
|
||||||
<a type="submit" id="submit-invite-request" class="btn btn-primary btn-lg" href="#" role="button">Request Invite</a>
|
<div class="col-md">
|
||||||
|
<input class="form-control w-100 mr-5 mb-5 mt-2" id="invite_email" type="email" placeholder="Email Address">
|
||||||
|
</div>
|
||||||
|
<div class="col-md">
|
||||||
|
<a type="submit" id="submit-invite-request" class="btn btn-primary btn-lg" role="button">Request
|
||||||
|
Invite</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
@@ -12,27 +19,44 @@
|
|||||||
invite_email: invite_email
|
invite_email: invite_email
|
||||||
},
|
},
|
||||||
callback: (data) => {
|
callback: (data) => {
|
||||||
$("#invite-request-form").hide();
|
if (data.message == "invalid email") {
|
||||||
|
$(".email-validation") && $(".email-validation").remove();
|
||||||
if (data.message == "OK") {
|
if (invite_email) {
|
||||||
var message = `<div>
|
var message = `<div>
|
||||||
<p class="lead">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p>
|
<small class="email-validation" style="color: red;">${invite_email} is not a valid email address.</small>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
else if (data.message == "invite") {
|
var message = `<div>
|
||||||
var message = `<div>
|
<small class="email-validation" style="color: red;">Please enter an email address.</small>
|
||||||
<p class="lead">Email ${invite_email} has already been used to request an invitation.</p>
|
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (data.message == "user") {
|
$("#invite-request-form").append(message);
|
||||||
var message = `<div>
|
}
|
||||||
<p class="lead">Looks like there is already an account with email ${invite_email}. Would you like to <a href="/login">login</a>.</p>
|
else {
|
||||||
|
$("#invite-request-form").hide();
|
||||||
|
|
||||||
|
if (data.message == "OK") {
|
||||||
|
var message = `<div>
|
||||||
|
<p class="lead alert alert-secondary">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".jumbotron").append(message);
|
else if (data.message == "invite") {
|
||||||
|
var message = `<div>
|
||||||
|
<p class="lead alert alert-secondary">Email ${invite_email} has already been used to request an invitation.</p>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (data.message == "user") {
|
||||||
|
var message = `<div>
|
||||||
|
<p class="lead alert alert-secondary">Looks like there is already an account with email ${invite_email}. Would you like to <a href="/login">login</a>?</p>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".jumbotron").append(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
|
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="sketch-author">
|
<div class="sketch-author">
|
||||||
by {{sketch.get_owner().full_name}}
|
{% set owner = sketch.get_owner() %}
|
||||||
|
by <a href="/{{owner.username}}">{{owner.full_name}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
community.patches.set_email_preferences
|
community.patches.set_email_preferences
|
||||||
community.patches.change_name_for_community_members
|
community.patches.change_name_for_community_members
|
||||||
community.patches.save_abbr_for_community_members
|
community.patches.save_abbr_for_community_members
|
||||||
|
community.patches.create_mentor_request_email_templates
|
||||||
|
|||||||
31
community/patches/create_mentor_request_email_templates.py
Normal file
31
community/patches/create_mentor_request_email_templates.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
import frappe, os
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
frappe.reload_doc("email", "doctype", "email_template")
|
||||||
|
base_path = frappe.get_app_path("community", "templates", "emails")
|
||||||
|
|
||||||
|
if not frappe.db.exists("Email Template", _('Mentor Request Creation Template')):
|
||||||
|
response = frappe.read_file(os.path.join(base_path, "mentor_request_creation_email.html"))
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Email Template',
|
||||||
|
'name': _("Mentor Request Creation Template"),
|
||||||
|
'response': response,
|
||||||
|
'subject': _('Request for Mentorship'),
|
||||||
|
'owner': frappe.session.user
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
frappe.db.set_value("LMS Settings", None, "mentor_request_creation", _('Mentor Request Creation Template'))
|
||||||
|
|
||||||
|
if not frappe.db.exists("Email Template", _('Mentor Request Status Update Template')):
|
||||||
|
response = frappe.read_file(os.path.join(base_path, "mentor_request_status_update_email.html"))
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Email Template',
|
||||||
|
'name': _("Mentor Request Status Update Template"),
|
||||||
|
'response': response,
|
||||||
|
'subject': _('The status of your application has changed.'),
|
||||||
|
'owner': frappe.session.user
|
||||||
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
|
frappe.db.set_value("LMS Settings", None, "mentor_request_status_update", _('Mentor Request Status Update Template'))
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"css/lms.css": [
|
|
||||||
"public/css/lms.css"
|
|
||||||
],
|
|
||||||
"css/community.css": [
|
|
||||||
"public/css/style.css",
|
|
||||||
"public/css/vars.css",
|
|
||||||
"public/css/style.less"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
4
community/public/css/community.bundle.less
Normal file
4
community/public/css/community.bundle.less
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
@import "./style.css";
|
||||||
|
@import "./vars.css";
|
||||||
|
@import "./style.less";
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
|
|
||||||
.livecode-editor-large .canvas-wrapper {
|
|
||||||
position: relative;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large canvas {
|
|
||||||
position: relative;
|
|
||||||
z-index: 0;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
height: 300px;
|
|
||||||
width: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large .code {
|
|
||||||
width: 100%;
|
|
||||||
padding: 5px;
|
|
||||||
min-height: 330px;
|
|
||||||
resize: none;
|
|
||||||
}
|
|
||||||
.livecode-editor-large .output {
|
|
||||||
padding: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large .CodeMirror {
|
|
||||||
height: 320px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.canvas-editor canvas {
|
|
||||||
position: relative;
|
|
||||||
z-index: 0;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
}
|
|
||||||
.canvas-wrapper .output {
|
|
||||||
position: absolute;
|
|
||||||
z-index: 1;
|
|
||||||
width: 100%;
|
|
||||||
left: 0px;
|
|
||||||
top: 0px;
|
|
||||||
background-color: rgba(255, 255, 255, 0);
|
|
||||||
margin: 15px;
|
|
||||||
max-height: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.canvas-editor .code {
|
|
||||||
width: 100%;
|
|
||||||
padding: 5px;
|
|
||||||
/* min-height: 330px; */
|
|
||||||
resize: none;
|
|
||||||
}
|
|
||||||
/* .canvas-editor .output {
|
|
||||||
padding: 5px;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.heading {
|
|
||||||
background: #eee;
|
|
||||||
padding: 10px;
|
|
||||||
clear: both;
|
|
||||||
color: #212529;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large h2 {
|
|
||||||
font-size: 1.2em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
margin: 0px;
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large .run {
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-editor-large .col-sm {
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sketch-header h1 {
|
|
||||||
font-size: 1.5em;
|
|
||||||
margin-bottom: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sketch-header {
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sketch-card .sketch-title a {
|
|
||||||
font-weight: bold;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.canvas-editor .CodeMirror {
|
|
||||||
background: #ffe;
|
|
||||||
border: 1px solid #eed;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
border-radius: 10px;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas {
|
|
||||||
border: 2px solid #eee;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
|
||||||
.canvas-wrapper {
|
|
||||||
margin-bottom: -200px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.canvas-wrapper {
|
|
||||||
padding-top: 20px;
|
|
||||||
margin-left: 2em;
|
|
||||||
}
|
|
||||||
.canvas-wrapper .output {
|
|
||||||
left: 2em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-controls {
|
|
||||||
margin-left: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.livecode-controls a {
|
|
||||||
margin-left: 10px;
|
|
||||||
color: #666;
|
|
||||||
}
|
|
||||||
|
|
||||||
.canvas-editor {
|
|
||||||
margin: 10px 0px;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css");
|
|
||||||
@import url("https://use.fontawesome.com/releases/v5.13.0/css/all.css");
|
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--c1: #fefae0;
|
--c1: #fefae0;
|
||||||
@@ -26,7 +24,7 @@
|
|||||||
--send-message: var(--c7);
|
--send-message: var(--c7);
|
||||||
--received-message: var(--c8);
|
--received-message: var(--c8);
|
||||||
|
|
||||||
--primary-color: #08B74F;
|
--primary-color: #08B74F !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -77,7 +75,7 @@ body {
|
|||||||
.lessons {
|
.lessons {
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
}
|
}
|
||||||
.lesson {
|
.lessons .lesson {
|
||||||
margin: 5px 0px;
|
margin: 5px 0px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
@@ -167,7 +165,7 @@ img.profile-photo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.msger-inputarea {
|
.msger-inputarea {
|
||||||
position: fixed;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
@primary-color: #08B74F;
|
@primary-color: #08B74F;
|
||||||
@import url('https://rsms.me/inter/inter.css');
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: "Inter", sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
margin: 20px 0px;
|
margin: 20px 0px;
|
||||||
@@ -232,3 +227,113 @@ section.lightgray {
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LiveCode editor
|
||||||
|
|
||||||
|
.livecode-editor {
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background: #ffe;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
max-height: 310px;
|
||||||
|
min-height: 310px;
|
||||||
|
}
|
||||||
|
.controls {
|
||||||
|
padding: 10px 0px;
|
||||||
|
}
|
||||||
|
canvas {
|
||||||
|
border: 5px solid #ddd;
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.output {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
width: 300px;
|
||||||
|
left: 0px;
|
||||||
|
top: 0px;
|
||||||
|
background-color: rgba(255, 255, 255, 0);
|
||||||
|
max-height: 300px;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
margin: 0px;
|
||||||
|
margin-left: 20px;
|
||||||
|
padding: 4px;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.canvas-wrapper {
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
.code-wrapper {
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
.CodeMirror {
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sketch-header {
|
||||||
|
input#sketch-title {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chapter-description {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lesson-teaser {
|
||||||
|
font-weight: bold;
|
||||||
|
color: black;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hero h1 {
|
||||||
|
color: black !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lesson-page {
|
||||||
|
margin: 20px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lesson-pagination {
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.exercise-image svg {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.svg-200 svg {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.livecode-editor-small .livecode-editor {
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
max-height: 160px;
|
||||||
|
min-height: 160px;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mentor-dashboard {
|
||||||
|
margin-top: 20px;
|
||||||
|
|
||||||
|
.submission {
|
||||||
|
margin: 40px 0px 0px 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg width="104px" height="81px" viewBox="0 0 104 81" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
||||||
<!-- Generator: Sketch 61.2 (89653) - https://sketch.com -->
|
|
||||||
<title>Group 2</title>
|
|
||||||
<desc>Created with Sketch.</desc>
|
|
||||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
||||||
<g id="site" transform="translate(-160.803147, -89.000000)">
|
|
||||||
<g id="Group-2" transform="translate(163.323899, 91.260768)">
|
|
||||||
<g id="g1593" transform="translate(10.217829, 8.684369)" fill="black" fill-rule="nonzero">
|
|
||||||
<g id="text1571" transform="translate(0.248104, 0.000000)">
|
|
||||||
<polygon id="path1919" points="6.20610364 30.6588166 0.0881167018 30.6588166 0.0881167018 0.711614981 15.1331308 0.711614981 15.1331308 6.82960641 6.20610364 6.82960641 6.20610364 12.6143164 15.1331308 12.6143164 15.1331308 18.7323078 6.20610364 18.7323078"></polygon>
|
|
||||||
<path d="M24.0601557,24.5170177 L29.8448702,24.5170177 L29.8448702,6.82960641 L24.0601557,6.82960641 L24.0601557,24.5170177 Z M20.917843,30.6588166 L20.917843,27.6593507 L17.9421688,27.6593507 L17.9421688,3.68729595 L20.917843,3.68729595 L20.917843,0.711614981 L32.9871829,0.711614981 L32.9871829,3.68729595 L35.9628571,3.68729595 L35.9628571,27.6593507 L32.9871829,27.6593507 L32.9871829,30.6588166 L20.917843,30.6588166 Z M18.108805,0.806844685 L20.917843,0.806844685 L20.917843,3.68729595 L18.108805,3.68729595 L18.108805,0.806844685 Z M32.9871829,0.711525057 L35.9628571,0.711525057 L35.9628571,3.68720602 L32.9871829,3.68720602 L32.9871829,0.711525057 Z M32.9871829,27.6592608 L35.9628571,27.6592608 L35.9628571,30.5635195 L32.9871829,30.5635195 L32.9871829,27.6592608 Z M17.9421688,27.6592608 L20.917843,27.6592608 L20.917843,30.6587267 L17.9421688,30.6587267 L17.9421688,27.6592608 Z" id="path1921"></path>
|
|
||||||
<path d="M53.8169092,30.6588166 L38.7718951,30.6588166 L38.7718951,24.5170177 L50.6745942,24.5170177 L50.6745942,18.7323078 L41.7475693,18.7323078 L41.7475693,15.7566493 L38.7718951,15.7566493 L38.7718951,3.68729595 L41.7475693,3.68729595 L41.7475693,0.711614981 L56.7925834,0.711614981 L56.7925834,6.82960641 L44.889882,6.82960641 L44.889882,12.6143164 L53.8169092,12.6143164 L53.8169092,15.5899973 L56.7925834,15.5899973 L56.7925834,27.6593507 L53.8169092,27.6593507 L53.8169092,30.6588166 Z M38.9385313,0.806844685 L41.7475693,0.806844685 L41.7475693,3.68729595 L38.9385313,3.68729595 L38.9385313,0.806844685 Z M38.7719018,15.7566493 L41.747576,15.7566493 L41.747576,18.7323078 L38.7719018,18.7323078 L38.7719018,15.7566493 Z M53.8169159,12.6143164 L56.7925901,12.6143164 L56.7925901,15.5899973 L53.8169159,15.5899973 L53.8169159,12.6143164 Z M53.8169159,27.6593507 L56.7925901,27.6593507 L56.7925901,30.5636094 L53.8169159,30.5636094 L53.8169159,27.6593507 Z" id="path1923"></path>
|
|
||||||
<path d="M74.64664,30.6588166 L59.6016259,30.6588166 L59.6016259,24.5170177 L71.5043273,24.5170177 L71.5043273,18.7323078 L62.5773023,18.7323078 L62.5773023,15.7566493 L59.6016259,15.7566493 L59.6016259,3.68729595 L62.5773023,3.68729595 L62.5773023,0.711614981 L77.6223164,0.711614981 L77.6223164,6.82960641 L65.7196151,6.82960641 L65.7196151,12.6143164 L74.64664,12.6143164 L74.64664,15.5899973 L77.6223164,15.5899973 L77.6223164,27.6593507 L74.64664,27.6593507 L74.64664,30.6588166 Z M59.7682644,0.806844685 L62.5773023,0.806844685 L62.5773023,3.68729595 L59.7682644,3.68729595 L59.7682644,0.806844685 Z M59.6016349,15.7566493 L62.5773113,15.7566493 L62.5773113,18.7323078 L59.6016349,18.7323078 L59.6016349,15.7566493 Z M74.646649,12.6143164 L77.6223254,12.6143164 L77.6223254,15.5899973 L74.646649,15.5899973 L74.646649,12.6143164 Z M74.646649,27.6593507 L77.6223254,27.6593507 L77.6223254,30.5636094 L74.646649,30.5636094 L74.646649,27.6593507 Z" id="path1925"></path>
|
|
||||||
</g>
|
|
||||||
<g id="text1575" transform="translate(0.127883, 35.473579)">
|
|
||||||
<path d="M2.35734791,22.5432945 L2.35734791,20.3720424 L0.206884567,20.3720424 L0.206884567,0.865355398 L4.62823747,0.865355398 L4.62823747,18.0974048 L8.80873794,18.0974048 L8.80873794,0.865355398 L13.2300908,0.865355398 L13.2300908,20.3720424 L11.0796275,20.3720424 L11.0796275,22.5432945 L2.35734791,22.5432945 Z M0.206884567,20.3720424 L2.35734791,20.3720424 L2.35734791,22.5432945 L0.206884567,22.5432945 L0.206884567,20.3720424 Z M11.0796275,20.3720424 L13.2300908,20.3720424 L13.2300908,22.4743558 L11.0796275,22.4743558 L11.0796275,20.3720424 Z" id="path1928"></path>
|
|
||||||
<polygon id="path1930" points="19.6814809 22.5432945 15.260128 22.5432945 15.260128 0.865355398 28.2833343 0.865355398 28.2833343 22.5432945 23.8619814 22.5432945 23.8619814 5.29401037 19.6814809 5.29401037"></polygon>
|
|
||||||
<polygon id="path1932" points="34.7347243 22.5432945 30.3133714 22.5432945 30.3133714 0.865355398 34.7347243 0.865355398"></polygon>
|
|
||||||
<polygon id="path1934" points="45.4870433 22.5432945 41.0656904 22.5432945 41.0656904 5.29401037 36.7647637 5.29401037 36.7647637 0.865355398 49.7879699 0.865355398 49.7879699 5.29401037 45.4870433 5.29401037"></polygon>
|
|
||||||
<polygon id="path1936" points="62.6907478 22.5432945 51.8180048 22.5432945 51.8180048 0.865355398 62.6907478 0.865355398 62.6907478 5.29401037 56.2393577 5.29401037 56.2393577 9.48138012 62.6907478 9.48138012 62.6907478 13.9100351 56.2393577 13.9100351 56.2393577 18.0974048 62.6907478 18.0974048"></polygon>
|
|
||||||
<path d="M69.1421378,18.0974048 L73.3226383,18.0974048 L73.3226383,5.29401037 L69.1421378,5.29401037 L69.1421378,18.0974048 Z M64.7207849,22.5432945 L64.7207849,0.865355398 L75.5935278,0.865355398 L75.5935278,3.01937283 L77.7439912,3.01937283 L77.7439912,20.3720424 L75.5935278,20.3720424 L75.5935278,22.5432945 L64.7207849,22.5432945 Z" id="path1938"></path>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<rect id="rect1579" stroke="black" stroke-width="3.99998745" x="0" y="0" width="98.6425638" height="76.0972583"></rect>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 6.1 KiB |
106
community/public/js/livecode-canvas.js
Normal file
106
community/public/js/livecode-canvas.js
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
function getLiveCodeOptions() {
|
||||||
|
var START = `
|
||||||
|
import sketch
|
||||||
|
code = open("main.py").read()
|
||||||
|
env = dict(sketch.__dict__)
|
||||||
|
exec(code, env)
|
||||||
|
`
|
||||||
|
|
||||||
|
var 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()
|
||||||
|
`
|
||||||
|
const CANVAS_FUNCTIONS = {
|
||||||
|
circle: function(ctx, args) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(args.x, args.y, args.d/2, 0, 2*Math.PI);
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
line: function(ctx, args) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(args.x1, args.y1);
|
||||||
|
ctx.lineTo(args.x2, args.y2);
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
rect: function(ctx, args) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.rect(args.x, args.y, args.w, args.h);
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
clear: function(ctx, args) {
|
||||||
|
var width = 300;
|
||||||
|
var height = 300;
|
||||||
|
ctx.clearRect(0, 0, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawOnCanvas(canvasElement, funcName, args) {
|
||||||
|
var ctx = canvasElement.getContext('2d');
|
||||||
|
var func = CANVAS_FUNCTIONS[funcName];
|
||||||
|
|
||||||
|
var scalex = canvasElement.width/300;
|
||||||
|
var scaley = canvasElement.height/300;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.scale(scalex, scaley);
|
||||||
|
func(ctx, args);
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
runtime: "python",
|
||||||
|
files: [
|
||||||
|
{filename: "start.py", contents: START},
|
||||||
|
{filename: "sketch.py", contents: SKETCH},
|
||||||
|
],
|
||||||
|
command: ["python", "start.py"],
|
||||||
|
codemirror: true,
|
||||||
|
onMessage: {
|
||||||
|
draw: function(editor, msg) {
|
||||||
|
const canvasElement = editor.parent.querySelector("canvas");
|
||||||
|
drawOnCanvas(canvasElement, msg.function, msg.args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<div>
|
||||||
|
<p>Dear {{ member_name }},</p>
|
||||||
|
<br>
|
||||||
|
<p>You've applied to become a mentor for this course. Your request is currently under review.</p>
|
||||||
|
<p>If you are not any more interested to mentor the course {{ course }}, you can <a href="{{ course_url }}">cancel your application</a>.</p>
|
||||||
|
<br>
|
||||||
|
<p>Thanks and Regards,</p>
|
||||||
|
<p>Team Community.</p>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<div>
|
||||||
|
<p>Dear {{ member_name }},</p>
|
||||||
|
<br>
|
||||||
|
<p>Your request to join us as a mentor for the course {{ course }} has been {{ status }}.</p>
|
||||||
|
<br>
|
||||||
|
<p>Thanks and Regards,</p>
|
||||||
|
<p>Team Community.</p>
|
||||||
|
</div>
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
<div class="footer-info">
|
|
||||||
<div class="row">
|
|
||||||
<div class="footer-col-left col-sm-6 col-12">
|
|
||||||
<img src="/assets/community/images/fossunited-logo.svg" style="width: 50px;">
|
|
||||||
</div>
|
|
||||||
{# powered #}
|
|
||||||
<div class="footer-col-right col-sm-6 col-12 footer-powered">
|
|
||||||
{% block powered %}
|
|
||||||
{% include "templates/includes/footer/footer_powered.html" %}
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<div class="footer-logo-extension">
|
|
||||||
<div class="row">
|
|
||||||
<div class="text-left col-6">
|
|
||||||
<h3>Mon School</h3>
|
|
||||||
</div>
|
|
||||||
<div class="text-right col-6">
|
|
||||||
{% block extension %}
|
|
||||||
{% include "templates/includes/footer/footer_extension.html" %}
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -36,8 +36,9 @@ class Widgets:
|
|||||||
'<div>Hello, World!</div>'
|
'<div>Hello, World!</div>'
|
||||||
"""
|
"""
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
widget_globals = {"widgets": self}
|
||||||
if not name.startswith("__"):
|
if not name.startswith("__"):
|
||||||
return Widget(name)
|
return Widget(name, widget_globals)
|
||||||
else:
|
else:
|
||||||
raise AttributeError(name)
|
raise AttributeError(name)
|
||||||
|
|
||||||
@@ -51,11 +52,13 @@ class Widget:
|
|||||||
>>> w(name="World!")
|
>>> w(name="World!")
|
||||||
'<div>Hello, World!</div>'
|
'<div>Hello, World!</div>'
|
||||||
"""
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, name, widget_globals={}):
|
||||||
|
self.widget_globals = widget_globals
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __call__(self, **kwargs):
|
def __call__(self, **kwargs):
|
||||||
# the widget could be in any of the modules
|
# the widget could be in any of the modules
|
||||||
paths = [f"{module}/widgets/{self.name}.html" for module in MODULES]
|
paths = [f"{module}/widgets/{self.name}.html" for module in MODULES]
|
||||||
env = get_jenv()
|
env = get_jenv()
|
||||||
|
kwargs.update(self.widget_globals)
|
||||||
return env.get_or_select_template(paths).render(kwargs)
|
return env.get_or_select_template(paths).render(kwargs)
|
||||||
|
|||||||
0
community/www/batch/__init__.py
Normal file
0
community/www/batch/__init__.py
Normal file
@@ -6,10 +6,13 @@
|
|||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="" />
|
<meta name="keywords" content="" />
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course.name, batch.name) }}
|
{{ Sidebar(course, batch) }}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ CourseBasicDetail(course)}}
|
{{ CourseBasicDetail(course)}}
|
||||||
{{ InstructorsSection(course.get_instructor()) }}
|
{{ InstructorsSection(course.get_instructor()) }}
|
||||||
@@ -46,9 +49,7 @@
|
|||||||
|
|
||||||
{% for m in batch.get_mentors() %}
|
{% for m in batch.get_mentors() %}
|
||||||
<div>
|
<div>
|
||||||
{% if m.photo_url %}
|
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||||
<img class="profile-photo" src="{{m.photo_url}}">
|
|
||||||
{% endif %}
|
|
||||||
<span class="instructor-title">{{m.full_name}}</span>
|
<span class="instructor-title">{{m.full_name}}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
7
community/www/batch/about.py
Normal file
7
community/www/batch/about.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
|
|
||||||
|
print("context", context)
|
||||||
@@ -6,18 +6,23 @@
|
|||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="" />
|
<meta name="keywords" content="" />
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course_slug, batch_code) }}
|
{{ Sidebar(course, batch) }}
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="batch-header">
|
<div class="batch-header">
|
||||||
{{ BatchHearder(course.name, member_count) }}
|
{{ BatchHearder(course.title, member_count) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="message-section">
|
<div class="messages">
|
||||||
{{ Messages(messages) }}
|
<div class="message-section">
|
||||||
|
{{ Messages(messages) }}
|
||||||
|
</div>
|
||||||
|
{{ TextArea() }}
|
||||||
</div>
|
</div>
|
||||||
{{ TextArea() }}
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@@ -44,4 +49,4 @@
|
|||||||
<input type="text" class="msger-input" placeholder="Write your message...">
|
<input type="text" class="msger-input" placeholder="Write your message...">
|
||||||
<button type="submit" class="msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
<button type="submit" class="msger-send-btn" data-batch="{{batch.name | urlencode }}">Send</button>
|
||||||
</form>
|
</form>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
9
community/www/batch/discuss.py
Normal file
9
community/www/batch/discuss.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
from community.lms.doctype.lms_batch.lms_batch import get_messages
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
|
|
||||||
|
context.members = utils.get_batch_members(context.batch.name)
|
||||||
|
context.member_count = len(context.members)
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
{% extends "templates/base.html" %}
|
{% extends "templates/base.html" %}
|
||||||
{% from "www/macros/livecode.html" import LiveCodeEditor with context %}
|
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||||
{% block title %}{{topic.title}} ({{course.title}}){% endblock %}
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
|
{% block title %}{{ lesson.title }}{% endblock %}
|
||||||
|
|
||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Topic {{topic.title}} of the course {{course.title}}" />
|
<meta name="description" content="{{lesson.title}} - {{course.title}}" />
|
||||||
<meta name="keywords" content="course {{course.title}} {{topic.title}}" />
|
<meta name="keywords" content="{{lesson.title}} - {{course.title}}" />
|
||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
||||||
<link rel="stylesheet" href="/assets/css/lms.css">
|
<link rel="stylesheet" href="/assets/css/lms.css">
|
||||||
|
|
||||||
@@ -18,33 +21,40 @@
|
|||||||
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
|
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section class="top-section" style="padding: 1rem 0rem;">
|
{{ Sidebar(course, batch) }}
|
||||||
<div class='container pb-5'>
|
|
||||||
<nav aria-label="breadcrumb">
|
|
||||||
<ol class="breadcrumb">
|
|
||||||
<li class="breadcrumb-item" aria-current="page"><a href="/courses">Courses</a></li>
|
|
||||||
<li class="breadcrumb-item" aria-current="page"><a href="/courses/{{course.slug}}">{{course.title}}</a></li>
|
|
||||||
</ol>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h1>{{ topic.title }}</h1>
|
<div class="container">
|
||||||
|
<div class="lesson-page">
|
||||||
|
{{ pagination(prev_url, next_url) }}
|
||||||
|
|
||||||
{% for s in topic.get_sections() %}
|
<h2>{{ lesson.title }}</h2>
|
||||||
|
|
||||||
|
{% for s in lesson.get_sections() %}
|
||||||
<div class="section section-{{ s.type }}">
|
<div class="section section-{{ s.type }}">
|
||||||
{{ render_section(s) }}
|
{{ render_section(s) }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
{{ pagination(prev_url, next_url) }}
|
||||||
</section>
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
{% macro render_section(s) %}
|
{% macro render_section(s) %}
|
||||||
{% if s.type == "text" %}
|
{% if s.type == "text" %}
|
||||||
{{ render_section_text(s) }}
|
{{ render_section_text(s) }}
|
||||||
{% elif s.type == "example" or s.type == "code" %}
|
{% elif s.type == "example" or s.type == "code" %}
|
||||||
{{ LiveCodeEditor(s.name, s.get_latest_code_for_user()) }}
|
{{ LiveCodeEditor(s.name,
|
||||||
|
code=s.get_latest_code_for_user(),
|
||||||
|
reset_code=s.contents,
|
||||||
|
is_exercise=False)
|
||||||
|
}}
|
||||||
|
{% elif s.type == "exercise" %}
|
||||||
|
{{ widgets.Exercise(exercise=s.get_exercise())}}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div>Unknown section type: {{s.type}}</div>
|
<div>Unknown section type: {{s.type}}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -58,10 +68,24 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro pagination(prev_url, next_url) %}
|
||||||
|
<div class="lesson-pagination">
|
||||||
|
{% if prev_url %}
|
||||||
|
<a href="{{prev_url}}" class="btn">← Prev</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if next_url %}
|
||||||
|
<a href="{{next_url}}" class="btn pull-right">Next →</a>
|
||||||
|
{% endif %}
|
||||||
|
<div style="clear: both;"></div>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
|
{{ LiveCodeEditorJS() }}
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
|
<!-- <script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
var editorLookup = {};
|
var editorLookup = {};
|
||||||
|
|
||||||
@@ -104,5 +128,5 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script> -->
|
||||||
{%- endblock %}
|
{%- endblock %}
|
||||||
31
community/www/batch/learn.py
Normal file
31
community/www/batch/learn.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
|
|
||||||
|
chapter_index = frappe.form_dict.get("chapter")
|
||||||
|
lesson_index = frappe.form_dict.get("lesson")
|
||||||
|
lesson_number = f"{chapter_index}.{lesson_index}"
|
||||||
|
|
||||||
|
course_name = context.course.name
|
||||||
|
batch_name = context.batch.name
|
||||||
|
|
||||||
|
if not chapter_index or not lesson_index:
|
||||||
|
frappe.local.flags.redirect_location = f"/courses/{course_name}/{batch_name}/learn/1.1"
|
||||||
|
raise frappe.Redirect
|
||||||
|
|
||||||
|
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
|
||||||
|
context.lesson_index = lesson_index
|
||||||
|
context.chapter_index = chapter_index
|
||||||
|
|
||||||
|
outline = context.course.get_outline()
|
||||||
|
next_ = outline.get_next(lesson_number)
|
||||||
|
prev_ = outline.get_prev(lesson_number)
|
||||||
|
context.next_url = get_learn_url(course_name, batch_name, next_)
|
||||||
|
context.prev_url = get_learn_url(course_name, batch_name, prev_)
|
||||||
|
|
||||||
|
def get_learn_url(course_name, batch_name, lesson_number):
|
||||||
|
if not lesson_number:
|
||||||
|
return
|
||||||
|
return f"/courses/{course_name}/{batch_name}/learn/{lesson_number}"
|
||||||
@@ -7,12 +7,14 @@
|
|||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="" />
|
<meta name="keywords" content="" />
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course_slug, batch_code) }}
|
{{ Sidebar(course, batch) }}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{ BatchHearder(course.name, member_count)}}
|
{{ BatchHearder(course.title, member_count)}}
|
||||||
{{ MembersList(members)}}
|
{{ MembersList(members)}}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -35,4 +37,4 @@
|
|||||||
<hr>
|
<hr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
8
community/www/batch/members.py
Normal file
8
community/www/batch/members.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import frappe
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
|
|
||||||
|
context.members = utils.get_batch_members(context.batch.name)
|
||||||
|
context.member_count = len(context.members)
|
||||||
52
community/www/batch/progress.html
Normal file
52
community/www/batch/progress.html
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
{% extends "templates/base.html" %}
|
||||||
|
{% from "www/macros/sidebar.html" import Sidebar %}
|
||||||
|
{% from "www/macros/livecode.html" import LiveCodeEditorJS, LiveCodeEditor with context %}
|
||||||
|
{% block title %}{{ course.title }} - Batch Dashboard{% endblock %}
|
||||||
|
|
||||||
|
{% block head_include %}
|
||||||
|
<meta name="description" content="{{course.title}} - Batch Dashboard" />
|
||||||
|
<meta name="keywords" content="{{course.title}} - Batch Dashboard" />
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
|
<link rel="stylesheet" href="{{ livecode_url }}/static/codemirror/lib/codemirror.css">
|
||||||
|
<link rel="stylesheet" href="/assets/css/lms.css">
|
||||||
|
|
||||||
|
<script src="{{ livecode_url }}/static/codemirror/lib/codemirror.js"></script>
|
||||||
|
<script src="{{ livecode_url }}/static/codemirror/mode/python/python.js"></script>
|
||||||
|
<script src="{{ livecode_url }}/static/codemirror/keymap/sublime.js"></script>
|
||||||
|
|
||||||
|
<script src="{{ livecode_url }}/static/codemirror/addon/edit/matchbrackets.js"></script>
|
||||||
|
<script src="{{ livecode_url }}/static/codemirror/addon/comment/comment.js"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{{ Sidebar(course, batch) }}
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="mentor-dashboard">
|
||||||
|
<h1>Batch Progress</h1>
|
||||||
|
{% for exercise in report.exercises %}
|
||||||
|
<div class="exercise-submissions">
|
||||||
|
<h2>{{exercise.title}}</h2>
|
||||||
|
{% for s in report.get_submissions_of_exercise(exercise.name) %}
|
||||||
|
<div class="submission">
|
||||||
|
<h4><a href="/{{s.owner.username}}">{{s.owner.full_name}}</a></h4>
|
||||||
|
<div class="livecode-editor-small">
|
||||||
|
{{ LiveCodeEditor(name=s.name, code=s.solution, reset_code=s.solution) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{%- block script %}
|
||||||
|
{{ super() }}
|
||||||
|
{{ LiveCodeEditorJS() }}
|
||||||
|
{% endblock %}
|
||||||
64
community/www/batch/progress.py
Normal file
64
community/www/batch/progress.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import frappe
|
||||||
|
from community.lms.models import Course
|
||||||
|
from collections import defaultdict
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def get_context(context):
|
||||||
|
utils.get_common_context(context)
|
||||||
|
|
||||||
|
exercise_name = frappe.form_dict.get("exercise")
|
||||||
|
if exercise_name:
|
||||||
|
exercise = frappe.get_doc("Exercise", exercise_name)
|
||||||
|
else:
|
||||||
|
exercise = None
|
||||||
|
|
||||||
|
context.exercise = exercise
|
||||||
|
context.report = BatchReport(context.course, context.batch)
|
||||||
|
|
||||||
|
class BatchReport:
|
||||||
|
def __init__(self, course, batch):
|
||||||
|
self.submissions = get_submissions(batch)
|
||||||
|
self.exercises = self.get_exercises(course.name)
|
||||||
|
|
||||||
|
self.submissions_by_exercise = defaultdict(list)
|
||||||
|
for s in self.submissions:
|
||||||
|
self.submissions_by_exercise[s.exercise].append(s)
|
||||||
|
|
||||||
|
def get_exercises(self, course_name):
|
||||||
|
return frappe.get_all("Exercise", {"course": course_name}, ["name", "title"])
|
||||||
|
|
||||||
|
def get_submissions_of_exercise(self, exercise_name):
|
||||||
|
return self.submissions_by_exercise[exercise_name]
|
||||||
|
|
||||||
|
def get_submissions(batch):
|
||||||
|
students = batch.get_students()
|
||||||
|
students_map = {s['email']: s for s in students}
|
||||||
|
|
||||||
|
names, values = nparams("s", students_map.keys())
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
select owner, exercise, name, solution, creation, image
|
||||||
|
from (
|
||||||
|
select owner, exercise, name, solution, creation, image,
|
||||||
|
row_number() over (partition by owner, exercise order by creation desc) as ix
|
||||||
|
from `tabExercise Submission`) as t
|
||||||
|
where t.ix=1 and owner IN {}
|
||||||
|
""".format(names)
|
||||||
|
|
||||||
|
data = frappe.db.sql(sql, values=values, as_dict=True)
|
||||||
|
|
||||||
|
for row in data:
|
||||||
|
row['owner'] = students_map[row['owner']]
|
||||||
|
return data
|
||||||
|
|
||||||
|
def nparams(name, values):
|
||||||
|
"""Creates n paramters from a list of values for a db query.
|
||||||
|
|
||||||
|
>>> nparams("name", ["a", "b])
|
||||||
|
("(%(name_1)s, %(name_2)s)", {"name_1": "a", "name_2": "b"})
|
||||||
|
"""
|
||||||
|
keys = [f"{name}_{i}" for i, _ in enumerate(values, start=1)]
|
||||||
|
param_names = [f"%({k})s" for k in keys]
|
||||||
|
param_values = dict(zip(keys, values))
|
||||||
|
joined_names = "(" + ", ".join(param_names) + ")"
|
||||||
|
return joined_names, param_values
|
||||||
@@ -4,10 +4,11 @@
|
|||||||
{% block head_include %}
|
{% block head_include %}
|
||||||
<meta name="description" content="Courses" />
|
<meta name="description" content="Courses" />
|
||||||
<meta name="keywords" content="" />
|
<meta name="keywords" content="" />
|
||||||
|
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ Sidebar(course, batch_code) }}
|
{{ Sidebar(course, batch) }}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -3,7 +3,6 @@ from community.lms.models import Course
|
|||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
|
|
||||||
course_name = frappe.form_dict["course"]
|
course_name = frappe.form_dict["course"]
|
||||||
batch_name = frappe.form_dict["batch"]
|
batch_name = frappe.form_dict["batch"]
|
||||||
|
|
||||||
43
community/www/batch/utils.py
Normal file
43
community/www/batch/utils.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import frappe
|
||||||
|
from community.lms.models import Course
|
||||||
|
|
||||||
|
def get_common_context(context):
|
||||||
|
context.no_cache = 1
|
||||||
|
|
||||||
|
course_name = frappe.form_dict["course"]
|
||||||
|
batch_name = frappe.form_dict["batch"]
|
||||||
|
|
||||||
|
course = Course.find(course_name)
|
||||||
|
if not course:
|
||||||
|
context.template = "www/404.html"
|
||||||
|
return
|
||||||
|
|
||||||
|
batch = course.get_batch(batch_name)
|
||||||
|
if not batch:
|
||||||
|
frappe.local.flags.redirect_location = "/courses/" + course_name
|
||||||
|
raise frappe.Redirect
|
||||||
|
|
||||||
|
context.course = course
|
||||||
|
context.batch = batch
|
||||||
|
context.livecode_url = get_livecode_url()
|
||||||
|
|
||||||
|
def get_livecode_url():
|
||||||
|
return frappe.db.get_single_value("LMS Settings", "livecode_url")
|
||||||
|
|
||||||
|
def get_batch_members(batch_name):
|
||||||
|
members = []
|
||||||
|
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch_name}, ["member", "member_type"])
|
||||||
|
|
||||||
|
for membership in memberships:
|
||||||
|
member = get_member_with_name(membership.member)
|
||||||
|
if membership.member_type == "Mentor":
|
||||||
|
member.is_mentor = True
|
||||||
|
members.append(member)
|
||||||
|
return members
|
||||||
|
|
||||||
|
def get_member_with_name(name):
|
||||||
|
try:
|
||||||
|
return frappe.get_doc("Community Member", name)
|
||||||
|
except frappe.DoesNotExistError:
|
||||||
|
return
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import frappe
|
|
||||||
from community.lms.models import Course
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
|
|
||||||
course_name = frappe.form_dict["course"]
|
|
||||||
batch_name = frappe.form_dict["batch"]
|
|
||||||
|
|
||||||
course = Course.find(course_name)
|
|
||||||
if not course:
|
|
||||||
context.template = "www/404.html"
|
|
||||||
return
|
|
||||||
|
|
||||||
batch = course.get_batch(batch_name)
|
|
||||||
if not batch:
|
|
||||||
frappe.local.flags.redirect_location = "/courses/" + course_name
|
|
||||||
raise frappe.Redirect
|
|
||||||
|
|
||||||
context.course = course
|
|
||||||
context.batch = batch
|
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
<h2>Course Description</h2>
|
<h2>Course Description</h2>
|
||||||
|
|
||||||
<div class="course-description">
|
<div class="course-description">
|
||||||
{{ course.short_introduction }}
|
{{ frappe.utils.md_to_html(course.description) }}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
@@ -88,7 +88,8 @@
|
|||||||
{% if can_manage %}
|
{% if can_manage %}
|
||||||
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button class="join-batch" data-batch="{{ batch.name | urlencode }}">Join this Batch</button>
|
<button class="join-batch" data-batch="{{ batch.name | urlencode }}"
|
||||||
|
data-course="{{ course.name | urlencode }}">Join this Batch</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -99,7 +100,7 @@
|
|||||||
<h2>Your Batches</h2>
|
<h2>Your Batches</h2>
|
||||||
|
|
||||||
{% if mentor_batches %}
|
{% if mentor_batches %}
|
||||||
<div class="message">
|
<div class="alert alert-secondary">
|
||||||
You are a mentor for this course. Manage your batches or create a new batch from here.
|
You are a mentor for this course. Manage your batches or create a new batch from here.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -111,11 +112,11 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}">Add a new batch</a>
|
<a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}">Add a new batch</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="mentor_message">
|
<div class="mentor_message">
|
||||||
<p> You are a mentor for this course. </p>
|
<p> You are a mentor for this course. </p>
|
||||||
<a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.title}}" >Create your first batch</a>
|
<a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.title}}&slug={{course.name}}" >Create your first batch</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ frappe.ready(() => {
|
|||||||
course: decodeURIComponent($("#course-title").attr("data-course")),
|
course: decodeURIComponent($("#course-title").attr("data-course")),
|
||||||
},
|
},
|
||||||
'callback': (data) => {
|
'callback': (data) => {
|
||||||
if (data.message) {
|
if (data.message > 0) {
|
||||||
$("#mentor-request").addClass("hide");
|
$("#mentor-request").addClass("hide");
|
||||||
$("#already-applied").removeClass("hide")
|
$("#already-applied").removeClass("hide")
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ frappe.ready(() => {
|
|||||||
$("#apply-now").click((e) => {
|
$("#apply-now").click((e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (frappe.session.user == "Guest") {
|
if (frappe.session.user == "Guest") {
|
||||||
window.location.href = "/login";
|
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@@ -53,7 +53,7 @@ frappe.ready(() => {
|
|||||||
$(".join-batch").click((e) => {
|
$(".join-batch").click((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (frappe.session.user == "Guest") {
|
if (frappe.session.user == "Guest") {
|
||||||
window.location.href = "/login";
|
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
|
||||||
@@ -70,4 +70,3 @@ frappe.ready(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -19,3 +19,8 @@ def get_context(context):
|
|||||||
|
|
||||||
context.course = course
|
context.course = course
|
||||||
|
|
||||||
|
batch = course.get_student_batch(frappe.session.user)
|
||||||
|
if batch:
|
||||||
|
frappe.local.flags.redirect_location = f"/courses/{course.name}/{batch.name}/learn"
|
||||||
|
raise frappe.Redirect
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import frappe
|
|
||||||
from community.www.courses.utils import redirect_if_not_a_member, get_course, get_batch_members, get_batch
|
|
||||||
from community.lms.doctype.lms_batch.lms_batch import get_messages
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
context.course_slug = frappe.form_dict["course"]
|
|
||||||
context.course = get_course(context.course_slug)
|
|
||||||
context.batch_code = frappe.form_dict["batch"]
|
|
||||||
redirect_if_not_a_member(context.course_slug, context.batch_code)
|
|
||||||
|
|
||||||
context.batch = get_batch(context.batch_code)
|
|
||||||
context.members = get_batch_members(context.batch.name)
|
|
||||||
context.member_count = len(context.members)
|
|
||||||
context.messages = get_messages(context.batch.name)
|
|
||||||
@@ -7,6 +7,6 @@ def get_context(context):
|
|||||||
def get_courses():
|
def get_courses():
|
||||||
courses = frappe.get_all(
|
courses = frappe.get_all(
|
||||||
"LMS Course",
|
"LMS Course",
|
||||||
fields=['name', 'slug', 'title', 'description']
|
fields=['name', 'title', 'description']
|
||||||
)
|
)
|
||||||
return courses
|
return courses
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
{% extends "templates/base.html" %}
|
|
||||||
{% from "www/macros/sidebar.html" import Sidebar %}
|
|
||||||
{% block title %}Learn{% endblock %}
|
|
||||||
{% block head_include %}
|
|
||||||
<meta name="description" content="Courses" />
|
|
||||||
<meta name="keywords" content="" />
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
{{ Sidebar(course.name, batch.name) }}
|
|
||||||
<div class="container">
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import frappe
|
|
||||||
from community.www.courses.utils import redirect_if_not_a_member, get_batch, get_member_with_name, get_course, get_batch_members
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
context.course_slug = frappe.form_dict["course"]
|
|
||||||
context.course = get_course(context.course_slug)
|
|
||||||
context.batch_code = frappe.form_dict["batch"]
|
|
||||||
redirect_if_not_a_member(context.course_slug, context.batch_code)
|
|
||||||
context.batch = get_batch(context.batch_code)
|
|
||||||
context.members = get_batch_members(context.batch.name)
|
|
||||||
context.member_count = len(context.members)
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import frappe
|
|
||||||
from community.www.courses.utils import redirect_if_not_a_member
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
context.course = frappe.form_dict["course"]
|
|
||||||
context.batch_code = frappe.form_dict["batch"]
|
|
||||||
redirect_if_not_a_member(context.course, context.batch_code)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import frappe
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
context.no_cache = 1
|
|
||||||
|
|
||||||
try:
|
|
||||||
course_slug = frappe.form_dict['course']
|
|
||||||
topic_slug = frappe.form_dict['topic']
|
|
||||||
except KeyError:
|
|
||||||
context.template = 'www/404.html'
|
|
||||||
return
|
|
||||||
|
|
||||||
course = get_course(course_slug)
|
|
||||||
topic = course and course.get_topic(topic_slug)
|
|
||||||
|
|
||||||
if not topic:
|
|
||||||
context.template = 'www/404.html'
|
|
||||||
return
|
|
||||||
|
|
||||||
context.course = course
|
|
||||||
context.topic = topic
|
|
||||||
context.livecode_url = get_livecode_url()
|
|
||||||
|
|
||||||
def notfound(context):
|
|
||||||
context.template = 'www/404.html'
|
|
||||||
|
|
||||||
def get_livecode_url():
|
|
||||||
doc = frappe.get_doc("LMS Settings")
|
|
||||||
return doc.livecode_url
|
|
||||||
|
|
||||||
def get_course(slug):
|
|
||||||
course = frappe.db.get_value('LMS Course', {"slug": slug}, ["name"], as_dict=1)
|
|
||||||
return course and frappe.get_doc('LMS Course', course['name'])
|
|
||||||
@@ -1,66 +1,128 @@
|
|||||||
|
|
||||||
{% macro LiveCodeEditorLarge(name, code) %}
|
{% macro LiveCodeEditorLarge(name, code) %}
|
||||||
<div class="livecode-editor livecode-editor-large row no-gutters" id="editor-{{name}}">
|
<div class="livecode-editor livecode-editor-large" id="editor-{{name}}">
|
||||||
<div class="col-sm">
|
<div class="row">
|
||||||
<div class="heading">
|
<div class="col-lg-8 col-md-6">
|
||||||
<button class="run">Run</button>
|
<div class="controls">
|
||||||
<h2>Editor</h2>
|
<button class="run">Run</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea class="code">{{code}}</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm">
|
<div class="code-editor">
|
||||||
<div class="heading">
|
<div class="row">
|
||||||
<h2>Output</h2>
|
<div class="col-lg-8 col-md-6">
|
||||||
</div>
|
<div class="code-wrapper">
|
||||||
<div class="canvas-wrapper">
|
<textarea class="code">{{code}}</textarea>
|
||||||
<canvas class="canvas" width="300" height="300"></canvas>
|
</div>
|
||||||
<pre class="output"></pre>
|
</div>
|
||||||
|
<div class="col-lg-4 col-md-6 canvas-wrapper">
|
||||||
|
<canvas width="300" height="300"></canvas>
|
||||||
|
<pre class="output"></pre>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro LiveCodeEditor(name, code) %}
|
{% macro LiveCodeEditor(name, code, reset_code, is_exercise=False, last_submitted=None) %}
|
||||||
<div class="livecode-editor canvas-editor" id="editor-{{name}}"
|
<div class="livecode-editor livecode-editor-inline" id="editor-{{name}}">
|
||||||
data-section="{{name}}">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-9">
|
<div class="col-lg-8 col-md-6">
|
||||||
<div>
|
<div class="controls">
|
||||||
<textarea class="code">{{code}}</textarea>
|
<button class="run">Run</button>
|
||||||
<div class="livecode-controls">
|
<button class="reset">Reset</button>
|
||||||
<button type="button" class="run">Run</button>
|
{% if is_exercise %}
|
||||||
<a href="javascript:;" class="reset">Reset</a>
|
<button class="submit pull-right btn-primary">Submit</button>
|
||||||
<a href="javascript:;" class="clear">Clear</a>
|
{% if last_submitted %}
|
||||||
|
<span class="pull-right" style="padding-right: 10px;"><span class="human-time" data-timestamp="{{last_submitted}}"></span></span>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div style="display: none">
|
||||||
|
<pre class="reset-code">{{reset_code}}</pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3">
|
<div class="code-editor">
|
||||||
<div class="canvas-wrapper">
|
<div class="row">
|
||||||
<canvas class="canvas" width="150" height="150"></canvas>
|
<div class="col-lg-8 col-md-6">
|
||||||
<pre class="output"></pre>
|
<div class="code-wrapper">
|
||||||
|
<textarea class="code">{{code}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4 col-md-6 canvas-wrapper">
|
||||||
|
<canvas width="300" height="300"></canvas>
|
||||||
|
<pre class="output"></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% macro LiveCodeEditorJS(name, code) %}
|
{% macro LiveCodeEditorJS(name, code) %}
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/assets/frappe/node_modules/moment/min/moment-with-locales.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/assets/frappe/node_modules/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
|
||||||
|
<script type="text/javascript" src="/assets/frappe/js/frappe/utils/datetime.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
// comment_when is failing because of this
|
||||||
|
if (!frappe.sys_defaults) {
|
||||||
|
frappe.sys_defaults = {}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
|
<script type="text/javascript" src="{{ livecode_url }}/static/livecode.js"></script>
|
||||||
|
<script type="text/javascript" src="/assets/community/js/livecode-canvas.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var livecodeEditors = [];
|
var livecodeEditors = [];
|
||||||
|
var livecodeEditorsMap = {};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$(".livecode-editor").each((i, e) => {
|
$(".livecode-editor").each((i, e) => {
|
||||||
|
var name = e.id.replace("editor-", "");
|
||||||
var editor = new LiveCodeEditor(e, {
|
var editor = new LiveCodeEditor(e, {
|
||||||
runtime: "python-canvas",
|
|
||||||
base_url: "{{ livecode_url }}",
|
base_url: "{{ livecode_url }}",
|
||||||
codemirror: true
|
...getLiveCodeOptions()
|
||||||
})
|
})
|
||||||
livecodeEditors.push(editor);
|
livecodeEditors.push(editor);
|
||||||
})
|
livecodeEditorsMap[e.id] = editor;
|
||||||
})
|
|
||||||
|
$(e).find(".reset").on('click', function() {
|
||||||
|
let code = $(e).find(".reset-code").html();
|
||||||
|
editor.codemirror.doc.setValue(code);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(e).find(".submit").on('click', function() {
|
||||||
|
let code = editor.codemirror.doc.getValue();
|
||||||
|
console.log("submit", name, code);
|
||||||
|
frappe.call("community.lms.api.submit_solution", {
|
||||||
|
"exercise": name,
|
||||||
|
"code": code
|
||||||
|
}).then(r => {
|
||||||
|
if (r.message.name) {
|
||||||
|
frappe.msgprint("Submitted successfully!");
|
||||||
|
|
||||||
|
let d = r.message.creation;
|
||||||
|
$(e).find(".human-time").html(__("Submitted {0}", [comment_when(d)]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateSubmitTimes() {
|
||||||
|
$(".human-time").each(function(i, e) {
|
||||||
|
var d = $(e).data().timestamp;
|
||||||
|
$(e).html(__("Submitted {0}", [comment_when(d)]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubmitTimes();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
{% macro Sidebar(course, batch_code) %}
|
{% macro Sidebar(course, batch, is_mentor=False) %}
|
||||||
<div class="sidebar-batch">
|
<div class="sidebar-batch">
|
||||||
<a href=""><i class="fas fa-bars fa-lg"></i></a>
|
<a href=""><i class="fa fa-bars fa-lg"></i></a>
|
||||||
<br>
|
<br>
|
||||||
<a href="/courses/{{course}}/{{batch_code}}/learn"><i class="fas fa-book fa-lg"></i></a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/learn"><i class="fa fa-book fa-lg"></i></a>
|
||||||
<a href="/courses/{{course}}/{{batch_code}}/schedule"><i class="fas fa-calendar-alt fa-lg"></i></a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/schedule"><i class="fa fa-calendar fa-lg"></i></a>
|
||||||
<a href="/courses/{{course}}/{{batch_code}}/members"><i class="fas fa-users fa-lg"></i></a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/members"><i class="fa fa-users fa-lg"></i></a>
|
||||||
<a href="/courses/{{course}}/{{batch_code}}/discuss"><i class="fas fa-comments fa-lg"></i></a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/discuss"><i class="fa fa-comments fa-lg"></i></a>
|
||||||
<a href="/courses/{{course}}/{{batch_code}}/about"><i class="fas fa-info-circle fa-lg"></i></a>
|
<a href="/courses/{{course.name}}/{{batch.name}}/about"><i class="fa fa-info-circle fa-lg"></i></a>
|
||||||
<!-- <a href="#contact"><i class="fas fa-home fa-lg"></i></a> -->
|
{% if batch.is_member(frappe.session.user, member_type="Mentor") %}
|
||||||
|
<a href="/courses/{{course.name}}/{{batch.name}}/progress"><i class="fa fa-flag-checkered fa-lg"></i></a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -55,7 +55,6 @@
|
|||||||
|
|
||||||
.dashboard__details {
|
.dashboard__details {
|
||||||
padding-top: 2rem;
|
padding-top: 2rem;
|
||||||
width: 80%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.dashboard__course {
|
.dashboard__course {
|
||||||
@@ -83,12 +82,18 @@
|
|||||||
.dashboard__description {
|
.dashboard__description {
|
||||||
height: 100px;
|
height: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.dashboard__parent {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
<section>
|
|
||||||
<div class="dashboard__parent">
|
<div class="dashboard__parent">
|
||||||
<div>
|
<div class="dashboard__photo">
|
||||||
{{ Profile(member.photo, member.full_name, member.abbr, "large")}}
|
{{ Profile(member.photo, member.full_name, member.abbr, "large")}}
|
||||||
</div>
|
</div>
|
||||||
<div class="dashboard__details">
|
<div class="dashboard__details">
|
||||||
@@ -106,40 +111,23 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane fade py-4 show active" role="tabpanel" id="home">
|
<div class="tab-pane fade py-4 show active" role="tabpanel" id="home">
|
||||||
<div class='container'>
|
<div class="row">
|
||||||
<div class="row row-cols-1 row-cols-xl-5 row-cols-lg-4 row-cols-md-3 row-cols-sm-2">
|
{% if sketches %}
|
||||||
{% if sketches %}
|
{% for sketch in sketches %}
|
||||||
{% for sketch in sketches %}
|
<div class="col-md-4 col-sm-6">
|
||||||
<div class="col m-4">
|
{{ widgets.SketchTeaser(sketch=sketch) }}
|
||||||
<div class="card sketch-card" style="width: 200px;">
|
|
||||||
<div class="card-img-top">
|
|
||||||
<a href="/sketches/{{sketch.sketch_id}}">
|
|
||||||
{{ sketch.to_svg() }}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="card-footer">
|
|
||||||
<div class="sketch-title">
|
|
||||||
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
|
|
||||||
</div>
|
|
||||||
<div class="sketch-author">
|
|
||||||
by {{sketch.get_owner_name()}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% if not sketches %}
|
{% endfor %}
|
||||||
<p class="text-center">{{member.full_name}} has not created any skecth yet.</p>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% if not sketches %}
|
||||||
|
<p class="text-center">{{member.full_name}} has not created any skecth yet.</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<!-- this is a sample default web page template -->
|
<!-- this is a sample default web page template -->
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<div class='container pb-5'>
|
<div class='container pb-5'>
|
||||||
<h1>Recent Sketches</h1>
|
<h1>Recent Sketches</h1>
|
||||||
|
|
||||||
<a href="/sketches/new">Create a New Sketch</a>
|
<a href="/sketches/new" class="btn btn-primary">Create a New Sketch</a>
|
||||||
</div>
|
</div>
|
||||||
<div class='container'>
|
<div class='container'>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -30,14 +30,18 @@
|
|||||||
|
|
||||||
<div class="sketch-header">
|
<div class="sketch-header">
|
||||||
{% if editable %}
|
{% if editable %}
|
||||||
<input type="button" class="pull-right" id="sketch-save" value="Save"/>
|
<div class="form-row">
|
||||||
<h1 class="sketch-title">
|
<div class="col-lg-8 col-md-6">
|
||||||
<input type="text" name="title" id="sketch-title" value="{{ sketch.title }}" />
|
<input type="text" id="sketch-title" name="title" class="form-control" value="{{ sketch.title }}">
|
||||||
</h1>
|
</div>
|
||||||
|
<div class="col-lg-4 col-md-6">
|
||||||
|
<button type="submit" id="sketch-save" class="btn-save btn btn-primary">Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h1 class="sketch-title">{{sketch.title}}</h1>
|
<h1 class="sketch-title">{{sketch.title}}</h1>
|
||||||
|
<div class="sketch-owner-wrapper">By <span class="sketch-owner">{{sketch.get_owner_name()}}</span></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="sketch-owner-wrapper">By <span class="sketch-owner">{{sketch.get_owner_name()}}</span></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if sketch.is_new() and not editable %}
|
{% if sketch.is_new() and not editable %}
|
||||||
@@ -49,7 +53,6 @@
|
|||||||
<div class="sketch-editor">
|
<div class="sketch-editor">
|
||||||
{{LiveCodeEditorLarge(sketch.name, sketch.code) }}
|
{{LiveCodeEditorLarge(sketch.name, sketch.code) }}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
|
|||||||
Reference in New Issue
Block a user