Compare commits
264 Commits
invite-flo
...
minor-issu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4079ed97b9 | ||
|
|
ce86b5deda | ||
|
|
037e946bbe | ||
|
|
a51c8de1eb | ||
|
|
53dc517180 | ||
|
|
44ca940c6b | ||
|
|
c0b688c720 | ||
|
|
861d5f231d | ||
|
|
d14b4f55a6 | ||
|
|
db9a6c3eda | ||
|
|
a667643681 | ||
|
|
f278e4b6a5 | ||
|
|
33a12c2dec | ||
|
|
508f90f459 | ||
|
|
709f0c2274 | ||
|
|
be47700e7c | ||
|
|
40842830a4 | ||
|
|
11d070fa0d | ||
|
|
dd2f830a33 | ||
|
|
5431fcb450 | ||
|
|
324033e9ee | ||
|
|
86596d0cfe | ||
|
|
9323cfd748 | ||
|
|
d125b02cec | ||
|
|
282c4c5351 | ||
|
|
276d64a66a | ||
|
|
79eb381a41 | ||
|
|
44f9c0dfd3 | ||
|
|
0ca4cd724e | ||
|
|
8a3e31f021 | ||
|
|
9be8a1af0b | ||
|
|
b9cac20613 | ||
|
|
e6d5e6d37b | ||
|
|
0abfcac7da | ||
|
|
b70e8b9acc | ||
|
|
3b1e1aa3c3 | ||
|
|
8f74c74d50 | ||
|
|
d2f435016c | ||
|
|
389b35802b | ||
|
|
a9192a74f9 | ||
|
|
1366c7cf75 | ||
|
|
eaa9e8e3ea | ||
|
|
5ecae0df61 | ||
|
|
4891be1d8c | ||
|
|
ec852fc255 | ||
|
|
47f2d3cb7b | ||
|
|
37820c1e19 | ||
|
|
230fab3bb2 | ||
|
|
d292d2d093 | ||
|
|
51d5db01e9 | ||
|
|
0fd760df81 | ||
|
|
71d0a89968 | ||
|
|
d939a63412 | ||
|
|
daaa2d2fe2 | ||
|
|
6dd7cb19df | ||
|
|
b1de2481a8 | ||
|
|
27c01b3b0c | ||
|
|
b7aa9aff51 | ||
|
|
524a041fb9 | ||
|
|
9de0203914 | ||
|
|
0ed5309b97 | ||
|
|
68fd32d536 | ||
|
|
5ea3b25d21 | ||
|
|
2c24412633 | ||
|
|
1b8a45ba4a | ||
|
|
3dd4adbc1f | ||
|
|
0c52c9c4bc | ||
|
|
9caf44cdbd | ||
|
|
45d88bdc08 | ||
|
|
94b3ccd3d9 | ||
|
|
ee8273fd30 | ||
|
|
60c1449f40 | ||
|
|
67708325ae | ||
|
|
3e99577401 | ||
|
|
5e916dc2c8 | ||
|
|
0c64d46e99 | ||
|
|
3aa974f8bd | ||
|
|
621d01d502 | ||
|
|
aa20136223 | ||
|
|
9bc5408a44 | ||
|
|
5a7afb3092 | ||
|
|
f8948ac2ef | ||
|
|
8b1576a028 | ||
|
|
56d8a72a7d | ||
|
|
f6c11ce52f | ||
|
|
0284c9305c | ||
|
|
d785fb7562 | ||
|
|
9f50af4ebd | ||
|
|
4c3645f0d4 | ||
|
|
20b3ae7d76 | ||
|
|
f303be4db5 | ||
|
|
fc1c393f15 | ||
|
|
5d96bf544d | ||
|
|
5abfa35095 | ||
|
|
6c751cdf39 | ||
|
|
2c570ea214 | ||
|
|
ecfcc8a2f7 | ||
|
|
3384f974e5 | ||
|
|
eb435261fe | ||
|
|
dc7eabefb9 | ||
|
|
fed4b5568b | ||
|
|
aa77c60abd | ||
|
|
9c1506d3c8 | ||
|
|
e94c3f27ab | ||
|
|
5fa8bdd40c | ||
|
|
17f03aeee7 | ||
|
|
7840512a13 | ||
|
|
526ded784b | ||
|
|
6b5ddcd54a | ||
|
|
c42247db42 | ||
|
|
8f8d4901ff | ||
|
|
f5f3c808d4 | ||
|
|
1e3152e303 | ||
|
|
344661cf83 | ||
|
|
d9185c0b6b | ||
|
|
5363fb7eb3 | ||
|
|
1cb81de5c0 | ||
|
|
d90a1247f1 | ||
|
|
ef0c3e4a24 | ||
|
|
3619b136f8 | ||
|
|
671b4a0650 | ||
|
|
586b39c0fd | ||
|
|
4fd7af053b | ||
|
|
5fd1143f76 | ||
|
|
0dc4743556 | ||
|
|
c96a14c972 | ||
|
|
400e706be1 | ||
|
|
a12a52747e | ||
|
|
b9a93bb160 | ||
|
|
9c65ff8ae6 | ||
|
|
bb0aa09b4e | ||
|
|
a8752afb3b | ||
|
|
327bde870b | ||
|
|
640ead4922 | ||
|
|
687f7f7f7b | ||
|
|
527a563e4a | ||
|
|
5bc9a7fe37 | ||
|
|
24835acd9c | ||
|
|
3648b3ab47 | ||
|
|
914f8504a0 | ||
|
|
ab8546a121 | ||
|
|
f327c6fb10 | ||
|
|
c7ccefa632 | ||
|
|
823cf4e431 | ||
|
|
18f074d8ac | ||
|
|
c9185ae68c | ||
|
|
82fa0fa4d7 | ||
|
|
64752433d2 | ||
|
|
50856fdfa5 | ||
|
|
cac4f2afef | ||
|
|
df431165e8 | ||
|
|
69125e571f | ||
|
|
68f7215b95 | ||
|
|
ca42c32f54 | ||
|
|
20adc8079e | ||
|
|
d55941d4bb | ||
|
|
6074ee3688 | ||
|
|
b3f87ba5b6 | ||
|
|
631275e9a8 | ||
|
|
8d7963fc60 | ||
|
|
38938ac14b | ||
|
|
14f9d4875a | ||
|
|
419a7e666f | ||
|
|
713dcf178a | ||
|
|
637c795321 | ||
|
|
63d00a46c4 | ||
|
|
e991dc5c73 | ||
|
|
4a2ecff15d | ||
|
|
f8d6b5b949 | ||
|
|
c77835b81f | ||
|
|
e04bbb633d | ||
|
|
a2b856aaf8 | ||
|
|
7a650b46ac | ||
|
|
b61ca1d7a2 | ||
|
|
573019bbcc | ||
|
|
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 | ||
|
|
343aa50f78 | ||
|
|
5a70687067 | ||
|
|
a0921f7380 | ||
|
|
11cc03849d | ||
|
|
413aeaccb1 | ||
|
|
88457a82ac | ||
|
|
761f36519e | ||
|
|
dc5b637ada | ||
|
|
5e5395658e | ||
|
|
69b3f366f4 | ||
|
|
da902d23f7 | ||
|
|
c2be23a902 | ||
|
|
da771d7830 | ||
|
|
8a242a69fb | ||
|
|
041bed7e9d | ||
|
|
e330f45adc | ||
|
|
370d3a321b | ||
|
|
138fba66ae | ||
|
|
82faaed15d | ||
|
|
b58a685e7a | ||
|
|
45ec16d9e4 | ||
|
|
18c0fb0da5 | ||
|
|
b7d93c1b50 | ||
|
|
e931ead270 | ||
|
|
8933ca9ac9 | ||
|
|
1a06e2c0aa | ||
|
|
491b5c46ae | ||
|
|
2139bddf01 | ||
|
|
cf68d3127c | ||
|
|
f13bb494ef | ||
|
|
5e18cd2ef4 | ||
|
|
0144ab60de | ||
|
|
b9d94df4d8 | ||
|
|
9e103af8b5 | ||
|
|
5728714d71 | ||
|
|
62cfc0fb24 | ||
|
|
a52a01ef7f | ||
|
|
67d3ec75c8 |
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
26
.github/workflows/ci.yml
vendored
26
.github/workflows/ci.yml
vendored
@@ -36,12 +36,27 @@ jobs:
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '12'
|
||||
node-version: '14'
|
||||
check-latest: true
|
||||
- name: setup cache for bench
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/bench-cache
|
||||
key: ${{ runner.os }}
|
||||
- name: install bench
|
||||
run: pip3 install frappe-bench
|
||||
run: |
|
||||
pip3 install frappe-bench
|
||||
which bench
|
||||
- name: bench init
|
||||
run: bench init ~/frappe-bench --skip-redis-config-generation
|
||||
run: |
|
||||
if [ -d ~/bench-cache/bench.tgz ]
|
||||
then
|
||||
(cd && tar xzf ~/bench-cache/bench.tgz)
|
||||
else
|
||||
bench init ~/frappe-bench --skip-redis-config-generation
|
||||
mkdir -p ~/bench-cache
|
||||
(cd && tar czf ~/bench-cache/bench.tgz frappe-bench)
|
||||
fi
|
||||
- name: add community app to bench
|
||||
working-directory: /home/runner/frappe-bench
|
||||
run: bench get-app community $GITHUB_WORKSPACE
|
||||
@@ -50,10 +65,13 @@ jobs:
|
||||
run: bench new-site --mariadb-root-password root --admin-password admin frappe.local
|
||||
- name: install community app
|
||||
working-directory: /home/runner/frappe-bench
|
||||
run: bench --site frappe.local install-app community
|
||||
run: bench --verbose --site frappe.local install-app community
|
||||
- name: allow tests
|
||||
working-directory: /home/runner/frappe-bench
|
||||
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
|
||||
working-directory: /home/runner/frappe-bench
|
||||
run: bench --site frappe.local run-tests --app community
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,4 +3,8 @@
|
||||
*.egg-info
|
||||
*.swp
|
||||
tags
|
||||
community/docs/current
|
||||
community/docs/current
|
||||
community/public/dist
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright (c) 2021, Frappe and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Community Course Member', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -1,96 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "field:user_name",
|
||||
"creation": "2021-03-02 11:24:49.612530",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"enabled",
|
||||
"full_name",
|
||||
"user_name",
|
||||
"email",
|
||||
"short_intro",
|
||||
"bio",
|
||||
"photo",
|
||||
"route"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "enabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"fieldname": "full_name",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Full Name",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "user_name",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "User Name",
|
||||
"reqd": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "email",
|
||||
"fieldtype": "Data",
|
||||
"label": "Email",
|
||||
"options": "Email",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "short_intro",
|
||||
"fieldtype": "Data",
|
||||
"label": "Short Intro"
|
||||
},
|
||||
{
|
||||
"fieldname": "bio",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Bio"
|
||||
},
|
||||
{
|
||||
"fieldname": "photo",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Photo"
|
||||
},
|
||||
{
|
||||
"fieldname": "route",
|
||||
"fieldtype": "Data",
|
||||
"label": "Route"
|
||||
}
|
||||
],
|
||||
"has_web_view": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_published_field": "enabled",
|
||||
"links": [],
|
||||
"modified": "2021-04-06 11:50:41.551665",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Community",
|
||||
"name": "Community Course Member",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"route": "community-course-member",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, Frappe and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import re
|
||||
from frappe.website.website_generator import WebsiteGenerator
|
||||
from frappe import _
|
||||
|
||||
class CommunityCourseMember(WebsiteGenerator):
|
||||
|
||||
def get_context(self, context):
|
||||
context.abbr = ("").join([ s[0] for s in self.full_name.split() ])
|
||||
return context
|
||||
|
||||
def validate(self):
|
||||
self.validate_user_name()
|
||||
if not self.route:
|
||||
self.route = self.user_name
|
||||
|
||||
def validate_user_name(self):
|
||||
if len(self.user_name) < 4:
|
||||
frappe.throw(_("Username must be atleast 4 characters long."))
|
||||
if not re.match("^[A-Za-z0-9_]*$", self.user_name):
|
||||
frappe.throw(_("Username can only contain alphabets, numbers, and underscore."))
|
||||
self.user_name = self.user_name.lower()
|
||||
|
||||
def after_insert(self):
|
||||
if frappe.db.exists("User", self.email):
|
||||
user = frappe.get_doc("User", self.email)
|
||||
else:
|
||||
user, update_password_link = self.create_user()
|
||||
self.send_email(update_password_link)
|
||||
|
||||
def send_email(self, update_password_link):
|
||||
|
||||
args = {
|
||||
'update_password_link': update_password_link,
|
||||
'full_name': self.full_name,
|
||||
}
|
||||
|
||||
frappe.sendmail(
|
||||
recipients=self.email,
|
||||
sender="Administrator",
|
||||
subject=_("Set your Password"),
|
||||
template="community_course_membership",
|
||||
reference_doctype=self.doctype,
|
||||
reference_name=self.name,
|
||||
send_priority=0,
|
||||
queue_separately=True,
|
||||
args=args)
|
||||
@@ -1,25 +0,0 @@
|
||||
{% extends "templates/web.html" %}
|
||||
{% block page_content %}
|
||||
<div class="py-20 row">
|
||||
{% if photo %}
|
||||
<div class="col-sm-2 border border-dark">
|
||||
<img src="{{ photo }}" alt="{{ full_name }}">
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col-sm-2">
|
||||
<div class="standard-image" style="font-size: 30px;">{{ abbr }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col">
|
||||
<h1>{{ full_name }}</h1>
|
||||
{% if short_intro %}
|
||||
<p class="lead"> {{ short_intro }} </p>
|
||||
{% endif %}
|
||||
{% if bio %}
|
||||
<p class="markdown-style"> {{ frappe.utils.md_to_html(bio) }} </p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
<!-- this is a sample default web page template -->
|
||||
@@ -1,4 +0,0 @@
|
||||
<div>
|
||||
<a href="{{ doc.route }}">{{ doc.full_name }}</a>
|
||||
</div>
|
||||
<!-- this is a sample default list template -->
|
||||
@@ -1,10 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, Frappe and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCommunityCourseMember(unittest.TestCase):
|
||||
pass
|
||||
@@ -13,13 +13,13 @@
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Member",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-02-15 12:03:31.153575",
|
||||
"modified": "2021-05-21 12:15:51.286478",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Community",
|
||||
"name": "Community Event Volunteer",
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// Copyright (c) 2021, Frappe and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Community Member', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -1,155 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_guest_to_view": 1,
|
||||
"allow_rename": 1,
|
||||
"creation": "2021-02-12 15:47:23.591567",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"full_name",
|
||||
"email",
|
||||
"enabled",
|
||||
"column_break_4",
|
||||
"username",
|
||||
"email_preference",
|
||||
"section_break_7",
|
||||
"bio",
|
||||
"section_break_9",
|
||||
"role",
|
||||
"photo",
|
||||
"column_break_12",
|
||||
"short_intro",
|
||||
"route",
|
||||
"abbr"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "enabled",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"fieldname": "full_name",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Full Name",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 1,
|
||||
"fieldname": "role",
|
||||
"fieldtype": "Select",
|
||||
"label": "Role",
|
||||
"options": "\nBoard\nDirector\nVolunteer\nSpeaker"
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 1,
|
||||
"fieldname": "photo",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Photo"
|
||||
},
|
||||
{
|
||||
"fieldname": "short_intro",
|
||||
"fieldtype": "Data",
|
||||
"label": "Short Intro"
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 1,
|
||||
"fieldname": "bio",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Bio"
|
||||
},
|
||||
{
|
||||
"fieldname": "route",
|
||||
"fieldtype": "Data",
|
||||
"label": "Route"
|
||||
},
|
||||
{
|
||||
"fieldname": "email",
|
||||
"fieldtype": "Data",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Email",
|
||||
"options": "Email",
|
||||
"reqd": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 1,
|
||||
"fieldname": "username",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "User Name",
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "email_preference",
|
||||
"fieldtype": "Select",
|
||||
"label": "Email preference",
|
||||
"options": "Email on every Message\nOne Digest Mail per day\nNever"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_7",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_9",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "abbr",
|
||||
"fieldtype": "Data",
|
||||
"label": "Abbr",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-28 11:22:35.402217",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Community",
|
||||
"name": "Community Member",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Website Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"search_fields": "full_name",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "full_name",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, Frappe and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import re
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
import random
|
||||
|
||||
class CommunityMember(Document):
|
||||
|
||||
def validate(self):
|
||||
self.validate_username()
|
||||
self.abbr = ("").join([ s[0] for s in self.full_name.split() ])
|
||||
if self.route != self.username:
|
||||
self.route = self.username
|
||||
|
||||
def validate_username(self):
|
||||
if not self.username:
|
||||
self.username = create_username_from_email(self.email)
|
||||
|
||||
if self.username:
|
||||
if len(self.username) < 4:
|
||||
frappe.throw(_("Username must be atleast 4 characters long."))
|
||||
if not re.match("^[A-Za-z0-9_]*$", self.username):
|
||||
frappe.throw(_("Username can only contain alphabets, numbers and underscore."))
|
||||
self.username = self.username.lower()
|
||||
|
||||
def __repr__(self):
|
||||
return f"<CommunityMember: {self.email}>"
|
||||
|
||||
def create_member_from_user(doc, method):
|
||||
username = doc.username
|
||||
|
||||
if ( doc.username and username_exists(doc.username)) or not doc.username:
|
||||
username = create_username_from_email(doc.email)
|
||||
|
||||
elif len(doc.username) < 4:
|
||||
username = adjust_username(doc.username)
|
||||
|
||||
if username_exists(username):
|
||||
username = username + str(random.randint(0,9))
|
||||
|
||||
member = frappe.get_doc({
|
||||
"doctype": "Community Member",
|
||||
"full_name": doc.full_name,
|
||||
"username": username,
|
||||
"email": doc.email,
|
||||
"route": doc.username,
|
||||
"owner": doc.email
|
||||
})
|
||||
member.save(ignore_permissions=True)
|
||||
|
||||
def username_exists(username):
|
||||
return frappe.db.exists("Community Member", dict(username=username))
|
||||
|
||||
def create_username_from_email(email):
|
||||
string = email.split("@")[0]
|
||||
return ''.join(e for e in string if e.isalnum())
|
||||
|
||||
def adjust_username(username):
|
||||
return username.ljust(4, str(random.randint(0,9)))
|
||||
@@ -1,25 +0,0 @@
|
||||
{% extends "templates/web.html" %}
|
||||
{% block page_content %}
|
||||
<div class="py-20 row">
|
||||
{% if photo %}
|
||||
<div class="col-sm-2 border border-dark">
|
||||
<img src="{{ photo }}" alt="{{ full_name }}">
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="col-sm-2">
|
||||
<div class="standard-image" style="font-size: 30px;">{{ abbr }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col">
|
||||
<h1>{{ full_name }}</h1>
|
||||
{% if short_intro %}
|
||||
<p class="lead"> {{ short_intro }} </p>
|
||||
{% endif %}
|
||||
{% if bio %}
|
||||
<p class="markdown-style"> {{ frappe.utils.md_to_html(bio) }} </p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
<!-- this is a sample default web page template -->
|
||||
@@ -1,4 +0,0 @@
|
||||
<div>
|
||||
<a href="{{ doc.route }}">{{ doc.title or doc.name }}</a>
|
||||
</div>
|
||||
<!-- this is a sample default list template -->
|
||||
@@ -1,92 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, Frappe and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
from community.lms.doctype.lms_course.test_lms_course import new_user
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
class TestCommunityMember(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
users = ["test_user@example.com","test_user1@example.com"]
|
||||
|
||||
for user in users:
|
||||
if not frappe.db.exists("User", user):
|
||||
new_user("Test User", user)
|
||||
|
||||
def test_member_created_from_user(self):
|
||||
user = frappe.db.get_value("User","test_user@example.com", ["full_name", "email", "username"], as_dict=True)
|
||||
self.assertTrue(frappe.db.exists("Community Member", {"username":user.username}))
|
||||
|
||||
member = frappe.db.get_value("Community Member",
|
||||
filters={"email": user.email},
|
||||
fieldname=["full_name", "email", "owner", "username", "route"],
|
||||
as_dict=True
|
||||
)
|
||||
|
||||
self.assertEqual(user.full_name, member.full_name)
|
||||
self.assertEqual(member.owner, user.email)
|
||||
self.assertEqual(user.username, member.username)
|
||||
self.assertEqual(member.username, member.route)
|
||||
|
||||
def test_members_with_same_name(self):
|
||||
user1 = frappe.db.get_value("User","test_user@example.com", ["email"], as_dict=True)
|
||||
user2 = frappe.get_doc("User","test_user1@example.com", ["email"], as_dict=True)
|
||||
|
||||
self.assertTrue(frappe.db.exists("Community Member", {"email": user1.email} ))
|
||||
self.assertTrue(frappe.db.exists("Community Member", {"email": user2.email }))
|
||||
|
||||
member1 = frappe.db.get_value("Community Member",
|
||||
filters={"email": user1.email},
|
||||
fieldname=["full_name", "email", "owner", "username", "route"],
|
||||
as_dict=True
|
||||
)
|
||||
member2 = frappe.db.get_value("Community Member",
|
||||
filters={"email": user2.email},
|
||||
fieldname=["full_name", "email", "owner", "username", "route"],
|
||||
as_dict=True
|
||||
)
|
||||
|
||||
self.assertEqual(member1.full_name, member2.full_name)
|
||||
self.assertEqual(member1.email, user1.email)
|
||||
self.assertEqual(member2.email, user2.email)
|
||||
self.assertNotEqual(member1.username, member2.username)
|
||||
|
||||
def test_username_validations(self):
|
||||
user = new_user("Tst", "tst@example.com")
|
||||
self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} ))
|
||||
|
||||
member = frappe.db.get_value("Community Member",
|
||||
filters={"email": user.email},
|
||||
fieldname=["username"],
|
||||
as_dict=True
|
||||
)
|
||||
|
||||
self.assertEqual(len(member.username), 4)
|
||||
frappe.delete_doc("User", user.email)
|
||||
|
||||
def test_user_without_username(self):
|
||||
user = new_user("Test User", "test_user2@example.com")
|
||||
self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} ))
|
||||
|
||||
member = frappe.db.get_value("Community Member",
|
||||
filters={"email": user.email},
|
||||
fieldname=["username"],
|
||||
as_dict=True
|
||||
)
|
||||
|
||||
self.assertTrue(member.username)
|
||||
frappe.delete_doc("User", user.email)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
users = ["test_user@example.com","test_user1@example.com"]
|
||||
|
||||
for user in users:
|
||||
if frappe.db.exists("User", user):
|
||||
frappe.delete_doc("User", user)
|
||||
|
||||
if frappe.db.exists("Community Member", {"email": user}):
|
||||
frappe.delete_doc("Community Member", {"email": user})
|
||||
@@ -1,16 +1 @@
|
||||
import frappe
|
||||
|
||||
def create_members_from_users():
|
||||
users = frappe.get_all("User", {"enabled": 1}, ["email"])
|
||||
for user in users:
|
||||
if not frappe.db.get_value("Community Member", {"email": user.email}, "name"):
|
||||
doc = frappe.get_doc("User", {"email": user.email})
|
||||
username = doc.username if doc.username and len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ])
|
||||
if not frappe.db.exists("Community Member", username):
|
||||
member = frappe.new_doc("Community Member")
|
||||
member.full_name = doc.full_name
|
||||
member.username = username
|
||||
member.email = doc.email
|
||||
member.route = username
|
||||
member.owner = doc.email
|
||||
member.insert(ignore_permissions=True)
|
||||
@@ -1,5 +0,0 @@
|
||||
frappe.ready(function() {
|
||||
frappe.web_form.after_save = () => {
|
||||
window.location.href = frappe.web_form.get_value("username")
|
||||
}
|
||||
})
|
||||
@@ -1,100 +0,0 @@
|
||||
{
|
||||
"accept_payment": 0,
|
||||
"allow_comments": 0,
|
||||
"allow_delete": 0,
|
||||
"allow_edit": 1,
|
||||
"allow_incomplete": 0,
|
||||
"allow_multiple": 0,
|
||||
"allow_print": 0,
|
||||
"amount": 0.0,
|
||||
"amount_based_on_field": 0,
|
||||
"apply_document_permissions": 0,
|
||||
"breadcrumbs": "",
|
||||
"button_label": "Save",
|
||||
"creation": "2021-03-09 17:34:03.394301",
|
||||
"doc_type": "Community Member",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2021-03-22 12:04:22.571655",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Community",
|
||||
"name": "update-profile",
|
||||
"owner": "Administrator",
|
||||
"payment_button_label": "Buy Now",
|
||||
"published": 1,
|
||||
"route": "edit-profile",
|
||||
"route_to_success_link": 0,
|
||||
"show_attachments": 0,
|
||||
"show_in_grid": 0,
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_message": "Profile updated successfully.",
|
||||
"success_url": "/",
|
||||
"title": "Update Profile",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "full_name",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Full Name",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "username",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "User Name",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "short_intro",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Short Intro",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "bio",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Bio",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
"allow_read_on_all_link_options": 0,
|
||||
"fieldname": "photo",
|
||||
"fieldtype": "Attach Image",
|
||||
"hidden": 0,
|
||||
"label": "Photo",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"show_in_filter": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
14
community/community/widgets/Avatar.html
Normal file
14
community/community/widgets/Avatar.html
Normal file
@@ -0,0 +1,14 @@
|
||||
{% set color = member.get_palette() %}
|
||||
<a class="button-links" href="/{{member.username}}">
|
||||
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
||||
{% if member.user_image %}
|
||||
<img class="avatar-frame standard-image" style="object-fit: cover;" src="{{ member.user_image }}" title="{{ member.full_name }}">
|
||||
</img>
|
||||
{% else %}
|
||||
<span class="avatar-frame standard-image" title="{{ member.full_name }}"
|
||||
style="background-color: var({{color[0]}}); color: var({{color[1]}});">
|
||||
{{ frappe.utils.get_abbr(member.full_name) }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</a>
|
||||
373
community/fixtures/custom_field.json
Normal file
373
community/fixtures/custom_field.json
Normal file
@@ -0,0 +1,373 @@
|
||||
[
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "linkedin",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "mobile_no",
|
||||
"label": "LinkedIn ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-linkedin",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "github",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "linkedin",
|
||||
"label": "Github ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-github",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "medium",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "github",
|
||||
"label": "Medium ID",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-medium",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "city",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "mute_sounds",
|
||||
"label": "City",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-city",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "college",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "city",
|
||||
"label": "College Name",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-college",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "branch",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "college",
|
||||
"label": "Branch",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-branch",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "User",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "profession",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "medium",
|
||||
"label": "Profession",
|
||||
"length": 0,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2021-06-30 14:46:55.834145",
|
||||
"name": "User-profession",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"parent": null,
|
||||
"parentfield": null,
|
||||
"parenttype": null,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
]
|
||||
@@ -23,7 +23,7 @@
|
||||
"fieldname": "organizer",
|
||||
"fieldtype": "Link",
|
||||
"label": "Organizer",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fieldname": "year",
|
||||
@@ -34,7 +34,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-14 11:43:23.515972",
|
||||
"modified": "2021-05-21 12:22:26.619776",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Hackathon",
|
||||
"name": "Community Hackathon",
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
class CommunityProjectMember(Document):
|
||||
def validate(self):
|
||||
self.validate_if_already_member()
|
||||
|
||||
|
||||
def validate_if_already_member(self):
|
||||
if frappe.get_all("Community Project Member", {"owner": self.owner}):
|
||||
frappe.throw(_("You have already applied for the membership of this project."))
|
||||
|
||||
@@ -10,15 +10,16 @@ app_icon = "octicon octicon-file-directory"
|
||||
app_color = "grey"
|
||||
app_email = "jannat@erpnext.com"
|
||||
app_license = "AGPL"
|
||||
|
||||
# Includes in <head>
|
||||
# ------------------
|
||||
|
||||
# include js, css files in header of desk.html
|
||||
app_include_css = "/assets/community/css/community.css"
|
||||
app_include_js = "/assets/community/js/community.js"
|
||||
# app_include_css = "/assets/community/css/community.css"
|
||||
# app_include_js = "/assets/community/js/community.js"
|
||||
|
||||
# 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_js = "/assets/community/js/community.js"
|
||||
|
||||
@@ -83,22 +84,17 @@ web_include_css = "/assets/css/community.css"
|
||||
# ---------------
|
||||
# Override standard doctype classes
|
||||
|
||||
# override_doctype_class = {
|
||||
# "ToDo": "custom_app.overrides.CustomToDo"
|
||||
# }
|
||||
override_doctype_class = {
|
||||
"User": "community.overrides.user.CustomUser"
|
||||
}
|
||||
|
||||
# Document Events
|
||||
# ---------------
|
||||
# Hook on document methods and events
|
||||
|
||||
doc_events = {
|
||||
"User": {
|
||||
"after_insert": "community.community.doctype.community_member.community_member.create_member_from_user"
|
||||
},
|
||||
"LMS Message": {
|
||||
"after_insert": "community.lms.doctype.lms_message.lms_message.publish_message"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Scheduled Tasks
|
||||
# ---------------
|
||||
@@ -108,6 +104,8 @@ doc_events = {
|
||||
# ]
|
||||
#}
|
||||
|
||||
fixtures = ["Custom Field"]
|
||||
|
||||
# Testing
|
||||
# -------
|
||||
|
||||
@@ -136,16 +134,18 @@ primary_rules = [
|
||||
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
|
||||
{"from_route": "/courses/<course>", "to_route": "courses/course"},
|
||||
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
|
||||
{"from_route": "/hackathons", "to_route": "hackathons"},
|
||||
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
|
||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||
{"from_route": "/dashboard", "to_route": ""},
|
||||
{"from_route": "/add-a-new-batch", "to_route": "add-a-new-batch"},
|
||||
{"from_route": "/courses/<course>/<batch>/learn", "to_route": "courses/learn"},
|
||||
{"from_route": "/courses/<course>/<batch>/schedule", "to_route": "courses/schedule"},
|
||||
{"from_route": "/courses/<course>/<batch>/members", "to_route": "courses/members"},
|
||||
{"from_route": "/courses/<course>/<batch>/discuss", "to_route": "courses/discuss"},
|
||||
{"from_route": "/courses/<course>/<batch>/about", "to_route": "courses/about"}
|
||||
{"from_route": "/courses/<course>/home", "to_route": "batch/home"},
|
||||
{"from_route": "/courses/<course>/learn", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/learn/<int:chapter>.<int:lesson>", "to_route": "batch/learn"},
|
||||
{"from_route": "/courses/<course>/schedule", "to_route": "batch/schedule"},
|
||||
{"from_route": "/courses/<course>/members", "to_route": "batch/members"},
|
||||
{"from_route": "/courses/<course>/discuss", "to_route": "batch/discuss"},
|
||||
{"from_route": "/courses/<course>/about", "to_route": "batch/about"},
|
||||
{"from_route": "/courses/<course>/progress", "to_route": "batch/progress"},
|
||||
{"from_route": "/courses/<course>/join", "to_route": "batch/join"}
|
||||
]
|
||||
|
||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||
@@ -162,9 +162,12 @@ whitelist = [
|
||||
"/socket.io",
|
||||
"/hackathons",
|
||||
"/dashboard",
|
||||
"/join-request"
|
||||
"/join-request",
|
||||
"/add-a-new-batch",
|
||||
"/new-sign-up"
|
||||
"/new-sign-up",
|
||||
"/message",
|
||||
"/about",
|
||||
"/edit-profile"
|
||||
]
|
||||
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]
|
||||
|
||||
@@ -175,4 +178,28 @@ profile_rules = [
|
||||
|
||||
website_route_rules = primary_rules + whitelist_rules + profile_rules
|
||||
|
||||
website_redirects = [
|
||||
{"source": "/update-profile", "target": "/edit-profile"},
|
||||
]
|
||||
|
||||
update_website_context = 'community.widgets.update_website_context'
|
||||
|
||||
## Specify the additional tabs to be included in the user profile page.
|
||||
## Each entry must be a subclass of community.community.plugins.ProfileTab
|
||||
# profile_tabs = []
|
||||
|
||||
## Specify the extension to be used to control what scripts and stylesheets
|
||||
## to be included in lesson pages. The specified value must be be a
|
||||
## subclass of community.community.plugins.PageExtension
|
||||
# community_lesson_page_extension = None
|
||||
|
||||
community_lesson_page_extensions = [
|
||||
"community.plugins.LiveCodeExtension"
|
||||
]
|
||||
|
||||
## Markdown Macros for Lessons
|
||||
community_markdown_macro_renderers = {
|
||||
"Exercise": "community.plugins.exercise_renderer",
|
||||
"Quiz": "community.plugins.quiz_renderer",
|
||||
"YouTubeVideo": "community.plugins.youtube_video_renderer",
|
||||
}
|
||||
|
||||
@@ -16,8 +16,32 @@ def autosave_section(section, code):
|
||||
return {"name": doc.name}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_section(name):
|
||||
"""Saves the code edited in one of the sections.
|
||||
def submit_solution(exercise, code):
|
||||
"""Submits a solution.
|
||||
|
||||
@exerecise: name of the exercise to submit
|
||||
@code: solution to the exercise
|
||||
"""
|
||||
doc = frappe.get_doc("LMS Section", name)
|
||||
return doc and doc.as_dict()
|
||||
ex = frappe.get_doc("Exercise", exercise)
|
||||
if not ex:
|
||||
return
|
||||
doc = ex.submit(code)
|
||||
return {"name": doc.name, "creation": doc.creation}
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_current_lesson(course_name, lesson_name):
|
||||
"""Saves the current lesson for a student/mentor.
|
||||
"""
|
||||
name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"course": course_name,
|
||||
"member": frappe.session.user
|
||||
},
|
||||
fieldname="name")
|
||||
if not name:
|
||||
return
|
||||
doc = frappe.get_doc("LMS Batch Membership", name)
|
||||
doc.current_lesson = lesson_name
|
||||
doc.save(ignore_permissions=True)
|
||||
return {"current_lesson": doc.current_lesson}
|
||||
|
||||
16
community/lms/doctype/chapter/chapter.js
Normal file
16
community/lms/doctype/chapter/chapter.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Chapter', {
|
||||
|
||||
onload: function (frm) {
|
||||
frm.set_query("lesson", "lessons", function () {
|
||||
return {
|
||||
filters: {
|
||||
"chapter": frm.doc.name,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -1,26 +1,22 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_guest_to_view": 1,
|
||||
"creation": "2021-03-02 07:20:41.686573",
|
||||
"autoname": "format:{####} {title}",
|
||||
"creation": "2021-05-03 05:49:08.383057",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"course",
|
||||
"title",
|
||||
"slug",
|
||||
"preview",
|
||||
"description",
|
||||
"order",
|
||||
"sections"
|
||||
"lessons"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Title",
|
||||
"reqd": 1
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "description",
|
||||
@@ -32,38 +28,27 @@
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course",
|
||||
"reqd": 1
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "order",
|
||||
"fieldtype": "Int",
|
||||
"label": "Order"
|
||||
},
|
||||
{
|
||||
"fieldname": "preview",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Preview"
|
||||
},
|
||||
{
|
||||
"fieldname": "sections",
|
||||
"fieldname": "lessons",
|
||||
"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"
|
||||
"label": "Lessons",
|
||||
"options": "Lessons"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-06 14:12:48.514062",
|
||||
"links": [
|
||||
{
|
||||
"group": "Lessons",
|
||||
"link_doctype": "Lesson",
|
||||
"link_fieldname": "chapter"
|
||||
}
|
||||
],
|
||||
"modified": "2021-07-27 16:28:08.667964",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Topic",
|
||||
"name": "Chapter",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -80,10 +65,8 @@
|
||||
}
|
||||
],
|
||||
"search_fields": "title",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "ASC",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1,
|
||||
"track_seen": 1,
|
||||
"track_views": 1
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CodeRevision(Document):
|
||||
pass
|
||||
class Chapter(Document):
|
||||
pass
|
||||
@@ -6,5 +6,5 @@ from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSTopic(unittest.TestCase):
|
||||
class TestChapter(unittest.TestCase):
|
||||
pass
|
||||
32
community/lms/doctype/chapters/chapters.json
Normal file
32
community/lms/doctype/chapters/chapters.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-07-27 16:25:02.903245",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"chapter"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-27 16:25:02.903245",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Chapters",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/chapters/chapters.py
Normal file
8
community/lms/doctype/chapters/chapters.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Chapters(Document):
|
||||
pass
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Topic', {
|
||||
frappe.ui.form.on('Exercise', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
123
community/lms/doctype/exercise/exercise.json
Normal file
123
community/lms/doctype/exercise/exercise.json
Normal file
@@ -0,0 +1,123 @@
|
||||
{
|
||||
"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",
|
||||
"index_",
|
||||
"index_label"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"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",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "index_",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-01 05:22:15.656013",
|
||||
"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": "index_label",
|
||||
"sort_order": "ASC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1
|
||||
}
|
||||
52
community/lms/doctype/exercise/exercise.py
Normal file
52
community/lms/doctype/exercise/exercise.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Exercise(Document):
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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,
|
||||
solution=code)
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
return doc
|
||||
|
||||
49
community/lms/doctype/exercise/test_exercise.py
Normal file
49
community/lms/doctype/exercise/test_exercise.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# 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",
|
||||
"short_introduction": "Test Course",
|
||||
"description": "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,119 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-19 11:41:18.108316",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"exercise",
|
||||
"status",
|
||||
"batch",
|
||||
"column_break_4",
|
||||
"exercise_title",
|
||||
"course",
|
||||
"lesson",
|
||||
"section_break_8",
|
||||
"solution",
|
||||
"image",
|
||||
"test_results",
|
||||
"comments"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "exercise",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Exercise",
|
||||
"options": "Exercise"
|
||||
},
|
||||
{
|
||||
"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
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"options": "Correct\nIncorrect"
|
||||
},
|
||||
{
|
||||
"fieldname": "test_results",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Test Results"
|
||||
},
|
||||
{
|
||||
"fieldname": "comments",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Comments"
|
||||
},
|
||||
{
|
||||
"fieldname": "solution",
|
||||
"fieldtype": "Code",
|
||||
"in_list_view": 1,
|
||||
"label": "Solution"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_8",
|
||||
"fieldtype": "Section Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-24 16:22:50.570845",
|
||||
"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,13 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from ..lesson.lesson import update_progress
|
||||
|
||||
class ExerciseSubmission(Document):
|
||||
|
||||
def after_insert(self):
|
||||
course_details = frappe.get_doc("LMS Course", self.course)
|
||||
if not (course_details.is_mentor(frappe.session.user) or frappe.flags.in_test):
|
||||
update_progress(self.lesson)
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestCodeRevision(unittest.TestCase):
|
||||
class TestExerciseSubmission(unittest.TestCase):
|
||||
pass
|
||||
@@ -11,7 +11,7 @@ from frappe.utils.password import get_decrypted_password
|
||||
|
||||
class InviteRequest(Document):
|
||||
def on_update(self):
|
||||
if self.has_value_changed('status') and self.status == "Approved":
|
||||
if self.has_value_changed("status") and self.status == "Approved":
|
||||
self.send_email()
|
||||
|
||||
def create_user(self, password):
|
||||
@@ -30,10 +30,13 @@ class InviteRequest(Document):
|
||||
return user
|
||||
|
||||
def send_email(self):
|
||||
subject = _("Your request has been approved.")
|
||||
site_name = "Mon.School"
|
||||
subject = _("Welcome to {0}!").format(site_name)
|
||||
|
||||
args = {
|
||||
"full_name": self.full_name,
|
||||
"signup_form_link": "/new-sign-up?invite_code={0}".format(self.name),
|
||||
"site_name": site_name,
|
||||
"site_url": frappe.utils.get_url()
|
||||
}
|
||||
frappe.sendmail(
|
||||
@@ -42,18 +45,28 @@ class InviteRequest(Document):
|
||||
subject=subject,
|
||||
header=[subject, "green"],
|
||||
template = "lms_invite_request_approved",
|
||||
args=args)
|
||||
args=args,
|
||||
now=True)
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def create_invite_request(invite_email):
|
||||
try:
|
||||
frappe.get_doc({
|
||||
|
||||
if not frappe.utils.validate_email_address(invite_email):
|
||||
return "invalid email"
|
||||
|
||||
if frappe.db.exists("User", invite_email):
|
||||
return "user"
|
||||
|
||||
if frappe.db.exists("Invite Request", {"invite_email": invite_email}):
|
||||
return "invite"
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "Invite Request",
|
||||
"invite_email": invite_email
|
||||
"invite_email": invite_email,
|
||||
"status": "Approved"
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
except frappe.UniqueValidationError:
|
||||
frappe.throw(_("Email {0} has already been used to request an invite").format(invite_email))
|
||||
return "OK"
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def update_invite(data):
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestInviteRequest(unittest.TestCase):
|
||||
filters={"invite_email": "test_invite@example.com"},
|
||||
fieldname=["invite_email", "status", "signup_email"],
|
||||
as_dict=True)
|
||||
self.assertEqual(invite.status, "Pending")
|
||||
self.assertEqual(invite.status, "Approved")
|
||||
self.assertEqual(invite.signup_email, None)
|
||||
|
||||
def test_create_invite_request_update(self):
|
||||
@@ -52,15 +52,8 @@ class TestInviteRequest(unittest.TestCase):
|
||||
self.assertEqual(user.send_welcome_email, 0)
|
||||
self.assertEqual(user.user_type, "Website User")
|
||||
|
||||
member = frappe.db.get_value("Community Member", {"email": "test_invite@example.com"})
|
||||
self.assertTrue(member)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
|
||||
if frappe.db.exists("Community Member", {"email": "test_invite@example.com"}):
|
||||
frappe.delete_doc("Community Member", {"email": "test_invite@example.com"})
|
||||
|
||||
if frappe.db.exists("User", "test_invite@example.com"):
|
||||
frappe.delete_doc("User", "test_invite@example.com")
|
||||
|
||||
|
||||
48
community/lms/doctype/lesson/lesson.js
Normal file
48
community/lms/doctype/lesson/lesson.js
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Lesson', {
|
||||
setup: function (frm) {
|
||||
frm.trigger('setup_help');
|
||||
},
|
||||
setup_help(frm) {
|
||||
frm.get_field('help').html(`
|
||||
<p>You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p>
|
||||
<div class="row font-weight-bold mb-3">
|
||||
<div class="col-sm-4">
|
||||
Content Type
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
Syntax
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
YouTube Video
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
{{ YouTubeVideo("unique_embed_id") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
Exercise
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
{{ Exercise("exercise_name") }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
Quiz
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
{{ Quiz("lms_quiz_name") }}
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
});
|
||||
92
community/lms/doctype/lesson/lesson.json
Normal file
92
community/lms/doctype/lesson/lesson.json
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "format:{####} {title}",
|
||||
"creation": "2021-05-03 06:21:12.995987",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"chapter",
|
||||
"include_in_preview",
|
||||
"column_break_4",
|
||||
"title",
|
||||
"index_label",
|
||||
"section_break_6",
|
||||
"body",
|
||||
"help_section",
|
||||
"help"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter"
|
||||
},
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "body",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Body"
|
||||
},
|
||||
{
|
||||
"fieldname": "index_label",
|
||||
"fieldtype": "Data",
|
||||
"label": "Index Label",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "include_in_preview",
|
||||
"fieldtype": "Check",
|
||||
"label": "Include In Preview"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "help_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Help"
|
||||
},
|
||||
{
|
||||
"fieldname": "help",
|
||||
"fieldtype": "HTML"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-27 16:28:29.203624",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Lesson",
|
||||
"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
|
||||
}
|
||||
132
community/lms/doctype/lesson/lesson.py
Normal file
132
community/lms/doctype/lesson/lesson.py
Normal file
@@ -0,0 +1,132 @@
|
||||
# -*- 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 ...md import markdown_to_html, find_macros
|
||||
|
||||
class Lesson(Document):
|
||||
def before_save(self):
|
||||
dynamic_documents = ["Exercise", "Quiz"]
|
||||
for section in dynamic_documents:
|
||||
self.update_lesson_name_in_document(section)
|
||||
|
||||
def update_lesson_name_in_document(self, section):
|
||||
doctype_map= {
|
||||
"Exercise": "Exercise",
|
||||
"Quiz": "LMS Quiz"
|
||||
}
|
||||
macros = find_macros(self.body)
|
||||
documents = [value for name, value in macros if name == section]
|
||||
index = 1
|
||||
for name in documents:
|
||||
e = frappe.get_doc(doctype_map[section], name)
|
||||
e.lesson = self.name
|
||||
e.index_ = index
|
||||
e.save()
|
||||
index += 1
|
||||
self.update_orphan_documents(doctype_map[section], documents)
|
||||
|
||||
def update_orphan_documents(self, doctype, documents):
|
||||
"""Updates the documents that were previously part of this lesson,
|
||||
but not any more.
|
||||
"""
|
||||
linked_documents = {row['name'] for row in frappe.get_all(doctype, {"lesson": self.name})}
|
||||
active_documents = set(documents)
|
||||
orphan_documents = linked_documents - active_documents
|
||||
for name in orphan_documents:
|
||||
ex = frappe.get_doc(doctype, name)
|
||||
ex.lesson = None
|
||||
ex.index_ = 0
|
||||
ex.index_label = ""
|
||||
ex.save()
|
||||
|
||||
def render_html(self):
|
||||
return markdown_to_html(self.body)
|
||||
|
||||
def get_exercises(self):
|
||||
if not self.body:
|
||||
return []
|
||||
|
||||
macros = find_macros(self.body)
|
||||
exercises = [value for name, value in macros if name == "Exercise"]
|
||||
return [frappe.get_doc("Exercise", name) for name in exercises]
|
||||
|
||||
def get_progress(self):
|
||||
return frappe.db.get_value("LMS Course Progress", {"lesson": self.name, "owner": frappe.session.user}, "status")
|
||||
|
||||
def get_slugified_class(self):
|
||||
if self.get_progress():
|
||||
return ("").join([ s for s in self.get_progress().lower().split() ])
|
||||
return
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_progress(lesson, course, status):
|
||||
if not frappe.db.exists("LMS Batch Membership",
|
||||
{
|
||||
"member": frappe.session.user,
|
||||
"course": course
|
||||
}):
|
||||
return
|
||||
|
||||
if frappe.db.exists("LMS Course Progress",
|
||||
{
|
||||
"lesson": lesson,
|
||||
"owner": frappe.session.user,
|
||||
"course": course
|
||||
}):
|
||||
doc = frappe.get_doc("LMS Course Progress",
|
||||
{
|
||||
"lesson": lesson,
|
||||
"owner": frappe.session.user,
|
||||
"course": course
|
||||
})
|
||||
doc.status = status
|
||||
doc.save(ignore_permissions=True)
|
||||
else:
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Progress",
|
||||
"lesson": lesson,
|
||||
"status": status,
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
def update_progress(lesson):
|
||||
user = frappe.session.user
|
||||
if not all_dynamic_content_submitted(lesson, user):
|
||||
return
|
||||
if frappe.db.exists("LMS Course Progress", {"lesson": lesson, "owner": user}):
|
||||
course_progress = frappe.get_doc("LMS Course Progress", {"lesson": lesson, "owner": user})
|
||||
course_progress.status = "Complete"
|
||||
course_progress.save(ignore_permissions=True)
|
||||
|
||||
def all_dynamic_content_submitted(lesson, user):
|
||||
all_exercises_submitted = check_all_exercise_submission(lesson, user)
|
||||
all_quiz_submitted = check_all_quiz_submitted(lesson, user)
|
||||
return all_exercises_submitted and all_quiz_submitted
|
||||
|
||||
def check_all_exercise_submission(lesson, user):
|
||||
exercise_names = frappe.get_list("Exercise", {"lesson": lesson}, pluck="name", ignore_permissions=True)
|
||||
if not len(exercise_names):
|
||||
return True
|
||||
query = {
|
||||
"exercise": ["in", exercise_names],
|
||||
"owner": user
|
||||
}
|
||||
if frappe.db.count("Exercise Submission", query) == len(exercise_names):
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_all_quiz_submitted(lesson, user):
|
||||
quizzes = frappe.get_list("LMS Quiz", {"lesson": lesson}, pluck="name", ignore_permissions=True)
|
||||
if not len(quizzes):
|
||||
return True
|
||||
query = {
|
||||
"quiz": ["in", quizzes],
|
||||
"owner": user
|
||||
}
|
||||
if frappe.db.count("LMS Quiz Submission", query) == len(quizzes):
|
||||
return True
|
||||
return False
|
||||
@@ -6,5 +6,5 @@ from __future__ import unicode_literals
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSSketch(unittest.TestCase):
|
||||
class TestLesson(unittest.TestCase):
|
||||
pass
|
||||
31
community/lms/doctype/lessons/lessons.json
Normal file
31
community/lms/doctype/lessons/lessons.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-07-27 16:25:48.269536",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"lesson"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-27 16:53:52.732191",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Lessons",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/lessons/lessons.py
Normal file
8
community/lms/doctype/lessons/lessons.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Lessons(Document):
|
||||
pass
|
||||
@@ -1,17 +1,15 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "field:title",
|
||||
"creation": "2021-03-18 19:37:34.614796",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"course",
|
||||
"title",
|
||||
"start_date",
|
||||
"start_time",
|
||||
"column_break_3",
|
||||
"code",
|
||||
"title",
|
||||
"sessions_on",
|
||||
"end_time",
|
||||
"section_break_5",
|
||||
@@ -32,18 +30,10 @@
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Data",
|
||||
"label": "Code",
|
||||
"read_only": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"label": "Title",
|
||||
"unique": 1
|
||||
"label": "Title"
|
||||
},
|
||||
{
|
||||
"fieldname": "description",
|
||||
@@ -51,10 +41,12 @@
|
||||
"label": "Description"
|
||||
},
|
||||
{
|
||||
"default": "Public",
|
||||
"fieldname": "visibility",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Visibility",
|
||||
"options": "\nPublic\nUnlisted\nPrivate"
|
||||
"options": "Public\nUnlisted\nPrivate"
|
||||
},
|
||||
{
|
||||
"fieldname": "membership",
|
||||
@@ -63,16 +55,19 @@
|
||||
"options": "\nOpen\nRestricted\nInvite Only\nClosed"
|
||||
},
|
||||
{
|
||||
"default": "Active",
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Status",
|
||||
"options": "\nActive\nInactive"
|
||||
"options": "Active\nInactive"
|
||||
},
|
||||
{
|
||||
"default": "Ready",
|
||||
"fieldname": "stage",
|
||||
"fieldtype": "Select",
|
||||
"label": "Stage",
|
||||
"options": "\nReady\nIn Progress\nCompleted\nCancelled"
|
||||
"options": "Ready\nIn Progress\nCompleted\nCancelled"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
@@ -80,7 +75,8 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_5",
|
||||
"fieldtype": "Section Break"
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Batch Description"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_9",
|
||||
@@ -88,7 +84,8 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_7",
|
||||
"fieldtype": "Section Break"
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Batch Settings"
|
||||
},
|
||||
{
|
||||
"fieldname": "start_date",
|
||||
@@ -122,7 +119,7 @@
|
||||
"link_fieldname": "batch"
|
||||
}
|
||||
],
|
||||
"modified": "2021-04-30 09:52:18.941276",
|
||||
"modified": "2021-06-16 10:51:05.403726",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch",
|
||||
|
||||
@@ -5,35 +5,104 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
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
|
||||
|
||||
class LMSBatch(Document):
|
||||
def validate(self):
|
||||
if not self.code:
|
||||
self.generate_code()
|
||||
def validate(self):
|
||||
self.validate_if_mentor()
|
||||
|
||||
def generate_code(self):
|
||||
short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
|
||||
course_batches = frappe.get_all("LMS Batch",{"course":self.course})
|
||||
self.code = short_code + str(len(course_batches) + 1)
|
||||
def 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))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_messages(batch):
|
||||
messages = frappe.get_all("LMS Message", {"batch": batch}, ["*"], order_by="creation")
|
||||
for message in messages:
|
||||
message.message = frappe.utils.md_to_html(message.message)
|
||||
member_email = frappe.db.get_value("Community Member", message.author, ["email"])
|
||||
if member_email == frappe.session.user:
|
||||
message.author_name = "You"
|
||||
message.is_author = True
|
||||
return messages
|
||||
def after_insert(self):
|
||||
create_membership(batch=self.name, course=self.course, member_type="Mentor")
|
||||
|
||||
def is_member(self, email, member_type=None):
|
||||
"""Checks if a person is part of a batch.
|
||||
|
||||
If member_type is specified, checks if the person is a Student/Mentor.
|
||||
"""
|
||||
|
||||
filters = {
|
||||
"batch": self.name,
|
||||
"member": email
|
||||
}
|
||||
if member_type:
|
||||
filters['member_type'] = member_type
|
||||
return frappe.db.exists("LMS Batch Membership", filters)
|
||||
|
||||
def get_messages(self):
|
||||
messages = frappe.get_all("LMS Message", {"batch": self.name}, ["*"], order_by="creation")
|
||||
for message in messages:
|
||||
message.message = frappe.utils.md_to_html(message.message)
|
||||
if message.author == frappe.session.user:
|
||||
message.author_name = "You"
|
||||
message.is_author = True
|
||||
return messages
|
||||
|
||||
def get_membership(self, email):
|
||||
"""Returns the membership document of given user.
|
||||
"""
|
||||
name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"batch": self.name,
|
||||
"member": email
|
||||
},
|
||||
fieldname="name")
|
||||
return frappe.get_doc("LMS Batch Membership", name)
|
||||
|
||||
def get_current_lesson(self, user):
|
||||
"""Returns the name of the current lesson for the given user.
|
||||
"""
|
||||
membership = self.get_membership(user)
|
||||
return membership and membership.current_lesson
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_message(message, batch):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Message",
|
||||
"batch": batch,
|
||||
"author": get_member_with_email(),
|
||||
"author": frappe.session.user,
|
||||
"message": message
|
||||
})
|
||||
doc.save(ignore_permissions=True)
|
||||
doc.save(ignore_permissions=True)
|
||||
|
||||
def switch_batch(course_name, email, batch_name):
|
||||
"""Switches the user from the current batch of the course to a new batch.
|
||||
"""
|
||||
membership = frappe.get_last_doc(
|
||||
"LMS Batch Membership",
|
||||
filters={"course": course_name, "member": email})
|
||||
|
||||
batch = frappe.get_doc("LMS Batch", batch_name)
|
||||
if not batch:
|
||||
raise ValueError(f"Invalid Batch: {batch_name}")
|
||||
|
||||
if batch.course != course_name:
|
||||
raise ValueError("Can not switch batches across courses")
|
||||
|
||||
if batch.is_member(email):
|
||||
print(f"{email} is already a member of {batch.title}")
|
||||
return
|
||||
|
||||
old_batch = frappe.get_doc("LMS Batch", membership.batch)
|
||||
|
||||
print("updating membership", membership.name)
|
||||
membership.batch = batch_name
|
||||
membership.save()
|
||||
|
||||
# update exercise submissions
|
||||
filters = {
|
||||
"owner": email,
|
||||
"batch": old_batch.name
|
||||
}
|
||||
for name in frappe.db.get_all("Exercise Submission", filters=filters, pluck='name'):
|
||||
doc = frappe.get_doc("Exercise Submission", name)
|
||||
print("updating exercise submission", name)
|
||||
doc.batch = batch_name
|
||||
doc.save()
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Batch Membership', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function(frm) {
|
||||
frm.set_query('member', function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"ignore_user_type": 1,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"batch",
|
||||
"role",
|
||||
"column_break_3",
|
||||
"member",
|
||||
"member_name",
|
||||
"member_type"
|
||||
"member_username",
|
||||
"column_break_3",
|
||||
"course",
|
||||
"member_type",
|
||||
"role",
|
||||
"current_lesson"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -27,19 +30,21 @@
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Member",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"default": "Student",
|
||||
"fieldname": "member_type",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Member Type",
|
||||
"options": "\nStudent\nMentor\nStaff"
|
||||
},
|
||||
{
|
||||
"default": "Member",
|
||||
"fieldname": "role",
|
||||
"fieldtype": "Select",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Role",
|
||||
"options": "\nMember\nAdmin"
|
||||
},
|
||||
@@ -54,11 +59,32 @@
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fetch_from": "batch.course",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "current_lesson",
|
||||
"fieldtype": "Link",
|
||||
"label": "Current Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fetch_from": "member.username",
|
||||
"fieldname": "member_username",
|
||||
"fieldtype": "Data",
|
||||
"label": "Memeber Username",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-26 12:52:59.826509",
|
||||
"modified": "2021-08-04 17:10:42.708479",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch Membership",
|
||||
|
||||
@@ -8,36 +8,71 @@ from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
class LMSBatchMembership(Document):
|
||||
|
||||
def validate(self):
|
||||
self.validate_membership_in_same_batch()
|
||||
self.validate_membership_in_different_batch_same_course()
|
||||
|
||||
def validate_membership_in_same_batch(self):
|
||||
previous_membership = frappe.db.get_value("LMS Batch Membership", {"member": self.member, "batch": self.batch, "name": ["!=", self.name]}, ["member_type","member"], as_dict=1)
|
||||
if previous_membership:
|
||||
member_name = frappe.db.get_value("Community Member", self.member, "full_name")
|
||||
frappe.throw(_("{0} is already a {1} of {2}").format(member_name, previous_membership.member_type, self.batch))
|
||||
|
||||
def validate_membership_in_different_batch_same_course(self):
|
||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||
previous_membership = frappe.get_all("LMS Batch Membership", {"member": self.member}, ["batch", "member_type"])
|
||||
for membership in previous_membership:
|
||||
batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course")
|
||||
if batch_course == course and (membership.member_type == "Student" or self.member_type == "Student"):
|
||||
member_name = frappe.db.get_value("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))
|
||||
def validate(self):
|
||||
self.validate_membership_in_same_batch()
|
||||
self.validate_membership_in_different_batch_same_course()
|
||||
|
||||
def validate_membership_in_same_batch(self):
|
||||
filters={
|
||||
"member": self.member,
|
||||
"course": self.course,
|
||||
"name": ["!=", self.name]
|
||||
}
|
||||
if self.batch:
|
||||
filters["batch"] = self.batch
|
||||
previous_membership = frappe.db.get_value("LMS Batch Membership",
|
||||
filters,
|
||||
fieldname=["member_type","member"],
|
||||
as_dict=1)
|
||||
|
||||
if previous_membership:
|
||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||
course_title = frappe.db.get_value("LMS Course", self.course, "title")
|
||||
frappe.throw(_("{0} is already a {1} of the course {2}").format(member_name, previous_membership.member_type, course_title))
|
||||
|
||||
def validate_membership_in_different_batch_same_course(self):
|
||||
"""Ensures that a studnet is only part of one batch.
|
||||
"""
|
||||
# nothing to worry if the member is not a student
|
||||
if self.member_type != "Student":
|
||||
return
|
||||
|
||||
course = frappe.db.get_value("LMS Batch", self.batch, "course")
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
filters={
|
||||
"member": self.member,
|
||||
"name": ["!=", self.name],
|
||||
"member_type": "Student",
|
||||
"course": self.course
|
||||
},
|
||||
fields=["batch", "member_type", "name"]
|
||||
)
|
||||
|
||||
if memberships:
|
||||
membership = memberships[0]
|
||||
member_name = frappe.db.get_value("User", self.member, "full_name")
|
||||
frappe.throw(_("{0} is already a Student of {1} course through {2} batch").format(member_name, course, membership.batch))
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_membership(batch, course, member=None, member_type="Student", role="Member"):
|
||||
if not member:
|
||||
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Batch Membership",
|
||||
"batch": batch,
|
||||
"role": role,
|
||||
"member_type": member_type,
|
||||
"member": member
|
||||
}).save(ignore_permissions=True)
|
||||
course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["slug"])
|
||||
return course_slug
|
||||
def create_membership(course, batch=None, member=None, member_type="Student", role="Member"):
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Batch Membership",
|
||||
"batch": batch,
|
||||
"course": course,
|
||||
"role": role,
|
||||
"member_type": member_type,
|
||||
"member": member or frappe.session.user
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_current_membership(batch, course, member):
|
||||
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": course})
|
||||
for membership in all_memberships:
|
||||
frappe.db.set_value("LMS Batch Membership", membership.name, "is_current", 0)
|
||||
|
||||
current_membership = frappe.get_all("LMS Batch Membership", {"batch": batch, "member": member})
|
||||
if len(current_membership):
|
||||
frappe.db.set_value("LMS Batch Membership", current_membership[0].name, "is_current", 1)
|
||||
|
||||
@@ -3,8 +3,78 @@
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSBatchMembership(unittest.TestCase):
|
||||
pass
|
||||
def setUp(self):
|
||||
frappe.db.sql("DELETE FROM `tabLMS Batch Membership`")
|
||||
frappe.db.sql("DELETE FROM `tabLMS Batch`")
|
||||
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
|
||||
frappe.db.sql("DELETE FROM `tabLMS Course`")
|
||||
frappe.db.sql("DELETE FROM `tabUser` where email like '%@test.com'")
|
||||
|
||||
def new_course_batch(self):
|
||||
course = frappe.get_doc({
|
||||
"doctype": "LMS Course",
|
||||
"name": "test-course",
|
||||
"title": "Test Course",
|
||||
"short_code": "XX",
|
||||
"short_introduction": "Test Course",
|
||||
"description": "Test Course"
|
||||
})
|
||||
course.insert()
|
||||
|
||||
self.new_user("mentor@test.com", "Test Mentor")
|
||||
# without this, the creating batch will fail
|
||||
course.add_mentor("mentor@test.com")
|
||||
|
||||
frappe.session.user = "mentor@test.com"
|
||||
|
||||
batch = frappe.get_doc({
|
||||
"doctype": "LMS Batch",
|
||||
"name": "test-batch",
|
||||
"title": "Test Batch",
|
||||
"course": course.name
|
||||
})
|
||||
batch.insert(ignore_permissions=True)
|
||||
|
||||
frappe.session.user = "Administrator"
|
||||
return course, batch
|
||||
|
||||
def new_user(self, email="test@test.com", full_name="Test User"):
|
||||
user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"name": email,
|
||||
"email": email,
|
||||
"first_name": full_name,
|
||||
})
|
||||
user.insert()
|
||||
return user
|
||||
|
||||
def add_membership(self, batch_name, member_name, member_type="Student"):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Batch Membership",
|
||||
"batch": batch_name,
|
||||
"member": member_name,
|
||||
"member_type": member_type
|
||||
})
|
||||
doc.insert()
|
||||
return doc
|
||||
|
||||
def test_membership(self):
|
||||
course, batch = self.new_course_batch()
|
||||
member = self.new_user("test01@test.com")
|
||||
membership = self.add_membership(batch.name, member.name)
|
||||
|
||||
assert membership.course == course.name
|
||||
assert membership.member_name == member.full_name
|
||||
|
||||
def test_membership_change_role(self):
|
||||
course, batch = self.new_course_batch()
|
||||
member = self.new_user("test01@test.com")
|
||||
membership = self.add_membership(batch.name, member.name)
|
||||
|
||||
# it should be possible to change role
|
||||
membership.role = "Admin"
|
||||
membership.save()
|
||||
|
||||
@@ -2,7 +2,15 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function (frm) {
|
||||
frm.set_query("chapter", "chapters", function () {
|
||||
return {
|
||||
filters: {
|
||||
"course": frm.doc.name,
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"actions": [
|
||||
{
|
||||
"action": "community.lms.doctype.lms_course.lms_course.reindex_exercises",
|
||||
"action_type": "Server Action",
|
||||
"group": "Reindex",
|
||||
"label": "Reindex Exercises"
|
||||
}
|
||||
],
|
||||
"allow_guest_to_view": 1,
|
||||
"allow_rename": 1,
|
||||
"autoname": "field:title",
|
||||
"creation": "2021-03-01 16:49:33.622422",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"slug",
|
||||
"is_published",
|
||||
"column_break_3",
|
||||
"short_code",
|
||||
"video_link",
|
||||
"image",
|
||||
"column_break_3",
|
||||
"tags",
|
||||
"is_published",
|
||||
"upcoming",
|
||||
"disable_self_learning",
|
||||
"section_break_5",
|
||||
"short_introduction",
|
||||
"description"
|
||||
"description",
|
||||
"chapters"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -30,7 +39,8 @@
|
||||
{
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Description"
|
||||
"label": "Description",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@@ -38,19 +48,6 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "Published"
|
||||
},
|
||||
{
|
||||
"fieldname": "short_code",
|
||||
"fieldtype": "Data",
|
||||
"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",
|
||||
"fieldtype": "Column Break"
|
||||
@@ -67,15 +64,44 @@
|
||||
{
|
||||
"fieldname": "short_introduction",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Short Introduction"
|
||||
"label": "Short Introduction",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "disable_self_learning",
|
||||
"fieldtype": "Check",
|
||||
"label": "Disable Self Learning"
|
||||
},
|
||||
{
|
||||
"fieldname": "image",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Preview Image"
|
||||
},
|
||||
{
|
||||
"fieldname": "tags",
|
||||
"fieldtype": "Data",
|
||||
"label": "Tags"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "upcoming",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is an Upcoming Course"
|
||||
},
|
||||
{
|
||||
"fieldname": "chapters",
|
||||
"fieldtype": "Table",
|
||||
"label": "Chapters",
|
||||
"options": "Chapters"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_published_field": "is_published",
|
||||
"links": [
|
||||
{
|
||||
"group": "Topics",
|
||||
"link_doctype": "LMS Topic",
|
||||
"group": "Chapters",
|
||||
"link_doctype": "Chapter",
|
||||
"link_fieldname": "course"
|
||||
},
|
||||
{
|
||||
@@ -89,7 +115,7 @@
|
||||
"link_fieldname": "course"
|
||||
}
|
||||
],
|
||||
"modified": "2021-04-21 14:45:41.658056",
|
||||
"modified": "2021-07-28 19:01:50.677445",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course",
|
||||
@@ -108,10 +134,9 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"search_fields": "slug",
|
||||
"search_fields": "title",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "title",
|
||||
"track_changes": 1,
|
||||
"track_views": 1
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -5,33 +5,39 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from ...utils import slugify
|
||||
from community.query import find, find_all
|
||||
from frappe.utils import flt, cint
|
||||
from ...utils import slugify
|
||||
|
||||
class LMSCourse(Document):
|
||||
def before_save(self):
|
||||
if not self.slug:
|
||||
self.slug = self.generate_slug(title=self.title)
|
||||
|
||||
@staticmethod
|
||||
def find(name):
|
||||
"""Returns the course with specified name.
|
||||
"""
|
||||
return find("LMS Course", is_published=True, name=name)
|
||||
|
||||
def autoname(self):
|
||||
if not self.name:
|
||||
self.name = self.generate_slug(title=self.title)
|
||||
|
||||
@staticmethod
|
||||
def find_all():
|
||||
"""Returns all published courses.
|
||||
"""
|
||||
return find_all("LMS Course", is_published=True)
|
||||
|
||||
def generate_slug(self, title):
|
||||
result = frappe.get_all(
|
||||
'LMS Course',
|
||||
fields=['slug'])
|
||||
slugs = set([row['slug'] for row in result])
|
||||
fields=['name'])
|
||||
slugs = set([row['name'] for row in result])
|
||||
return slugify(title, used_slugs=slugs)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Course#{self.name} {self.slug}>"
|
||||
|
||||
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'])
|
||||
return f"<Course#{self.name}>"
|
||||
|
||||
def has_mentor(self, email):
|
||||
"""Checks if this course has a mentor with given email.
|
||||
@@ -39,21 +45,9 @@ class LMSCourse(Document):
|
||||
if not email or email == "Guest":
|
||||
return False
|
||||
|
||||
member = self.get_community_member(email)
|
||||
if not member:
|
||||
return False
|
||||
|
||||
mapping = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name, "mentor": member})
|
||||
mapping = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name, "mentor": email})
|
||||
return mapping != []
|
||||
|
||||
def get_community_member(self, email):
|
||||
"""Returns the name of Community Member document for a give user.
|
||||
"""
|
||||
try:
|
||||
return frappe.db.get_value("Community Member", {"email": email}, ["name"])
|
||||
except frappe.DoesNotExistError:
|
||||
return None
|
||||
|
||||
def add_mentor(self, email):
|
||||
"""Adds a new mentor to the course.
|
||||
"""
|
||||
@@ -66,14 +60,10 @@ class LMSCourse(Document):
|
||||
if self.has_mentor(email):
|
||||
return
|
||||
|
||||
member = self.get_community_member(email)
|
||||
if not member:
|
||||
return False
|
||||
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Course Mentor Mapping",
|
||||
"course": self.name,
|
||||
"mentor": member
|
||||
"mentor": email
|
||||
})
|
||||
doc.insert()
|
||||
|
||||
@@ -83,20 +73,251 @@ class LMSCourse(Document):
|
||||
course_mentors = []
|
||||
mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": self.name}, ["mentor"])
|
||||
for mentor in mentors:
|
||||
member = frappe.get_doc("Community Member", mentor.mentor)
|
||||
# TODO: change this to count query
|
||||
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
|
||||
member = frappe.get_doc("User", mentor.mentor)
|
||||
member.batch_count = frappe.db.count("LMS Batch Membership",
|
||||
{
|
||||
"member": member.name,
|
||||
"member_type": "Mentor"
|
||||
})
|
||||
course_mentors.append(member)
|
||||
return course_mentors
|
||||
|
||||
def is_mentor(self, email):
|
||||
"""Checks if given user is a mentor for this course.
|
||||
"""
|
||||
if not email:
|
||||
return False
|
||||
return frappe.db.count("LMS Course Mentor Mapping",
|
||||
{
|
||||
"course": self.name,
|
||||
"mentor": email
|
||||
})
|
||||
|
||||
def get_student_batch(self, email):
|
||||
"""Returns the batch the given student is part of.
|
||||
|
||||
Returns None if the student is not part of any batch.
|
||||
"""
|
||||
if not email:
|
||||
return
|
||||
|
||||
batch_name = frappe.get_value(
|
||||
doctype="LMS Batch Membership",
|
||||
filters={
|
||||
"course": self.name,
|
||||
"member_type": "Student",
|
||||
"member": email
|
||||
},
|
||||
fieldname="batch")
|
||||
return batch_name and frappe.get_doc("LMS Batch", batch_name)
|
||||
|
||||
def get_instructor(self):
|
||||
return frappe.get_doc("User", self.owner)
|
||||
|
||||
@staticmethod
|
||||
def find_all():
|
||||
"""Returns all published courses.
|
||||
def get_chapters(self):
|
||||
"""Returns all chapters of this course.
|
||||
"""
|
||||
rows = frappe.db.get_all("LMS Course",
|
||||
filters={"is_published": True},
|
||||
fields='*')
|
||||
return [frappe.get_doc(dict(row, doctype='LMS Course')) for row in rows]
|
||||
chapters = []
|
||||
for row in self.chapters:
|
||||
chapter_details = frappe.db.get_value("Chapter", row.chapter,
|
||||
["name", "title", "description"],
|
||||
as_dict=True)
|
||||
chapter_details.idx = row.idx
|
||||
chapters.append(chapter_details)
|
||||
return chapters
|
||||
|
||||
def get_lessons(self, chapter=None):
|
||||
""" If chapter is passed, returns lessons of only that chapter.
|
||||
Else returns lessons of all chapters of the course """
|
||||
lessons = []
|
||||
|
||||
if chapter:
|
||||
return self.get_lesson_details(chapter)
|
||||
|
||||
for chapter in self.get_chapters():
|
||||
lesson = self.get_lesson_details(chapter)
|
||||
lessons += lesson
|
||||
|
||||
return lessons
|
||||
|
||||
def get_lesson_details(self, chapter):
|
||||
lessons = []
|
||||
lesson_list = frappe.get_all("Lessons", {"parent": chapter.name},
|
||||
["lesson", "idx"], order_by="idx")
|
||||
for row in lesson_list:
|
||||
lesson_details = frappe.get_doc("Lesson", row.lesson)
|
||||
lesson_details.number = flt("{}.{}".format(chapter.idx, row.idx))
|
||||
lessons.append(lesson_details)
|
||||
return lessons
|
||||
|
||||
def get_slugified_chapter_title(self, chapter):
|
||||
return slugify(chapter)
|
||||
|
||||
def get_course_progress(self):
|
||||
""" Returns the course progress of the session user """
|
||||
lesson_count = len(self.get_lessons())
|
||||
completed_lessons = frappe.db.count("LMS Course Progress",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user,
|
||||
"status": "Complete"
|
||||
})
|
||||
precision = cint(frappe.db.get_default("float_precision")) or 3
|
||||
if not lesson_count:
|
||||
return 0
|
||||
return flt(((completed_lessons/lesson_count) * 100), precision)
|
||||
|
||||
def get_batch(self, batch_name):
|
||||
return find("LMS Batch", name=batch_name, course=self.name)
|
||||
|
||||
def get_batches(self, mentor=None):
|
||||
batches = find_all("LMS Batch", course=self.name)
|
||||
if mentor:
|
||||
# TODO: optimize this
|
||||
memberships = frappe.db.get_all(
|
||||
"LMS Batch Membership",
|
||||
{"member": mentor},
|
||||
["batch"])
|
||||
batch_names = {m.batch for m in memberships}
|
||||
return [b for b in batches if b.name in batch_names]
|
||||
|
||||
def get_upcoming_batches(self):
|
||||
now = frappe.utils.nowdate()
|
||||
batches = find_all("LMS Batch",
|
||||
course=self.name,
|
||||
start_date=[">", now],
|
||||
status="Active",
|
||||
visibility="Public")
|
||||
return batches
|
||||
|
||||
def get_lesson_index(self, lesson_name):
|
||||
"""Returns the {chapter_index}.{lesson_index} for the lesson.
|
||||
"""
|
||||
lesson = frappe.db.get_value("Lessons", {"lesson": lesson_name}, ["idx", "parent"], as_dict=True)
|
||||
if not lesson:
|
||||
return None
|
||||
|
||||
chapter = frappe.db.get_value("Chapters", {"chapter": lesson.parent}, ["idx"], as_dict=True)
|
||||
if not chapter:
|
||||
return None
|
||||
|
||||
return f"{chapter.idx}.{lesson.idx}"
|
||||
|
||||
def reindex_exercises(self):
|
||||
for i, c in enumerate(self.get_chapters(), start=1):
|
||||
if c.index_ != i:
|
||||
c.index_ = i
|
||||
c.save()
|
||||
self._reindex_exercises_in_chapter(c)
|
||||
|
||||
def _reindex_exercises_in_chapter(self, c):
|
||||
i = 1
|
||||
for lesson in self.get_lessons(c):
|
||||
for exercise in lesson.get_exercises():
|
||||
exercise.index_ = i
|
||||
exercise.index_label = f"{c.index_}.{i}"
|
||||
exercise.save()
|
||||
i += 1
|
||||
|
||||
def get_learn_url(self, lesson_number):
|
||||
if not lesson_number:
|
||||
return
|
||||
return f"/courses/{self.name}/learn/{lesson_number}"
|
||||
|
||||
def get_membership(self, member, batch=None):
|
||||
filters = {
|
||||
"member": member,
|
||||
"course": self.name
|
||||
}
|
||||
if batch:
|
||||
filters["batch"] = batch
|
||||
|
||||
membership = frappe.db.get_value("LMS Batch Membership",
|
||||
filters,
|
||||
["name", "batch", "current_lesson", "member_type"],
|
||||
as_dict=True)
|
||||
|
||||
if membership and membership.batch:
|
||||
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
|
||||
return membership
|
||||
|
||||
def get_all_memberships(self, member):
|
||||
all_memberships = frappe.get_all("LMS Batch Membership", {"member": member, "course": self.name}, ["batch"])
|
||||
for membership in all_memberships:
|
||||
membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title")
|
||||
return all_memberships
|
||||
|
||||
def get_students(self, batch=None):
|
||||
"""Returns (email, full_name, username) of all the students of this batch as a list of dict.
|
||||
"""
|
||||
filters = {
|
||||
"course": self.name,
|
||||
"member_type": "Student"
|
||||
}
|
||||
if batch:
|
||||
filters["batch"] = batch
|
||||
memberships = frappe.get_all(
|
||||
"LMS Batch Membership",
|
||||
filters,
|
||||
["member"])
|
||||
member_names = [m['member'] for m in memberships]
|
||||
return find_all("User", name=["IN", member_names])
|
||||
|
||||
def get_tags(self):
|
||||
return self.tags.split(",") if self.tags else []
|
||||
|
||||
def get_reviews(self):
|
||||
reviews = frappe.get_all("LMS Course Review",
|
||||
{
|
||||
"course": self.name
|
||||
},
|
||||
["review", "rating", "owner"],
|
||||
order_by= "creation desc")
|
||||
|
||||
for review in reviews:
|
||||
review.owner_details = frappe.get_doc("User", review.owner)
|
||||
|
||||
return reviews
|
||||
|
||||
def is_eligible_to_review(self, membership):
|
||||
""" Checks if user is eligible to review the course """
|
||||
if not membership:
|
||||
return False
|
||||
if frappe.db.count("LMS Course Review",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user
|
||||
}):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_average_rating(self):
|
||||
ratings = [review.rating for review in self.get_reviews()]
|
||||
if not len(ratings):
|
||||
return None
|
||||
return sum(ratings)/len(ratings)
|
||||
|
||||
def get_progress(self, lesson):
|
||||
return frappe.db.get_value("LMS Course Progress",
|
||||
{
|
||||
"course": self.name,
|
||||
"owner": frappe.session.user,
|
||||
"lesson": lesson
|
||||
},
|
||||
["status"])
|
||||
|
||||
def get_neighbours(self, current, lessons):
|
||||
current = flt(current)
|
||||
numbers = sorted(lesson.number for lesson in lessons)
|
||||
index = numbers.index(current)
|
||||
return {
|
||||
"prev": numbers[index-1] if index-1 >= 0 else None,
|
||||
"next": numbers[index+1] if index+1 < len(numbers) else None
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def reindex_exercises(doc):
|
||||
course_data = json.loads(doc)
|
||||
course = frappe.get_doc("LMS Course", course_data['name'])
|
||||
course.reindex_exercises()
|
||||
frappe.msgprint("All exercises in this course have been re-indexed.")
|
||||
|
||||
@@ -11,12 +11,13 @@ class TestLMSCourse(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
|
||||
frappe.db.sql('delete from `tabLMS Course`')
|
||||
frappe.db.sql('delete from `tabCommunity Member`')
|
||||
|
||||
def new_course(self, title):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "LMS Course",
|
||||
"title": title
|
||||
"title": title,
|
||||
"short_introduction": title,
|
||||
"description": title
|
||||
})
|
||||
doc.insert()
|
||||
return doc
|
||||
@@ -24,8 +25,7 @@ class TestLMSCourse(unittest.TestCase):
|
||||
def test_new_course(self):
|
||||
course = self.new_course("Test Course")
|
||||
assert course.title == "Test Course"
|
||||
assert course.slug == "test-course"
|
||||
assert course.get_mentors() == []
|
||||
assert course.name == "test-course"
|
||||
|
||||
def test_find_all(self):
|
||||
courses = LMSCourse.find_all()
|
||||
@@ -41,7 +41,7 @@ class TestLMSCourse(unittest.TestCase):
|
||||
|
||||
# now we should find one course
|
||||
courses = LMSCourse.find_all()
|
||||
assert [c.slug for c in courses] == [course.slug]
|
||||
assert [c.name for c in courses] == [course.name]
|
||||
|
||||
# disabled this test as it is failing
|
||||
def _test_add_mentors(self):
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course Mentor Mapping', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
onload: function(frm) {
|
||||
frm.set_query('mentor', function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"ignore_user_type": 1,
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Mentor",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fetch_from": "mentor.full_name",
|
||||
@@ -36,7 +36,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-20 12:46:48.460934",
|
||||
"modified": "2021-05-21 11:48:43.340315",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course Mentor Mapping",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Course Progress', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-31 17:20:13.388453",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"status",
|
||||
"column_break_3",
|
||||
"lesson",
|
||||
"chapter",
|
||||
"course"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fetch_from": "chapter.course",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Course",
|
||||
"options": "LMS Course",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "lesson.chapter",
|
||||
"fieldname": "chapter",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Chapter",
|
||||
"options": "Chapter",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Lesson"
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"options": "Complete\nPartially Complete\nIncomplete"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-02 13:05:31.114939",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Course Progress",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSCourseProgress(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSCourseProgress(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Code Revision', {
|
||||
frappe.ui.form.on('LMS Course Review', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -1,41 +1,41 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-04-07 00:26:28.806520",
|
||||
"creation": "2021-06-28 13:36:36.146718",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"section",
|
||||
"code",
|
||||
"author"
|
||||
"review",
|
||||
"rating",
|
||||
"course"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "section",
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "review",
|
||||
"fieldtype": "Small Text",
|
||||
"in_list_view": 1,
|
||||
"label": "Section",
|
||||
"options": "LMS Section"
|
||||
"label": "Review"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
"fieldname": "rating",
|
||||
"fieldtype": "Rating",
|
||||
"in_list_view": 1,
|
||||
"label": "Rating"
|
||||
},
|
||||
{
|
||||
"fieldname": "author",
|
||||
"fieldname": "course",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Author",
|
||||
"options": "User"
|
||||
"label": "Course",
|
||||
"options": "LMS Course"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-14 11:26:19.628317",
|
||||
"modified": "2021-07-05 14:57:03.841430",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Code Revision",
|
||||
"name": "LMS Course Review",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -53,6 +53,5 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"title_field": "section",
|
||||
"track_changes": 1
|
||||
}
|
||||
18
community/lms/doctype/lms_course_review/lms_course_review.py
Normal file
18
community/lms/doctype/lms_course_review/lms_course_review.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSCourseReview(Document):
|
||||
pass
|
||||
|
||||
@frappe.whitelist()
|
||||
def submit_review(rating, review, course):
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Course Review",
|
||||
"rating": rating,
|
||||
"review": review,
|
||||
"course": course
|
||||
}).save(ignore_permissions=True)
|
||||
return "OK"
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSCourseReview(unittest.TestCase):
|
||||
pass
|
||||
@@ -19,7 +19,7 @@
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Member",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fieldname": "course",
|
||||
@@ -52,7 +52,7 @@
|
||||
"fieldname": "reviewed_by",
|
||||
"fieldtype": "Link",
|
||||
"label": "Reviewed By",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fieldname": "comments",
|
||||
@@ -62,7 +62,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-19 09:27:03.814016",
|
||||
"modified": "2021-05-21 11:49:12.543502",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Mentor Request",
|
||||
|
||||
@@ -8,86 +8,115 @@ from frappe.model.document import Document
|
||||
from frappe import _
|
||||
|
||||
class LMSMentorRequest(Document):
|
||||
def on_update(self):
|
||||
if self.has_value_changed('status'):
|
||||
template = frappe.db.get_single_value('LMS Settings', 'mentor_request_status_update')
|
||||
if not template:
|
||||
return
|
||||
def on_update(self):
|
||||
if self.has_value_changed('status'):
|
||||
|
||||
email_template = frappe.get_doc('Email Template', template)
|
||||
message = frappe.render_template(email_template.response, {'member_name': self.member_name, 'status': self.status})
|
||||
subject = _('The status of your application has changed.')
|
||||
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')
|
||||
send_email(member_email, [get_course_author(self.course), reviewed_by], subject, message)
|
||||
|
||||
elif self.status == 'Withdrawn':
|
||||
send_email([member_email, get_course_author(self.course)], None, subject, message)
|
||||
if self.status == "Approved":
|
||||
self.create_course_mentor_mapping()
|
||||
|
||||
if self.status != "Pending":
|
||||
self.send_status_change_email()
|
||||
|
||||
def create_course_mentor_mapping(self):
|
||||
mapping = frappe.get_doc({
|
||||
"doctype": "LMS Course Mentor Mapping",
|
||||
"mentor": self.member,
|
||||
"course": self.course
|
||||
})
|
||||
mapping.save()
|
||||
|
||||
def send_creation_email(self):
|
||||
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': frappe.db.get_value("User", frappe.session.user, "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
|
||||
})
|
||||
|
||||
if self.status == 'Approved' or self.status == 'Rejected':
|
||||
email_args = {
|
||||
"recipients": self.member,
|
||||
"cc": [course_details.owner, self.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": [self.member, 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()
|
||||
def has_requested(course):
|
||||
return len(frappe.get_all('LMS Mentor Request',
|
||||
filters = {
|
||||
'member': get_member().name,
|
||||
'course': course,
|
||||
'status': ['in', ('Pending', 'Approved')]
|
||||
}
|
||||
)
|
||||
return frappe.db.count('LMS Mentor Request',
|
||||
filters = {
|
||||
'member': frappe.session.user,
|
||||
'course': course,
|
||||
'status': ['in', ('Pending', 'Approved')]
|
||||
}
|
||||
)
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_request(course):
|
||||
if not has_requested(course):
|
||||
member = get_member()
|
||||
frappe.get_doc({
|
||||
'doctype': 'LMS Mentor Request',
|
||||
'member': member.name,
|
||||
'course': course,
|
||||
'status': 'Pending'
|
||||
}).save(ignore_permissions=True)
|
||||
send_creation_email(course, member)
|
||||
return 'OK'
|
||||
else:
|
||||
return 'Already Applied'
|
||||
if not has_requested(course):
|
||||
request = frappe.get_doc({
|
||||
'doctype': 'LMS Mentor Request',
|
||||
'member': frappe.session.user,
|
||||
'course': course,
|
||||
'status': 'Pending'
|
||||
})
|
||||
request.save(ignore_permissions=True)
|
||||
request.send_creation_email()
|
||||
return 'OK'
|
||||
|
||||
else:
|
||||
return 'Already Applied'
|
||||
|
||||
@frappe.whitelist()
|
||||
def cancel_request(course):
|
||||
request = frappe.get_doc('LMS Mentor Request', {'member': get_member().name, 'course': course, 'status': ['in', ('Pending', 'Approved')]})
|
||||
request.status = 'Withdrawn'
|
||||
request.save(ignore_permissions=True)
|
||||
return 'OK'
|
||||
|
||||
def get_member():
|
||||
try:
|
||||
return frappe.get_doc('Community Member', {'email': frappe.session.user})
|
||||
except frappe.DoesNotExistError:
|
||||
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
|
||||
)
|
||||
request = frappe.get_doc('LMS Mentor Request',{
|
||||
'member': frappe.session.user,
|
||||
'course': course,
|
||||
'status': ['in', ('Pending', 'Approved')]
|
||||
}
|
||||
)
|
||||
request.status = 'Withdrawn'
|
||||
request.save(ignore_permissions=True)
|
||||
return 'OK'
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Author",
|
||||
"options": "Community Member"
|
||||
"options": "User"
|
||||
},
|
||||
{
|
||||
"fieldname": "message",
|
||||
@@ -58,7 +58,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-04-28 10:17:57.618127",
|
||||
"modified": "2021-05-21 11:49:34.911479",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Message",
|
||||
@@ -82,4 +82,4 @@
|
||||
"sort_order": "DESC",
|
||||
"title_field": "author",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,98 +7,104 @@ import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe import _
|
||||
from frappe.utils import add_days, nowdate
|
||||
from community.www.courses.utils import get_batch_members
|
||||
|
||||
class LMSMessage(Document):
|
||||
""" def after_insert(self):
|
||||
self.send_email() """
|
||||
def after_insert(self):
|
||||
self.publish_message()
|
||||
#Todo: Adding email preference field for users
|
||||
#self.send_email()
|
||||
|
||||
def publish_message(self):
|
||||
template = self.get_message_template()
|
||||
message = frappe._dict({
|
||||
"author_name": self.author_name,
|
||||
"message_time": frappe.utils.format_datetime(self.creation, "dd-mm-yyyy HH:mm"),
|
||||
"message": frappe.utils.md_to_html(self.message)
|
||||
})
|
||||
|
||||
js = """
|
||||
$(".msger-input").val("");
|
||||
var template = `{0}`;
|
||||
var message = {1};
|
||||
var session_user = ("{2}" == frappe.session.user) ? true : false;
|
||||
message.author_name = session_user ? "You" : message.author_name
|
||||
message.is_author = session_user;
|
||||
template = frappe.render_template(template, {{
|
||||
"message": message
|
||||
}})
|
||||
$(".messages").append(template);
|
||||
var message_element = document.getElementsByClassName("messages")[0]
|
||||
message_element.scrollTo(0, message_element.scrollHeight);
|
||||
""".format(template, message, self.owner)
|
||||
|
||||
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
||||
|
||||
def get_message_template(self):
|
||||
return """
|
||||
<li class="{% if message.is_author %} ours {% endif %}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="font-weight-bold">
|
||||
{{ message.author_name }}
|
||||
</div>
|
||||
<small class="">
|
||||
{{ message.message_time }}
|
||||
</small>
|
||||
</div>
|
||||
<div class="message-para">
|
||||
{{ message.message }}
|
||||
</div>
|
||||
</li>
|
||||
"""
|
||||
|
||||
def send_email(self):
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.get_doc("User", entry.member)
|
||||
if member.name != self.author:
|
||||
#Todo: wrap sendmail in frappe.enqueue, else messages takes long to display.
|
||||
frappe.sendmail(
|
||||
recipients = member.email,
|
||||
subject = _("New Message on ") + self.batch,
|
||||
header = _("New Message on ") + self.batch,
|
||||
template = "lms_message",
|
||||
args = {
|
||||
"author": self.author,
|
||||
"message": frappe.utils.md_to_html(self.message),
|
||||
"creation": frappe.utils.format_datetime(self.creation, "medium"),
|
||||
"course": frappe.db.get_value("LMS Batch", self.batch, ["course"])
|
||||
}
|
||||
)
|
||||
|
||||
def send_email(self):
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.get_doc("Community Member", entry.member)
|
||||
if member.name != self.author and member.email_preference == "Email on every Message":
|
||||
frappe.sendmail(
|
||||
recipients = member.email,
|
||||
subject = _("New Message on ") + self.batch,
|
||||
header = _("New Message on ") + self.batch,
|
||||
template = "lms_message",
|
||||
args = {
|
||||
"author": self.author,
|
||||
"message": frappe.utils.md_to_html(self.message),
|
||||
"creation": frappe.utils.format_datetime(self.creation, "medium"),
|
||||
"course": frappe.db.get_value("LMS Batch", self.batch, ["course"])
|
||||
}
|
||||
)
|
||||
def send_daily_digest():
|
||||
emails = frappe._dict()
|
||||
messages = frappe.get_all("LMS Message", {"creation": [">=", add_days(nowdate(), -1)]}, ["message", "batch", "author", "creation"])
|
||||
for message in messages:
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": message.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.db.get_value("Community Member", entry.member, ["name", "email_preference", "email"], as_dict=1)
|
||||
if member.name != message.author and member.email_preference == "One Digest Mail per day":
|
||||
if member.name in emails.keys():
|
||||
emails[member.name]["messages"].append(message)
|
||||
else:
|
||||
emails[member.name] = frappe._dict({
|
||||
"email": member.email,
|
||||
"messages": [message]
|
||||
})
|
||||
for email in emails:
|
||||
group_by_batch = frappe._dict()
|
||||
for message in emails[email]["messages"]:
|
||||
if message.batch in group_by_batch.keys():
|
||||
group_by_batch[message.batch].append(message)
|
||||
else:
|
||||
group_by_batch[message.batch] = [message]
|
||||
frappe.sendmail(
|
||||
recipients = frappe.db.get_value("Community Member", email, "email"),
|
||||
subject = _("Message Digest"),
|
||||
header = _("Message Digest"),
|
||||
template = "lms_daily_digest",
|
||||
args = {
|
||||
"batches": group_by_batch
|
||||
},
|
||||
delayed = False
|
||||
)
|
||||
|
||||
def publish_message(doc, method):
|
||||
email = frappe.db.get_value("Community Member", doc.author, "email")
|
||||
template = get_message_template()
|
||||
message = frappe._dict()
|
||||
message.author_name = doc.author_name
|
||||
message.message_time = frappe.utils.pretty_date(doc.creation)
|
||||
message.message = frappe.utils.md_to_html(doc.message)
|
||||
|
||||
js = """
|
||||
$(".msger-input").val("");
|
||||
var template = `{0}`;
|
||||
var message = {1};
|
||||
var session_user = ("{2}" == frappe.session.user) ? true : false;
|
||||
message.author_name = session_user ? "You" : message.author_name
|
||||
message.is_author = session_user;
|
||||
template = frappe.render_template(template, {{
|
||||
"message": message
|
||||
}})
|
||||
$(".message-section").append(template);
|
||||
""".format(template, message, email)
|
||||
|
||||
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
|
||||
|
||||
def get_message_template():
|
||||
return """
|
||||
<div class="discussion {% if message.is_author %} is-author {% endif %}">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div class="font-weight-bold">
|
||||
{{ message.author_name }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ message.message_time }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
{{ message.message }}
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
#Todo: Optimize this
|
||||
emails = frappe._dict()
|
||||
messages = frappe.get_all("LMS Message", {"creation": [">=", add_days(nowdate(), -1)]}, ["message", "batch", "author", "creation"])
|
||||
for message in messages:
|
||||
membership = frappe.get_all("LMS Batch Membership", {"batch": message.batch}, ["member"])
|
||||
for entry in membership:
|
||||
member = frappe.db.get_value("User", entry.member, ["name", "email"], as_dict=1)
|
||||
if member.name != message.author:
|
||||
if member.name in emails.keys():
|
||||
emails[member.name]["messages"].append(message)
|
||||
else:
|
||||
emails[member.name] = frappe._dict({
|
||||
"email": member.email,
|
||||
"messages": [message]
|
||||
})
|
||||
for email in emails:
|
||||
group_by_batch = frappe._dict()
|
||||
for message in emails[email]["messages"]:
|
||||
if message.batch in group_by_batch.keys():
|
||||
group_by_batch[message.batch].append(message)
|
||||
else:
|
||||
group_by_batch[message.batch] = [message]
|
||||
frappe.sendmail(
|
||||
recipients = frappe.db.get_value("User", email, "email"),
|
||||
subject = _("Message Digest"),
|
||||
header = _("Message Digest"),
|
||||
template = "lms_daily_digest",
|
||||
args = {
|
||||
"batches": group_by_batch
|
||||
},
|
||||
delayed = False
|
||||
)
|
||||
|
||||
36
community/lms/doctype/lms_option/lms_option.json
Normal file
36
community/lms/doctype/lms_option/lms_option.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 10:46:10.402684",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"option",
|
||||
"is_correct"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "option",
|
||||
"fieldtype": "Data",
|
||||
"label": "Option"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_correct",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Correct"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-07 10:48:45.290227",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Option",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/lms_option/lms_option.py
Normal file
8
community/lms/doctype/lms_option/lms_option.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSOption(Document):
|
||||
pass
|
||||
0
community/lms/doctype/lms_quiz/__init__.py
Normal file
0
community/lms/doctype/lms_quiz/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Sketch', {
|
||||
frappe.ui.form.on('LMS Quiz', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
@@ -1,45 +1,42 @@
|
||||
{
|
||||
"actions": [],
|
||||
"autoname": "format:SKETCH-{#}",
|
||||
"creation": "2021-03-09 16:31:50.523524",
|
||||
"autoname": "field:title",
|
||||
"creation": "2021-06-07 10:50:17.893625",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"runtime",
|
||||
"code",
|
||||
"svg"
|
||||
"questions",
|
||||
"lesson"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "title",
|
||||
"fieldtype": "Data",
|
||||
"label": "Title"
|
||||
"label": "Title",
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "runtime",
|
||||
"fieldtype": "Data",
|
||||
"label": "Runtime"
|
||||
"fieldname": "questions",
|
||||
"fieldtype": "Table",
|
||||
"label": "Questions",
|
||||
"options": "LMS Quiz Question"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "svg",
|
||||
"fieldtype": "Code",
|
||||
"label": "SVG",
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"label": "Lesson",
|
||||
"options": "Lesson",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-03-12 08:42:56.671658",
|
||||
"modified": "2021-07-23 19:06:12.551633",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Sketch",
|
||||
"name": "LMS Quiz",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -57,6 +54,5 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_views": 1
|
||||
"track_changes": 1
|
||||
}
|
||||
75
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
75
community/lms/doctype/lms_quiz/lms_quiz.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from community.lms.doctype.lesson.lesson import update_progress
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
from frappe import _
|
||||
from ..lesson.lesson import update_progress
|
||||
|
||||
class LMSQuiz(Document):
|
||||
def validate(self):
|
||||
self.validate_correct_answers()
|
||||
|
||||
def validate_correct_answers(self):
|
||||
for question in self.questions:
|
||||
correct_options = self.get_correct_options(question)
|
||||
|
||||
if len(correct_options) > 1:
|
||||
question.multiple = 1
|
||||
|
||||
if not len(correct_options):
|
||||
frappe.throw(_("At least one answer must be correct for this question: {0}").format(frappe.bold(question.question)))
|
||||
|
||||
def get_correct_options(self, question):
|
||||
correct_option_fields = ["is_correct_1", "is_correct_2", "is_correct_3", "is_correct_4"]
|
||||
return list(filter(lambda x: question.get(x) == 1, correct_option_fields))
|
||||
|
||||
def get_last_submission_details(self):
|
||||
"""Returns the latest submission for this user.
|
||||
"""
|
||||
user = frappe.session.user
|
||||
if not user or user == "Guest":
|
||||
return
|
||||
|
||||
result = frappe.get_all('LMS Quiz Submission',
|
||||
fields="*",
|
||||
filters={
|
||||
"owner": user,
|
||||
"quiz": self.name
|
||||
},
|
||||
order_by="creation desc",
|
||||
page_length=1)
|
||||
|
||||
if result:
|
||||
return result[0]
|
||||
|
||||
@frappe.whitelist()
|
||||
def quiz_summary(quiz, results):
|
||||
score = 0
|
||||
results = json.loads(results)
|
||||
|
||||
for result in results:
|
||||
correct = result["is_correct"][0]
|
||||
result["question"] = frappe.db.get_value("LMS Quiz Question",
|
||||
{"parent": quiz, "idx": result["question_index"]},
|
||||
["question"])
|
||||
|
||||
for point in result["is_correct"]:
|
||||
correct = correct and point
|
||||
|
||||
result["result"] = "Right" if correct else "Wrong"
|
||||
score += correct
|
||||
|
||||
del result["is_correct"]
|
||||
del result["question_index"]
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Quiz Submission",
|
||||
"quiz": quiz,
|
||||
"result": results,
|
||||
"score": score
|
||||
}).save(ignore_permissions=True)
|
||||
|
||||
return score
|
||||
41
community/lms/doctype/lms_quiz/test_lms_quiz.py
Normal file
41
community/lms/doctype/lms_quiz/test_lms_quiz.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
import frappe
|
||||
|
||||
class TestLMSQuiz(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
frappe.get_doc({
|
||||
"doctype": "LMS Quiz",
|
||||
"title": "Test Quiz"
|
||||
}).save()
|
||||
|
||||
def test_with_multiple_options(self):
|
||||
quiz = frappe.get_doc("LMS Quiz", "Test Quiz")
|
||||
quiz.append("questions", {
|
||||
"question": "Question multiple",
|
||||
"option_1": "Option 1",
|
||||
"is_correct_1": 1,
|
||||
"option_2": "Option 2",
|
||||
"is_correct_2": 1
|
||||
})
|
||||
quiz.save()
|
||||
self.assertTrue(quiz.questions[0].multiple)
|
||||
|
||||
def test_with_no_correct_option(self):
|
||||
quiz = frappe.get_doc("LMS Quiz", "Test Quiz")
|
||||
quiz.append("questions", {
|
||||
"question": "Question no correct option",
|
||||
"option_1": "Option 1",
|
||||
"option_2": "Option 2",
|
||||
})
|
||||
self.assertRaises(frappe.ValidationError, quiz.save)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
frappe.db.delete("LMS Quiz", "Test Quiz")
|
||||
frappe.db.delete("LMS Quiz Question", {"parent": "Test Quiz"})
|
||||
0
community/lms/doctype/lms_quiz_question/__init__.py
Normal file
0
community/lms/doctype/lms_quiz_question/__init__.py
Normal file
166
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
166
community/lms/doctype/lms_quiz_question/lms_quiz_question.json
Normal file
@@ -0,0 +1,166 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 10:48:57.994714",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"question",
|
||||
"options_section",
|
||||
"option_1",
|
||||
"is_correct_1",
|
||||
"column_break_5",
|
||||
"explanation_1",
|
||||
"section_break_5",
|
||||
"option_2",
|
||||
"is_correct_2",
|
||||
"column_break_10",
|
||||
"explanation_2",
|
||||
"column_break_4",
|
||||
"option_3",
|
||||
"is_correct_3",
|
||||
"column_break_15",
|
||||
"explanation_3",
|
||||
"section_break_11",
|
||||
"option_4",
|
||||
"is_correct_4",
|
||||
"column_break_20",
|
||||
"explanation_4",
|
||||
"multiple"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "question",
|
||||
"fieldtype": "Text",
|
||||
"in_list_view": 1,
|
||||
"label": "Question",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "option_1",
|
||||
"fieldtype": "Data",
|
||||
"label": "Option 1",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "option_2",
|
||||
"fieldtype": "Data",
|
||||
"label": "Option 2",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "option_3",
|
||||
"fieldtype": "Data",
|
||||
"label": "Option 3"
|
||||
},
|
||||
{
|
||||
"fieldname": "option_4",
|
||||
"fieldtype": "Data",
|
||||
"label": "Option 4"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "option_1",
|
||||
"fieldname": "is_correct_1",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Correct"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "option_2",
|
||||
"fieldname": "is_correct_2",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Correct"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "option_3",
|
||||
"fieldname": "is_correct_3",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Correct"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "option_4",
|
||||
"fieldname": "is_correct_4",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Correct"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "multiple",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 1,
|
||||
"label": "Multiple Correct Answers",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "options_section",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_4",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_5",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_11",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_1",
|
||||
"fieldname": "explanation_1",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_2",
|
||||
"fieldname": "explanation_2",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_3",
|
||||
"fieldname": "explanation_3",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"depends_on": "option_4",
|
||||
"fieldname": "explanation_4",
|
||||
"fieldtype": "Data",
|
||||
"label": "Explanation"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_5",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_10",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_15",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_20",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-19 19:35:28.446236",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Question",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizQuestion(Document):
|
||||
pass
|
||||
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
0
community/lms/doctype/lms_quiz_result/__init__.py
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
45
community/lms/doctype/lms_quiz_result/lms_quiz_result.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 14:19:23.683323",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"question",
|
||||
"answer",
|
||||
"result"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "question",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Question"
|
||||
},
|
||||
{
|
||||
"fieldname": "result",
|
||||
"fieldtype": "Select",
|
||||
"in_list_view": 1,
|
||||
"label": "Result",
|
||||
"options": "Right\nWrong"
|
||||
},
|
||||
{
|
||||
"fieldname": "answer",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Users Response"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-22 18:32:28.813159",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Result",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
8
community/lms/doctype/lms_quiz_result/lms_quiz_result.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizResult(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2021, FOSS United and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('LMS Quiz Submission', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-06-07 14:19:54.958989",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"quiz",
|
||||
"result",
|
||||
"score"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "quiz",
|
||||
"fieldtype": "Link",
|
||||
"label": "Quiz",
|
||||
"options": "LMS Quiz"
|
||||
},
|
||||
{
|
||||
"fieldname": "result",
|
||||
"fieldtype": "Table",
|
||||
"label": "Result",
|
||||
"options": "LMS Quiz Result"
|
||||
},
|
||||
{
|
||||
"fieldname": "score",
|
||||
"fieldtype": "Data",
|
||||
"label": "Score"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-07 14:19:54.958989",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Quiz Submission",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class LMSQuizSubmission(Document):
|
||||
pass
|
||||
@@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestLMSQuizSubmission(unittest.TestCase):
|
||||
pass
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-03-05 15:10:53.906006",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"label",
|
||||
"type",
|
||||
"contents",
|
||||
"code",
|
||||
"attrs",
|
||||
"index"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Label"
|
||||
},
|
||||
{
|
||||
"fieldname": "type",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Type"
|
||||
},
|
||||
{
|
||||
"fieldname": "contents",
|
||||
"fieldtype": "Markdown Editor",
|
||||
"label": "Contents"
|
||||
},
|
||||
{
|
||||
"fieldname": "code",
|
||||
"fieldtype": "Code",
|
||||
"label": "Code"
|
||||
},
|
||||
{
|
||||
"fieldname": "attrs",
|
||||
"fieldtype": "Long Text",
|
||||
"label": "attrs"
|
||||
},
|
||||
{
|
||||
"fieldname": "index",
|
||||
"fieldtype": "Int",
|
||||
"label": "Index"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-03-12 17:56:23.118854",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Section",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -10,6 +10,14 @@ class LMSSection(Document):
|
||||
def __repr__(self):
|
||||
return f"<LMSSection {self.label!r}>"
|
||||
|
||||
def get_exercise(self):
|
||||
if self.type == "exercise":
|
||||
return frappe.get_doc("Exercise", self.id)
|
||||
|
||||
def get_quiz(self):
|
||||
if self.type == "quiz":
|
||||
return frappe.get_doc("LMS Quiz", self.id)
|
||||
|
||||
def get_latest_code_for_user(self):
|
||||
"""Returns the latest code for the logged in user.
|
||||
"""
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user