Compare commits

..

35 Commits

Author SHA1 Message Date
Anand Chitipothu
343aa50f78 Merge branch 'main' into course-page 2021-05-06 13:50:12 +05:30
Anand Chitipothu
5a70687067 refactor: removed the slug using the course name as part of url 2021-05-06 13:42:45 +05:30
Anand Chitipothu
a0921f7380 Merge pull request #77 from fossunited/widget-avatar
feat: Widget avatar
2021-05-06 13:26:49 +05:30
pateljannat
413aeaccb1 feat: avatar widget 2021-05-06 12:17:28 +05:30
Anand Chitipothu
88457a82ac refactor: learn page 2021-05-06 07:05:27 +05:30
Anand Chitipothu
761f36519e refactor: refactored the about page 2021-05-06 07:05:17 +05:30
Anand Chitipothu
dc5b637ada refactor: fixed the course page 2021-05-06 06:47:09 +05:30
pateljannat
69b3f366f4 feat: widget file added 2021-05-05 16:32:21 +05:30
Anand Chitipothu
da902d23f7 Merge pull request #71 from fossunited/footer
Fix footer
2021-05-05 16:30:45 +05:30
Anand Chitipothu
c2be23a902 fix: fixed the pickle error on installing community 2021-05-05 15:58:28 +05:30
Anand Chitipothu
da771d7830 [actions] added action to ache bench 2021-05-05 15:57:41 +05:30
Anand Chitipothu
041bed7e9d Added sketches to the nav-bar on install 2021-05-05 12:56:27 +05:30
Anand Chitipothu
e330f45adc style: fixed the footer 2021-05-05 12:53:24 +05:30
Anand Chitipothu
370d3a321b Merge pull request #68 from fossunited/invite-flow-fixes
fix: invite flow issues
2021-05-04 23:23:40 +05:30
Anand Chitipothu
138fba66ae Merge branch 'main' of git://github.com/khalby786/community into khalby786-main 2021-05-04 23:21:21 +05:30
Anand Chitipothu
82faaed15d feat: set app name and logo on install and disable signup
- set app_name and app_logo_url on install
- disabled signup
2021-05-04 23:19:50 +05:30
Anand Chitipothu
b58a685e7a Merge pull request #64 from fossunited/miscellaneous-fixes
fix: Miscellaneous fixes
2021-05-04 19:18:17 +05:30
pateljannat
45ec16d9e4 fix: reverted error message 2021-05-04 17:43:09 +05:30
pateljannat
18c0fb0da5 fix: #65 and #66 2021-05-04 17:41:54 +05:30
pateljannat
b7d93c1b50 fix: get_mentors in batch 2021-05-04 16:50:39 +05:30
pateljannat
e931ead270 fix: miscellaneous 2021-05-04 12:47:45 +05:30
pateljannat
8933ca9ac9 Merge branch 'main' of https://github.com/frappe/community into miscellaneous-fixes 2021-05-03 16:57:58 +05:30
Anand Chitipothu
1a06e2c0aa Merge pull request #61 from fossunited/issue-56
doctypes for chapter and lesson
2021-05-03 16:51:01 +05:30
Anand Chitipothu
491b5c46ae Merge branch 'main' into issue-56 2021-05-03 16:03:30 +05:30
pateljannat
2139bddf01 fix: removed unused form add messages, changed url for new batch form in course.html, changed get_recent_sketch to have an owner filter 2021-05-03 15:57:00 +05:30
pateljannat
cf68d3127c fix: conflicts 2021-05-03 15:51:06 +05:30
pateljannat
f13bb494ef fix: converted tabs to spaces 2021-05-03 15:50:14 +05:30
Jannat Patel
5e18cd2ef4 Merge pull request #52 from fossunited/invite-flow
fix: invite flow and add new batch form enhancements
2021-05-03 15:47:09 +05:30
pateljannat
0144ab60de fix: logout issue, liscence.txt change 2021-05-03 15:05:23 +05:30
Anand Chitipothu
b9d94df4d8 refactor: refactored the course page
- simplified the portal page for course
- added mentods to LMS Course and Community Member to reduce custom code
  in portal pages
- included lessons in the ChapterTeaser
2021-05-03 12:05:17 +05:30
Anand Chitipothu
9e103af8b5 refactor: added auto name to chapter and lesson doctypes 2021-05-03 06:52:22 +05:30
Anand Chitipothu
5728714d71 feat: added lesson doctype 2021-05-03 06:50:23 +05:30
Anand Chitipothu
62cfc0fb24 feat: Added ChapterTeaser widget 2021-05-03 06:50:07 +05:30
Anand Chitipothu
a52a01ef7f feat: Added chapter doctype
Also linked it from the LMS Course doctype.

Issue #56
2021-05-03 06:06:35 +05:30
Khaleel Gibran
67d3ec75c8 feat: design homepage based on figma design 2021-05-01 18:51:44 +05:30
53 changed files with 988 additions and 556 deletions

View File

@@ -38,10 +38,25 @@ jobs:
with: with:
node-version: '12' node-version: '12'
check-latest: true check-latest: true
- name: setup cache for bench
uses: actions/cache@v2
with:
path: ~/bench-cache
key: ${{ runner.os }}
- name: install bench - name: install bench
run: pip3 install frappe-bench run: |
pip3 install frappe-bench
which bench
- name: bench init - 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 - name: add community app to bench
working-directory: /home/runner/frappe-bench working-directory: /home/runner/frappe-bench
run: bench get-app community $GITHUB_WORKSPACE run: bench get-app community $GITHUB_WORKSPACE
@@ -50,7 +65,7 @@ jobs:
run: bench new-site --mariadb-root-password root --admin-password admin frappe.local run: bench new-site --mariadb-root-password root --admin-password admin frappe.local
- name: install community app - name: install community app
working-directory: /home/runner/frappe-bench 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 - name: allow tests
working-directory: /home/runner/frappe-bench working-directory: /home/runner/frappe-bench
run: bench --site frappe.local set-config allow_tests true run: bench --site frappe.local set-config allow_tests true

View File

@@ -8,57 +8,94 @@ import re
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
import random import random
from frappe.utils import cint
import hashlib
class CommunityMember(Document): class CommunityMember(Document):
def validate(self): def validate(self):
self.validate_username() self.validate_username()
self.abbr = ("").join([ s[0] for s in self.full_name.split() ]) self.abbr = ("").join([ s[0] for s in self.full_name.split() ])
if self.route != self.username: if self.route != self.username:
self.route = self.username self.route = self.username
def validate_username(self): def validate_username(self):
if not self.username: if not self.username:
self.username = create_username_from_email(self.email) self.username = create_username_from_email(self.email)
if self.username: if self.username:
if len(self.username) < 4: if len(self.username) < 4:
frappe.throw(_("Username must be atleast 4 characters long.")) frappe.throw(_("Username must be atleast 4 characters long."))
if not re.match("^[A-Za-z0-9_]*$", self.username): if not re.match("^[A-Za-z0-9_]*$", self.username):
frappe.throw(_("Username can only contain alphabets, numbers and underscore.")) frappe.throw(_("Username can only contain alphabets, numbers and underscore."))
self.username = self.username.lower() self.username = self.username.lower()
def __repr__(self): def get_course_count(self) -> int:
return f"<CommunityMember: {self.email}>" """Returns the number of courses authored by this user.
"""
return frappe.db.count(
'LMS Course', {
'owner': self.email
})
def get_batch_count(self) -> int:
"""Returns the number of batches authored by this user.
"""
return frappe.db.count(
'LMS Batch Membership', {
'member': self.name,
'member_type': 'Mentor'
})
def get_palette(self):
palette = [
['--orange-avatar-bg', '--orange-avatar-color'],
['--pink-avatar-bg', '--pink-avatar-color'],
['--blue-avatar-bg', '--blue-avatar-color'],
['--green-avatar-bg', '--green-avatar-color'],
['--dark-green-avatar-bg', '--dark-green-avatar-color'],
['--red-avatar-bg', '--red-avatar-color'],
['--yellow-avatar-bg', '--yellow-avatar-color'],
['--purple-avatar-bg', '--purple-avatar-color'],
['--gray-avatar-bg', '--gray-avatar-color0']
]
encoded_name = str(self.full_name).encode("utf-8")
hash_name = hashlib.md5(encoded_name).hexdigest()
idx = cint((int(hash_name[4:6], 16) + 1) / 5.33)
return palette[idx % 8]
def __repr__(self):
return f"<CommunityMember: {self.email}>"
def create_member_from_user(doc, method): def create_member_from_user(doc, method):
username = doc.username username = doc.username
if ( doc.username and username_exists(doc.username)) or not doc.username: if ( doc.username and username_exists(doc.username)) or not doc.username:
username = create_username_from_email(doc.email) username = create_username_from_email(doc.email)
elif len(doc.username) < 4: elif len(doc.username) < 4:
username = adjust_username(doc.username) username = adjust_username(doc.username)
if username_exists(username): if username_exists(username):
username = username + str(random.randint(0,9)) username = username + str(random.randint(0,9))
member = frappe.get_doc({ member = frappe.get_doc({
"doctype": "Community Member", "doctype": "Community Member",
"full_name": doc.full_name, "full_name": doc.full_name,
"username": username, "username": username,
"email": doc.email, "email": doc.email,
"route": doc.username, "route": doc.username,
"owner": doc.email "owner": doc.email
}) })
member.save(ignore_permissions=True) member.save(ignore_permissions=True)
def username_exists(username): def username_exists(username):
return frappe.db.exists("Community Member", dict(username=username)) return frappe.db.exists("Community Member", dict(username=username))
def create_username_from_email(email): def create_username_from_email(email):
string = email.split("@")[0] string = email.split("@")[0]
return ''.join(e for e in string if e.isalnum()) return ''.join(e for e in string if e.isalnum())
def adjust_username(username): def adjust_username(username):
return username.ljust(4, str(random.randint(0,9))) return username.ljust(4, str(random.randint(0,9)))

View File

@@ -0,0 +1,12 @@
{% set color = member.get_palette() %}
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
{% if member.photo %}
<img class="avatar-frame standard-image" src="{{ member.photo }}" 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]}});">
{{ member.abbr }}
</span>
{% endif %}
</span>

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from . import __version__ as app_version from . import __version__ as app_version
from .install import APP_LOGO_URL
app_name = "community" app_name = "community"
app_title = "Community" app_title = "Community"
@@ -10,6 +11,9 @@ app_icon = "octicon octicon-file-directory"
app_color = "grey" app_color = "grey"
app_email = "jannat@erpnext.com" app_email = "jannat@erpnext.com"
app_license = "AGPL" app_license = "AGPL"
app_logo_url = APP_LOGO_URL
# Includes in <head> # Includes in <head>
# ------------------ # ------------------
@@ -59,7 +63,7 @@ web_include_css = "/assets/css/community.css"
# ------------ # ------------
# before_install = "community.install.before_install" # before_install = "community.install.before_install"
# after_install = "community.install.after_install" after_install = "community.install.after_install"
# Desk Notifications # Desk Notifications
# ------------------ # ------------------
@@ -136,7 +140,6 @@ primary_rules = [
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"}, {"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
{"from_route": "/courses/<course>", "to_route": "courses/course"}, {"from_route": "/courses/<course>", "to_route": "courses/course"},
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"}, {"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
{"from_route": "/hackathons", "to_route": "hackathons"},
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"}, {"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"}, {"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
{"from_route": "/dashboard", "to_route": ""}, {"from_route": "/dashboard", "to_route": ""},
@@ -164,7 +167,8 @@ whitelist = [
"/dashboard", "/dashboard",
"/join-request" "/join-request"
"/add-a-new-batch", "/add-a-new-batch",
"/new-sign-up" "/new-sign-up",
"/message"
] ]
whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist] whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist]

42
community/install.py Normal file
View File

@@ -0,0 +1,42 @@
"""Hooks that are executed during and after install.
"""
import os
import frappe
APP_LOGO_URL = os.getenv("APP_LOGO_URL") or "/files/logo.png"
def after_install():
set_app_name()
disable_signup()
add_header_items()
add_footer_items()
def set_app_name():
app_name = os.getenv("FRAPPE_APP_NAME")
if app_name:
frappe.db.set_value('System Settings', None, 'app_name', app_name)
def disable_signup():
frappe.db.set_value("Website Settings", None, "disable_signup", 1)
def add_header_items():
items = [
{"label": "Sketches", "url": "/sketches"},
]
doc = frappe.get_doc("Website Settings", None)
doc.update({
"top_bar_items": items
})
doc.save()
def add_footer_items():
items = [
{"label": "About", "url": "/about"},
{"label": "Blog", "url": "/blog"},
{"label": "Github", "url": "https://github.com/fossunited/community"}
]
doc = frappe.get_doc("Website Settings", None)
doc.update({
"footer_items": items
})
doc.save()

View File

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

View File

@@ -0,0 +1,72 @@
{
"actions": [],
"autoname": "format:{####} {title}",
"creation": "2021-05-03 05:49:08.383057",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"course",
"title",
"description",
"locked"
],
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Title"
},
{
"fieldname": "description",
"fieldtype": "Markdown Editor",
"label": "Description"
},
{
"default": "0",
"fieldname": "locked",
"fieldtype": "Check",
"label": "Locked"
},
{
"fieldname": "course",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Course",
"options": "LMS Course"
}
],
"index_web_pages_for_search": 1,
"links": [
{
"group": "Lessons",
"link_doctype": "Lesson",
"link_fieldname": "chapter"
}
],
"modified": "2021-05-03 06:52:10.894328",
"modified_by": "Administrator",
"module": "LMS",
"name": "Chapter",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"search_fields": "title",
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "title",
"track_changes": 1
}

View File

@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class Chapter(Document):
def get_lessons(self):
rows = frappe.db.get_all("Lesson",
filters={"chapter": self.name},
fields='*')
return [frappe.get_doc(dict(row, doctype='Lesson')) for row in rows]

View File

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

View File

@@ -11,7 +11,7 @@ from frappe.utils.password import get_decrypted_password
class InviteRequest(Document): class InviteRequest(Document):
def on_update(self): 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() self.send_email()
def create_user(self, password): def create_user(self, password):
@@ -46,14 +46,19 @@ class InviteRequest(Document):
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def create_invite_request(invite_email): def create_invite_request(invite_email):
try:
frappe.get_doc({ 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", "doctype": "Invite Request",
"invite_email": invite_email "invite_email": invite_email
}).save(ignore_permissions=True) }).save(ignore_permissions=True)
return "OK" return "OK"
except frappe.UniqueValidationError:
frappe.throw(_("Email {0} has already been used to request an invite").format(invite_email))
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def update_invite(data): def update_invite(data):

View File

View File

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

View File

@@ -0,0 +1,60 @@
{
"actions": [],
"autoname": "format:{####} {title}",
"creation": "2021-05-03 06:21:12.995987",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"chapter",
"lesson_type",
"title"
],
"fields": [
{
"fieldname": "chapter",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Chapter",
"options": "Chapter"
},
{
"default": "Video",
"fieldname": "lesson_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Lesson Type",
"options": "Video\nText\nQuiz"
},
{
"fieldname": "title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Title"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-05-03 06:51:43.588969",
"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
}

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class Lesson(Document):
pass

View File

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

View File

@@ -1,6 +1,5 @@
{ {
"actions": [], "actions": [],
"autoname": "field:title",
"creation": "2021-03-18 19:37:34.614796", "creation": "2021-03-18 19:37:34.614796",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
@@ -51,10 +50,12 @@
"label": "Description" "label": "Description"
}, },
{ {
"default": "Public",
"fieldname": "visibility", "fieldname": "visibility",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1,
"label": "Visibility", "label": "Visibility",
"options": "\nPublic\nUnlisted\nPrivate" "options": "Public\nUnlisted\nPrivate"
}, },
{ {
"fieldname": "membership", "fieldname": "membership",
@@ -63,16 +64,19 @@
"options": "\nOpen\nRestricted\nInvite Only\nClosed" "options": "\nOpen\nRestricted\nInvite Only\nClosed"
}, },
{ {
"default": "Active",
"fieldname": "status", "fieldname": "status",
"fieldtype": "Select", "fieldtype": "Select",
"in_list_view": 1,
"label": "Status", "label": "Status",
"options": "\nActive\nInactive" "options": "Active\nInactive"
}, },
{ {
"default": "Ready",
"fieldname": "stage", "fieldname": "stage",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Stage", "label": "Stage",
"options": "\nReady\nIn Progress\nCompleted\nCancelled" "options": "Ready\nIn Progress\nCompleted\nCancelled"
}, },
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
@@ -122,7 +126,7 @@
"link_fieldname": "batch" "link_fieldname": "batch"
} }
], ],
"modified": "2021-04-30 09:52:18.941276", "modified": "2021-05-06 05:46:38.469120",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Batch", "name": "LMS Batch",

View File

@@ -6,16 +6,34 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
from community.www.courses.utils import get_member_with_email from community.www.courses.utils import get_member_with_email
from community.query import find, find_all
class LMSBatch(Document): class LMSBatch(Document):
def validate(self): def validate(self):
if not self.code: if not self.code:
self.generate_code() self.generate_code()
def generate_code(self): def generate_code(self):
short_code = frappe.db.get_value("LMS Course", self.course, "short_code") short_code = frappe.db.get_value("LMS Course", self.course, "short_code")
course_batches = frappe.get_all("LMS Batch",{"course":self.course}) course_batches = frappe.get_all("LMS Batch",{"course":self.course})
self.code = short_code + str(len(course_batches) + 1) self.code = short_code + str(len(course_batches) + 1)
def get_mentors(self):
mentors = []
memberships = frappe.get_all(
"LMS Batch Membership",
{"batch": self.name, "member_type": "Mentor"},
["member"])
member_names = [m['member'] for m in memberships]
return find_all("Community Member", name=["IN", member_names])
def is_member(self, email):
"""Checks if a person is part of a batch.
"""
member = find("Community Member", email=email)
return member and frappe.db.exists(
"LMS Batch Membership",
{"batch": self.name, "member": member.name})
@frappe.whitelist() @frappe.whitelist()
def get_messages(batch): def get_messages(batch):

View File

@@ -9,35 +9,37 @@ from frappe import _
class LMSBatchMembership(Document): class LMSBatchMembership(Document):
def validate(self): def validate(self):
self.validate_membership_in_same_batch() self.validate_membership_in_same_batch()
self.validate_membership_in_different_batch_same_course() self.validate_membership_in_different_batch_same_course()
def validate_membership_in_same_batch(self): def validate_membership_in_same_batch(self):
previous_membership = frappe.db.get_value("LMS Batch Membership", {"member": self.member, "batch": self.batch, "name": ["!=", self.name]}, ["member_type","member"], as_dict=1) 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: if previous_membership:
member_name = frappe.db.get_value("Community Member", self.member, "full_name") member_name = frappe.db.get_value("Community Member", self.member, "full_name")
frappe.throw(_("{0} is already a {1} of {2}").format(member_name, previous_membership.member_type, self.batch)) 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): def validate_membership_in_different_batch_same_course(self):
course = frappe.db.get_value("LMS Batch", self.batch, "course") course = frappe.db.get_value("LMS Batch", self.batch, "course")
previous_membership = frappe.get_all("LMS Batch Membership", {"member": self.member}, ["batch", "member_type"]) previous_membership = frappe.get_all("LMS Batch Membership", {"member": self.member}, ["batch", "member_type"])
for membership in previous_membership: for membership in previous_membership:
batch_course = frappe.db.get_value("LMS Batch", membership.batch, "course") 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"): 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") member_name = frappe.db.get_value("Community Member", self.member, "full_name")
frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch)) frappe.throw(_("{0} is already a {1} of {2} course through {3} batch").format(member_name, membership.member_type, course, membership.batch))
@frappe.whitelist() @frappe.whitelist()
def create_membership(batch, course, member=None, member_type="Student", role="Member"): def create_membership(batch, course=None, member=None, member_type="Student", role="Member"):
if not member: if not member:
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name") member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
frappe.get_doc({ frappe.get_doc({
"doctype": "LMS Batch Membership", "doctype": "LMS Batch Membership",
"batch": batch, "batch": batch,
"role": role, "role": role,
"member_type": member_type, "member_type": member_type,
"member": member "member": member
}).save(ignore_permissions=True) }).save(ignore_permissions=True)
course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["slug"]) if course:
return course_slug course_slug = frappe.db.get_value("LMS Course", {"title": course}, ["name"])
return course_slug
return "OK"

View File

@@ -2,7 +2,6 @@
"actions": [], "actions": [],
"allow_guest_to_view": 1, "allow_guest_to_view": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "field:title",
"creation": "2021-03-01 16:49:33.622422", "creation": "2021-03-01 16:49:33.622422",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
@@ -74,8 +73,8 @@
"is_published_field": "is_published", "is_published_field": "is_published",
"links": [ "links": [
{ {
"group": "Topics", "group": "Chapters",
"link_doctype": "LMS Topic", "link_doctype": "Chapter",
"link_fieldname": "course" "link_fieldname": "course"
}, },
{ {
@@ -89,7 +88,7 @@
"link_fieldname": "course" "link_fieldname": "course"
} }
], ],
"modified": "2021-04-21 14:45:41.658056", "modified": "2021-05-06 11:15:45.728976",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Course", "name": "LMS Course",

View File

@@ -6,11 +6,24 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
from ...utils import slugify from ...utils import slugify
from community.query import find, find_all
class LMSCourse(Document): class LMSCourse(Document):
def before_save(self): @staticmethod
if not self.slug: def find(name):
self.slug = self.generate_slug(title=self.title) """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): def generate_slug(self, title):
result = frappe.get_all( result = frappe.get_all(
@@ -20,7 +33,7 @@ class LMSCourse(Document):
return slugify(title, used_slugs=slugs) return slugify(title, used_slugs=slugs)
def __repr__(self): def __repr__(self):
return f"<Course#{self.name} {self.slug}>" return f"<Course#{self.name}>"
def get_topic(self, slug): def get_topic(self, slug):
"""Returns the topic with given slug in this course as a Document. """Returns the topic with given slug in this course as a Document.
@@ -50,7 +63,7 @@ class LMSCourse(Document):
"""Returns the name of Community Member document for a give user. """Returns the name of Community Member document for a give user.
""" """
try: try:
return frappe.db.get_value("Community Member", {"email": email}, ["name"]) return frappe.db.get_value("Community Member", {"email": email}, "name")
except frappe.DoesNotExistError: except frappe.DoesNotExistError:
return None return None
@@ -89,14 +102,49 @@ class LMSCourse(Document):
course_mentors.append(member) course_mentors.append(member)
return course_mentors return course_mentors
def get_instructor(self): def is_mentor(self, email):
return frappe.get_doc("User", self.owner) """Checks if given user is a mentor for this course.
@staticmethod
def find_all():
"""Returns all published courses.
""" """
rows = frappe.db.get_all("LMS Course", if not email:
filters={"is_published": True}, return False
fields='*') member = self.get_community_member(email)
return [frappe.get_doc(dict(row, doctype='LMS Course')) for row in rows] return frappe.db.exists({
"doctype": "LMS Course Mentor Mapping",
"course": self.name,
"mentor": member
})
def get_instructor(self):
member_name = self.get_community_member(self.owner)
return frappe.get_doc("Community Member", member_name)
def get_chapters(self):
"""Returns all chapters of this course.
"""
# TODO: chapters should have a way to specify the order
return find_all("Chapter", course=self.name, order_by="creation")
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
member = self.get_community_member(email=mentor)
memberships = frappe.db.get_all(
"LMS Batch Membership",
{"member": member},
["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

View File

@@ -24,7 +24,7 @@ class TestLMSCourse(unittest.TestCase):
def test_new_course(self): def test_new_course(self):
course = self.new_course("Test Course") course = self.new_course("Test Course")
assert course.title == "Test Course" assert course.title == "Test Course"
assert course.slug == "test-course" assert course.name == "test-course"
assert course.get_mentors() == [] assert course.get_mentors() == []
def test_find_all(self): def test_find_all(self):
@@ -41,7 +41,7 @@ class TestLMSCourse(unittest.TestCase):
# now we should find one course # now we should find one course
courses = LMSCourse.find_all() 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 # disabled this test as it is failing
def _test_add_mentors(self): def _test_add_mentors(self):

View File

@@ -1,12 +0,0 @@
frappe.ready(function() {
// bind events here
frappe.web_form.after_load = () => {
frappe.web_form.set_value(["batch"], [frappe.utils.get_url_arg('batch')]);
frappe.web_form.set_value(["author"], [frappe.utils.get_url_arg('author')]);
}
frappe.web_form.success_url = `courses/course?course=${frappe.utils.get_url_arg('course')}`;
$('.breadcrumb-container')
.html(`<a href="${frappe.web_form.success_url}">Back to my course</a>`)
.addClass('py-4');
})

View File

@@ -1,77 +0,0 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 0,
"allow_incomplete": 0,
"allow_multiple": 0,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 0,
"button_label": "Send",
"client_script": "",
"creation": "2021-03-23 13:10:16.814983",
"doc_type": "LMS Message",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2021-03-23 19:25:54.984968",
"modified_by": "Administrator",
"module": "LMS",
"name": "add-messages",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 0,
"route": "add-messages",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "",
"title": "Add Messages",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "batch",
"fieldtype": "Link",
"hidden": 0,
"label": "Batch",
"max_length": 0,
"max_value": 0,
"options": "LMS Batch",
"read_only": 1,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "message",
"fieldtype": "Data",
"hidden": 0,
"label": "Message",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "author",
"fieldtype": "Link",
"hidden": 1,
"label": "Author",
"max_length": 0,
"max_value": 0,
"options": "Community Member",
"read_only": 1,
"reqd": 0,
"show_in_filter": 0
}
]
}

View File

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

View File

@@ -0,0 +1,15 @@
<div class="chapter-teaser">
<div class="teaser-body">
<h3 class="chapter-title"><span class="chapter-number">{{index}}</span> {{ chapter.title }}</h3>
<div class="chapter-description">
{{ chapter.description or "" }}
</div>
<div class="chapter-lessons">
{% for lesson in chapter.get_lessons() %}
<div class="lesson-teaser">
{{lesson.title}}
</div>
{% endfor %}
</div>
</div>
</div>

View File

@@ -1,13 +1,13 @@
<div class="course-teaser"> <div class="course-teaser">
<div class="course-body"> <div class="course-body">
<h3 class="course-title"><a href="/courses/{{ course.slug }}">{{ course.title }}</a></h3> <h3 class="course-title"><a href="/courses/{{ course.name }}">{{ course.title }}</a></h3>
<div class="course-intro"> <div class="course-intro">
{{ course.short_introduction or "" }} {{ course.short_introduction or "" }}
</div> </div>
</div> </div>
<div class="course-footer"> <div class="course-footer">
<div class="course-author"> <div class="course-author">
{{ course.get_instructor().full_name }} <img class="course-author-avatar" src="{{ course.get_instructor().avatar }}" />{{ course.get_instructor().full_name }}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -4,22 +4,37 @@
</form> </form>
<script> <script>
frappe.ready(() => { frappe.ready(() => {
$("#submit-invite-request").click(function () { $("#submit-invite-request").click(function () {
frappe.call({ var invite_email = $("#invite_email").val()
method: "community.lms.doctype.invite_request.invite_request.create_invite_request", frappe.call({
args: { method: "community.lms.doctype.invite_request.invite_request.create_invite_request",
invite_email: $("#invite_email").val() args: {
}, invite_email: invite_email
callback: (data) => { },
if (data.message == "OK") { callback: (data) => {
$("#invite-request-form").hide(); $("#invite-request-form").hide();
var message = `<div>
<p class="lead">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p> if (data.message == "OK") {
</div>`; var message = `<div>
<p class="lead">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p>
</div>`;
}
else if (data.message == "invite") {
var message = `<div>
<p class="lead">Email ${invite_email} has already been used to request an invitation.</p>
</div>`;
}
else if (data.message == "user") {
var message = `<div>
<p class="lead">Looks like there is already an account with email ${invite_email}. Would you like to <a href="/login">login</a>.</p>
</div>`;
}
$(".jumbotron").append(message); $(".jumbotron").append(message);
} }
} })
}) })
}) })
})
</script> </script>

View File

@@ -3,8 +3,8 @@
"public/css/lms.css" "public/css/lms.css"
], ],
"css/community.css": [ "css/community.css": [
"public/css/vars.css",
"public/css/style.css", "public/css/style.css",
"public/css/vars.css",
"public/css/style.less" "public/css/style.less"
] ]
} }

View File

@@ -32,78 +32,10 @@
body { body {
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
background: white;
} }
.course-header {
margin-top: 20px;
padding: 20px;
background: var(--header-bg);
color: var(--header-color);
border-radius: 10px;
}
.course-header h1 { /* .course-details {
color: inherit;
}
.course-type {
text-transform: uppercase;
font-size: 1.0em;
color: var(--tag-color);
}
.sidebar {
background: var(--sidebar-bg);
margin: 20px 0px;
border-radius: 10px;
padding: 1px 20px 20px 20px;
color: var(--text-color);
}
.sidebar h3 {
margin-top: 20px;
color: var(--c2);
}
.sidebar-batch {
background: var(--sidebar-bg);
color: var(--text-color);
position: fixed;
left: 0;
height: 100%;
}
.sidebar-batch a {
padding: 16px 8px 8px 16px;
display: block;
}
.instructor {
padding: 10px;
}
.instructor-title {
font-weight: bold;
}
.instructor-subtitle {
font-size: 0.8em;
color: var(--text-color);
}
.sidebar .notice {
padding: 10px;
border-radius: 10px;
border: 1px dashed var(--text-color);
}
.sidebar .notice a {
color: inherit;
text-decoration: underline;
}
.course-details {
margin: 20px 0px; margin: 20px 0px;
} }
@@ -112,7 +44,7 @@ body {
font-size: 1.4em; font-size: 1.4em;
font-weight: bold; font-weight: bold;
margin: 20px 0px 10px 0px; margin: 20px 0px 10px 0px;
} } */
.chapter-plan { .chapter-plan {
border-radius: 10px; border-radius: 10px;
@@ -127,7 +59,7 @@ body {
font-weight: bold; font-weight: bold;
} }
.chapter-number { /* .chapter-number {
background: var(--text-color); background: var(--text-color);
color: white; color: white;
border-radius: 50%; border-radius: 50%;
@@ -140,7 +72,7 @@ body {
.chapter-description { .chapter-description {
margin: 20px 0px; margin: 20px 0px;
} } */
.lessons { .lessons {
padding-left: 20px; padding-left: 20px;
@@ -287,6 +219,13 @@ img.profile-photo {
} }
.message-section { .message-section {
margin-left: 5%; margin-left: 3%;
display: inline-block; display: inline-block;
width: 95%;
}
.display-4 {
color: #2D005A;
font-weight: 600;
line-height: 51px;
} }

View File

@@ -1,14 +1,33 @@
@primary-color: #08B74F; @primary-color: #08B74F;
@import url('https://rsms.me/inter/inter.css');
body {
font-family: "Inter", sans-serif;
}
h2 {
margin: 20px 0px;
color: black;
}
.teaser { .teaser {
background: white; background: white;
border-radius: 10px; border-radius: 9px;
border: 1px solid #ddd; border: 1px solid #C4C4C4;
.teaser-body {
padding: 20px;
}
.teaser-footer {
padding: 20px;
}
} }
.sketch-teaser { .sketch-teaser {
.teaser(); .teaser();
width: 220px; width: 220px;
margin-bottom: 30px;
margin-top: 30px;
svg { svg {
width: 200px; width: 200px;
@@ -18,8 +37,9 @@
padding: 10px; padding: 10px;
} }
.sketch-footer { .sketch-footer {
border-top: 1px solid#C4C4C4;
padding: 10px; padding: 10px;
background: #eee; background: #F6F6F6;
border-radius: 0px 0px 10px 10px; border-radius: 0px 0px 10px 10px;
} }
} }
@@ -27,6 +47,8 @@
.course-teaser { .course-teaser {
.teaser(); .teaser();
color: #444; color: #444;
margin-bottom: 20px;
margin-top: 20px;
h3, h4 { h3, h4 {
color: black; color: black;
@@ -57,17 +79,156 @@ section {
section h2 { section h2 {
margin-bottom: 40px; margin-bottom: 40px;
font-size: 48px;
line-height: 58px;
font-weight: bold;
} }
section.lightgray { section.lightgray {
background: #f8f8f8; background: #F6F6F6;
} }
#hero .jumbotron { #hero .jumbotron {
background: inherit; background: inherit;
} }
.chapter-teaser {
.teaser();
color: #444;
margin: 20px 0px;
h3, h4 {
color: black;
font-weight: bold;
}
}
.field-width { .field-width {
width: 40%; width: 40%;
display: inline-block; display: inline-block;
} }
.footer-grouped-links {
display: none;
}
.footer-info {
border-top: 0px;
margin-top: 0px;
.footer-col-right {
padding-top: 1.8rem;
}
}
.web-footer {
border-top: 1px solid #E2E6E9;
padding: 0px;
padding: 2rem 0px;
margin-top: 2rem;
}
.course-type {
text-transform: uppercase;
font-size: 1.0em;
font-weight: bold;
color: var(--tag-color);
}
.course-header {
margin-top: 20px;
}
/*
.course-header {
margin-top: 20px;
padding: 20px;
background: var(--header-bg);
color: var(--header-color);
border-radius: 9px;
}
.course-author-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 20px;
}
.course-header h1 {
color: inherit;
}
*/
// .gray-section {
// background:#F6F6F6;
// border: 1px solid #C4C4C4;
// padding: 20px;
// margin: 20px 0px;
// }
.instructor-title {
font-weight: bold;
color: black;
}
.instructor-subtitle {
font-size: 0.8em;
color: var(--text-color);
}
// .mentors-wrapper {
// .gray-section();
// }
.chapter-number {
background: var(--text-color);
color: white;
border-radius: 50%;
height: 24px;
min-width: 24px;
align-items: center;
padding: 5px 8px 2px 8px;
margin-right: 5px;
}
.sidebar {
background: var(--sidebar-bg);
border: 1px solid var(--sidebar-border);
margin: 20px 0px;
border-radius: 10px;
padding: 1px 20px 20px 20px;
}
.sidebar h3 {
margin-top: 20px;
color: black;
}
.sidebar-batch {
background: var(--sidebar-bg);
color: var(--text-color);
position: fixed;
left: 0;
height: 100%;
}
.sidebar-batch a {
padding: 16px 8px 8px 16px;
display: block;
}
.sidebar .notice {
margin-top: 10px;
padding: 10px;
border-radius: 10px;
border: 1px dashed var(--text-color);
}
.sidebar .notice a {
color: inherit;
text-decoration: underline;
}

View File

@@ -1,4 +1,7 @@
/* Define all your css variables here. */ /* Define all your css variables here. */
:root { :root {
--primary-color: #08B74F; --primary-color: #08B74F;
--tag-color: #737373;
--sidebar-bg: #F6F6F6;
--sidebar-border: #C4C4C4;
} }

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="104px" height="81px" viewBox="0 0 104 81" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 61.2 (89653) - https://sketch.com -->
<title>Group 2</title>
<desc>Created with Sketch.</desc>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="site" transform="translate(-160.803147, -89.000000)">
<g id="Group-2" transform="translate(163.323899, 91.260768)">
<g id="g1593" transform="translate(10.217829, 8.684369)" fill="black" fill-rule="nonzero">
<g id="text1571" transform="translate(0.248104, 0.000000)">
<polygon id="path1919" points="6.20610364 30.6588166 0.0881167018 30.6588166 0.0881167018 0.711614981 15.1331308 0.711614981 15.1331308 6.82960641 6.20610364 6.82960641 6.20610364 12.6143164 15.1331308 12.6143164 15.1331308 18.7323078 6.20610364 18.7323078"></polygon>
<path d="M24.0601557,24.5170177 L29.8448702,24.5170177 L29.8448702,6.82960641 L24.0601557,6.82960641 L24.0601557,24.5170177 Z M20.917843,30.6588166 L20.917843,27.6593507 L17.9421688,27.6593507 L17.9421688,3.68729595 L20.917843,3.68729595 L20.917843,0.711614981 L32.9871829,0.711614981 L32.9871829,3.68729595 L35.9628571,3.68729595 L35.9628571,27.6593507 L32.9871829,27.6593507 L32.9871829,30.6588166 L20.917843,30.6588166 Z M18.108805,0.806844685 L20.917843,0.806844685 L20.917843,3.68729595 L18.108805,3.68729595 L18.108805,0.806844685 Z M32.9871829,0.711525057 L35.9628571,0.711525057 L35.9628571,3.68720602 L32.9871829,3.68720602 L32.9871829,0.711525057 Z M32.9871829,27.6592608 L35.9628571,27.6592608 L35.9628571,30.5635195 L32.9871829,30.5635195 L32.9871829,27.6592608 Z M17.9421688,27.6592608 L20.917843,27.6592608 L20.917843,30.6587267 L17.9421688,30.6587267 L17.9421688,27.6592608 Z" id="path1921"></path>
<path d="M53.8169092,30.6588166 L38.7718951,30.6588166 L38.7718951,24.5170177 L50.6745942,24.5170177 L50.6745942,18.7323078 L41.7475693,18.7323078 L41.7475693,15.7566493 L38.7718951,15.7566493 L38.7718951,3.68729595 L41.7475693,3.68729595 L41.7475693,0.711614981 L56.7925834,0.711614981 L56.7925834,6.82960641 L44.889882,6.82960641 L44.889882,12.6143164 L53.8169092,12.6143164 L53.8169092,15.5899973 L56.7925834,15.5899973 L56.7925834,27.6593507 L53.8169092,27.6593507 L53.8169092,30.6588166 Z M38.9385313,0.806844685 L41.7475693,0.806844685 L41.7475693,3.68729595 L38.9385313,3.68729595 L38.9385313,0.806844685 Z M38.7719018,15.7566493 L41.747576,15.7566493 L41.747576,18.7323078 L38.7719018,18.7323078 L38.7719018,15.7566493 Z M53.8169159,12.6143164 L56.7925901,12.6143164 L56.7925901,15.5899973 L53.8169159,15.5899973 L53.8169159,12.6143164 Z M53.8169159,27.6593507 L56.7925901,27.6593507 L56.7925901,30.5636094 L53.8169159,30.5636094 L53.8169159,27.6593507 Z" id="path1923"></path>
<path d="M74.64664,30.6588166 L59.6016259,30.6588166 L59.6016259,24.5170177 L71.5043273,24.5170177 L71.5043273,18.7323078 L62.5773023,18.7323078 L62.5773023,15.7566493 L59.6016259,15.7566493 L59.6016259,3.68729595 L62.5773023,3.68729595 L62.5773023,0.711614981 L77.6223164,0.711614981 L77.6223164,6.82960641 L65.7196151,6.82960641 L65.7196151,12.6143164 L74.64664,12.6143164 L74.64664,15.5899973 L77.6223164,15.5899973 L77.6223164,27.6593507 L74.64664,27.6593507 L74.64664,30.6588166 Z M59.7682644,0.806844685 L62.5773023,0.806844685 L62.5773023,3.68729595 L59.7682644,3.68729595 L59.7682644,0.806844685 Z M59.6016349,15.7566493 L62.5773113,15.7566493 L62.5773113,18.7323078 L59.6016349,18.7323078 L59.6016349,15.7566493 Z M74.646649,12.6143164 L77.6223254,12.6143164 L77.6223254,15.5899973 L74.646649,15.5899973 L74.646649,12.6143164 Z M74.646649,27.6593507 L77.6223254,27.6593507 L77.6223254,30.5636094 L74.646649,30.5636094 L74.646649,27.6593507 Z" id="path1925"></path>
</g>
<g id="text1575" transform="translate(0.127883, 35.473579)">
<path d="M2.35734791,22.5432945 L2.35734791,20.3720424 L0.206884567,20.3720424 L0.206884567,0.865355398 L4.62823747,0.865355398 L4.62823747,18.0974048 L8.80873794,18.0974048 L8.80873794,0.865355398 L13.2300908,0.865355398 L13.2300908,20.3720424 L11.0796275,20.3720424 L11.0796275,22.5432945 L2.35734791,22.5432945 Z M0.206884567,20.3720424 L2.35734791,20.3720424 L2.35734791,22.5432945 L0.206884567,22.5432945 L0.206884567,20.3720424 Z M11.0796275,20.3720424 L13.2300908,20.3720424 L13.2300908,22.4743558 L11.0796275,22.4743558 L11.0796275,20.3720424 Z" id="path1928"></path>
<polygon id="path1930" points="19.6814809 22.5432945 15.260128 22.5432945 15.260128 0.865355398 28.2833343 0.865355398 28.2833343 22.5432945 23.8619814 22.5432945 23.8619814 5.29401037 19.6814809 5.29401037"></polygon>
<polygon id="path1932" points="34.7347243 22.5432945 30.3133714 22.5432945 30.3133714 0.865355398 34.7347243 0.865355398"></polygon>
<polygon id="path1934" points="45.4870433 22.5432945 41.0656904 22.5432945 41.0656904 5.29401037 36.7647637 5.29401037 36.7647637 0.865355398 49.7879699 0.865355398 49.7879699 5.29401037 45.4870433 5.29401037"></polygon>
<polygon id="path1936" points="62.6907478 22.5432945 51.8180048 22.5432945 51.8180048 0.865355398 62.6907478 0.865355398 62.6907478 5.29401037 56.2393577 5.29401037 56.2393577 9.48138012 62.6907478 9.48138012 62.6907478 13.9100351 56.2393577 13.9100351 56.2393577 18.0974048 62.6907478 18.0974048"></polygon>
<path d="M69.1421378,18.0974048 L73.3226383,18.0974048 L73.3226383,5.29401037 L69.1421378,5.29401037 L69.1421378,18.0974048 Z M64.7207849,22.5432945 L64.7207849,0.865355398 L75.5935278,0.865355398 L75.5935278,3.01937283 L77.7439912,3.01937283 L77.7439912,20.3720424 L75.5935278,20.3720424 L75.5935278,22.5432945 L64.7207849,22.5432945 Z" id="path1938"></path>
</g>
</g>
<rect id="rect1579" stroke="black" stroke-width="3.99998745" x="0" y="0" width="98.6425638" height="76.0972583"></rect>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

22
community/query.py Normal file
View File

@@ -0,0 +1,22 @@
"""Utilities to find docs.
"""
import frappe
def find_all(doctype, order_by=None, **filters):
"""Queries the database for documents of a doctype matching given filters.
"""
rows = frappe.db.get_all(doctype,
filters=filters,
fields='*',
order_by=order_by)
return [frappe.get_doc(dict(row, doctype=doctype)) for row in rows]
def find(doctype, **filters):
"""Queries the database for a document of given doctype matching given filters.
"""
rows = frappe.db.get_all(doctype,
filters=filters,
fields='*')
if rows:
row = rows[0]
return frappe.get_doc(dict(row, doctype=doctype))

View File

@@ -0,0 +1,14 @@
<div class="footer-info">
<div class="row">
<div class="footer-col-left col-sm-6 col-12">
<img src="/assets/community/images/fossunited-logo.svg" style="width: 50px;">
</div>
{# powered #}
<div class="footer-col-right col-sm-6 col-12 footer-powered">
{% block powered %}
{% include "templates/includes/footer/footer_powered.html" %}
{% endblock %}
</div>
</div>
</div>

View File

@@ -0,0 +1,12 @@
<div class="footer-logo-extension">
<div class="row">
<div class="text-left col-6">
<h3>Mon School</h3>
</div>
<div class="text-right col-6">
{% block extension %}
{% include "templates/includes/footer/footer_extension.html" %}
{% endblock %}
</div>
</div>
</div>

View File

@@ -14,7 +14,8 @@ from frappe.utils.jinja import get_jenv
# When {{widgets.SomeWidget()}} is called, it looks for # When {{widgets.SomeWidget()}} is called, it looks for
# widgets/SomeWidgets.html in each of these modules. # widgets/SomeWidgets.html in each of these modules.
MODULES = [ MODULES = [
"lms" "lms",
"community"
] ]
def update_website_context(context): def update_website_context(context):

View File

@@ -9,19 +9,16 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course_slug, batch_code) }} {{ Sidebar(course.name, batch.name) }}
<div class="container"> <div class="container">
{{ CourseBasicDetail(course)}} {{ CourseBasicDetail(course)}}
{{ InstructorsSection(instructor) }} {{ InstructorsSection(course.get_instructor()) }}
{% if batch.description %} {{ BatchDetails(batch)}}
{{ BatchDetails(batch.description) }}
{% endif %}
{{ MentorsSection(mentors, True) }}
</div> </div>
{% endblock %} {% endblock %}
{% macro CourseBasicDetail(course) %} {% macro CourseBasicDetail(course) %}
<h2>{{course.name}}</h2> <h2>{{course.title}}</h2>
<div class="course-description"> <div class="course-description">
{{course.short_introduction}} {{course.short_introduction}}
</div> </div>
@@ -36,11 +33,25 @@
<div>{{frappe.utils.md_to_html(course.description)}}</div> <div>{{frappe.utils.md_to_html(course.description)}}</div>
{% endmacro %} {% endmacro %}
{% macro BatchDetails(description) %} {% macro BatchDetails(batch) %}
<div class="mt-5"> <h2>About the Batch</h2>
<h3>About the Batch</h3>
<div> <div class="batch">
{{ frappe.utils.md_to_html(description) }} <div class="batch-details">
</div> <div>Session every {{batch.sessions_on}}</div>
<div>{{frappe.utils.format_time(batch.start_time, "short")}} -
{{frappe.utils.format_time(batch.end_time, "short")}}</div>
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
{% for m in batch.get_mentors() %}
<div>
{% if m.photo_url %}
<img class="profile-photo" src="{{m.photo_url}}">
{% endif %}
<span class="instructor-title">{{m.full_name}}</span>
</div>
{% endfor %}
</div>
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -1,23 +1,21 @@
import frappe import frappe
from community.www.courses.utils import redirect_if_not_a_member, get_course, get_instructor, get_batch from community.lms.models import Course
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
context.course_slug = frappe.form_dict["course"]
context.course = get_course(context.course_slug)
context.batch_code = frappe.form_dict["batch"]
redirect_if_not_a_member(context.course_slug, context.batch_code)
context.instructor = get_instructor(context.course.owner) course_name = frappe.form_dict["course"]
context.batch = get_batch(context.batch_code) batch_name = frappe.form_dict["batch"]
context.mentors = get_mentors(context.batch.name)
print(context.mentors)
def get_mentors(batch): course = Course.find(course_name)
mentors = [] if not course:
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"]) context.template = "www/404.html"
for membership in memberships: return
member = frappe.db.get_value("Community Member", membership.member, ["name","full_name"], as_dict=True)
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"})) batch = course.get_batch(batch_name)
mentors.append(member) if not batch:
return mentors frappe.local.flags.redirect_location = "/courses/" + course_name
raise frappe.Redirect
context.course = course
context.batch = batch

View File

@@ -10,39 +10,33 @@
<div class="container"> <div class="container">
<div class="course-header"> <div class="course-header">
<div class="course-type">course</div> <div class="course-type">course</div>
<h1>{{course.title}}</h1> <h1 id="course-title" data-course="{{course.name}}">{{course.title}}</h1>
<div class="course-short-intro">{{ course.short_introduction }}</div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-9 col-md-12"> <div class="col-lg-8 col-md-12">
<div class="course-details"> <div class="course-details">
{{ CourseVideo(course) }}
{{ CourseDescription(course) }} {{ CourseDescription(course) }}
{{ BatchSection(course, is_mentor, upcoming_batches, mentor_batches) }} {{ BatchSection(course) }}
{{ CourseOutline(course) }} {{ CourseOutline(course) }}
</div> </div>
</div> </div>
<div class="col-lg-4 col-md-12">
<div class="col-lg-3 col-md-12">
<div class="sidebar"> <div class="sidebar">
{{ InstructorsSection(instructor) }} {{ InstructorsSection(course.get_instructor()) }}
</div> </div>
<div class="sidebar"> <div class="sidebar">
{{ MentorsSection(mentors, is_mentor) }} {{ MentorsSection(course.get_mentors(), course.is_mentor(frappe.session.user), course.name) }}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% macro CourseVideo(course) %}
{% macro CourseDescription(course) %}
<h2>Course Description</h2>
<div class="course-description">
{{ course.short_introduction }}
</div>
{% if course.video_link %} {% if course.video_link %}
<div class="preview-video"> <div class="preview-video">
<iframe <iframe
@@ -57,11 +51,19 @@
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro BatchSection(course, is_mentor, upcoming_batches, mentor_batches) %} {% macro CourseDescription(course) %}
{% if is_mentor %} <h2>Course Description</h2>
{{ BatchSectionForMentors(course, mentor_batches) }}
<div class="course-description">
{{ course.short_introduction }}
</div>
{% endmacro %}
{% macro BatchSection(course) %}
{% if course.is_mentor(frappe.session.user) %}
{{ BatchSectionForMentors(course, course.get_batches(mentor=frappe.session.user)) }}
{% else %} {% else %}
{{ BatchSectionForStudents(course, upcoming_batches) }} {{ BatchSectionForStudents(course, course.get_upcoming_batches()) }}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@@ -74,11 +76,9 @@
<div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div> <div>Starting {{frappe.utils.format_date(batch.start_date, "medium")}}</div>
<div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div> <div class="course-type" style="color: #888; padding: 10px 0px;">mentors</div>
{% for m in batch.mentors %} {% for m in batch.get_mentors() %}
<div> <div>
{% if m.photo_url %} {{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
<img class="profile-photo" src="{{m.photo_url}}">
{% endif %}
<span class="instructor-title">{{m.full_name}}</span> <span class="instructor-title">{{m.full_name}}</span>
</div> </div>
{% endfor %} {% endfor %}
@@ -86,9 +86,9 @@
<div class="cta"> <div class="cta">
<div class=""> <div class="">
{% if can_manage %} {% if can_manage %}
<button type="button">Manage</button> <a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
{% else %} {% else %}
<button type="button">Join this Batch</button> <button class="join-batch" data-batch="{{ batch.name | urlencode }}">Join this Batch</button>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@@ -111,11 +111,11 @@
{% endfor %} {% endfor %}
</div> </div>
<a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.name}}">Add a new batch</a> <a class="btn btn-primary add-batch margin-bottom" href="/add-a-new-batch?new=1&course={{course.title}}">Add a new batch</a>
{% else %} {% else %}
<div class="mentor_message"> <div class="mentor_message">
<p> You are a mentor for this course. </p> <p> You are a mentor for this course. </p>
<a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.name}}" >Create your first batch</a> <a class="btn btn-primary" href="/add-a-new-batch?new=1&course={{course.title}}" >Create your first batch</a>
</div> </div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@@ -123,33 +123,19 @@
{% macro BatchSectionForStudents(course, upcoming_batches) %} {% macro BatchSectionForStudents(course, upcoming_batches) %}
<h2>Upcoming Batches</h2> <h2>Upcoming Batches</h2>
{% for batch in upcoming_batches %} <div class="row">
<div class="col-lg-4 col-md-6"> {% for batch in upcoming_batches %}
{{ RenderBatch(batch, can_manage=False) }} <div class="col-lg-4 col-md-6">
{{ RenderBatch(batch, can_manage=False) }}
</div>
{% endfor %}
</div> </div>
{% endfor %}
{% endmacro %} {% endmacro %}
{% macro CourseOutline(course) %} {% macro CourseOutline(course) %}
<h2>Course Outline</h2> <h2>Course Outline</h2>
{% for chapter in course.topics %} {% for chapter in course.get_chapters() %}
<div class="chapter-plan"> {{ widgets.ChapterTeaser(index=loop.index, chapter=chapter)}}
<h3><span class="chapter-number">{{loop.index}}</span> {{chapter.title}}</h3> {% endfor %}
<div class="chapter-description">
{{chapter.preview | markdown}}
</div>
{#
<div class="lessons">
{% for lesson in chapter.lessons %}
<div class="lesson">
<span class="lesson-type"><i class="{{lesson.icon}}"></i></span>
<span class="lesson-title">{{lesson.title}}</span>
</div>
{% endfor %}
</div>
#}
</div>
{% endfor %}
{% endmacro %} {% endmacro %}

View File

@@ -3,18 +3,19 @@ frappe.ready(() => {
frappe.call({ frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested', 'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
'args': { 'args': {
course: decodeURIComponent($(".course-title").attr("data-course")), course: decodeURIComponent($("#course-title").attr("data-course")),
}, },
'callback': (data) => { 'callback': (data) => {
if (data.message) { if (data.message) {
$(".mentor-request").addClass("hide"); $("#mentor-request").addClass("hide");
$(".already-applied").removeClass("hide") $("#already-applied").removeClass("hide")
} }
} }
}) })
} }
$(".apply-now").click((e) => { $("#apply-now").click((e) => {
e.preventDefault();
if (frappe.session.user == "Guest") { if (frappe.session.user == "Guest") {
window.location.href = "/login"; window.location.href = "/login";
return; return;
@@ -26,14 +27,15 @@ frappe.ready(() => {
}, },
"callback": (data) => { "callback": (data) => {
if (data.message == "OK") { if (data.message == "OK") {
$(".mentor-request").addClass("hide"); $("#mentor-request").addClass("hide");
$(".already-applied").removeClass("hide") $("#already-applied").removeClass("hide")
} }
} }
}) })
}) })
$(".cancel-request").click((e) => { $("#cancel-request").click((e) => {
e.preventDefault()
frappe.call({ frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request", "method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
"args": { "args": {
@@ -41,14 +43,15 @@ frappe.ready(() => {
}, },
"callback": (data) => { "callback": (data) => {
if (data.message == "OK") { if (data.message == "OK") {
$(".mentor-request").removeClass("hide"); $("#mentor-request").removeClass("hide");
$(".already-applied").addClass("hide") $("#already-applied").addClass("hide")
} }
} }
}) })
}) })
$(".join-batch").click((e) => { $(".join-batch").click((e) => {
e.preventDefault()
if (frappe.session.user == "Guest") { if (frappe.session.user == "Guest") {
window.location.href = "/login"; window.location.href = "/login";
return; return;
@@ -62,7 +65,6 @@ frappe.ready(() => {
"callback": (data) => { "callback": (data) => {
if (data.message == "OK") { if (data.message == "OK") {
frappe.msgprint(__("You are now a student of this course.")) frappe.msgprint(__("You are now a student of this course."))
$(".upcoming-batches").addClass("hide")
} }
} }
}) })

View File

@@ -1,101 +1,21 @@
import frappe import frappe
from community.www.courses.utils import get_instructor from community.www.courses.utils import get_instructor
from frappe.utils import nowdate, getdate from frappe.utils import nowdate, getdate
from community.lms.models import Course
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
try: try:
course_id = frappe.form_dict["course"] course_name = frappe.form_dict["course"]
except KeyError: except KeyError:
frappe.local.flags.redirect_location = "/courses" frappe.local.flags.redirect_location = "/courses"
raise frappe.Redirect raise frappe.Redirect
context.course = get_course(course_id) course = Course.find(course_name)
context.batches = get_course_batches(context.course.name) if course is None:
context.is_mentor = is_mentor(context.course.name) frappe.local.flags.redirect_location = "/courses"
context.memberships = get_membership(context.batches)
if len(context.memberships) and not context.is_mentor:
frappe.local.flags.redirect_location = "/courses/" + course_id + "/" + context.memberships[0].code + "/learn"
raise frappe.Redirect raise frappe.Redirect
context.upcoming_batches = get_upcoming_batches(context.course.name)
context.instructor = get_instructor(context.course.owner)
context.mentors = get_mentors(context.course.name)
if context.is_mentor: context.course = course
context.mentor_batches = get_mentor_batches(context.memberships) # Your Bacthes for mentor
def get_course(slug):
course = frappe.db.get_value("LMS Course", {"slug": slug},
["name", "slug", "title", "description", "short_introduction", "video_link", "owner"], as_dict=1)
course["topics"] = frappe.db.get_all("LMS Topic",
filters={
"course": course["name"]
},
fields=["name", "slug", "title", "preview"],
order_by="creation"
)
return course
def get_upcoming_batches(course):
batches = frappe.get_all("LMS Batch", {"course": course, "start_date": [">", nowdate()]}, ["start_date", "start_time", "end_time", "sessions_on", "name"])
batches = get_batch_mentors(batches)
return batches
def get_batch_mentors(batches):
for batch in batches:
batch.mentors = []
mentors = frappe.get_all("LMS Batch Membership", {"batch": batch.name, "member_type": "Mentor"}, ["member"])
for mentor in mentors:
member = frappe.db.get_value("Community Member", mentor.member, ["full_name", "photo", "abbr"], as_dict=1)
batch.mentors.append(member)
return batches
def get_membership(batches):
memberships = []
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, "name")
for batch in batches:
membership = frappe.db.get_value("LMS Batch Membership", {"member": member, "batch": batch.name}, ["batch", "member", "member_type"], as_dict=1)
if membership:
membership.code = batch.code
memberships.append(membership)
return memberships
def get_mentors(course):
course_mentors = []
mentors = frappe.get_all("LMS Course Mentor Mapping", {"course": course}, ["mentor"])
for mentor in mentors:
member = frappe.get_doc("Community Member", mentor.mentor)
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
course_mentors.append(member)
return course_mentors
def get_course_batches(course):
return frappe.get_all("LMS Batch", {"course": course}, ["name", "code"])
def get_mentor_batches(memberships):
mentor_batches = []
memberships_as_mentor = list(filter(lambda x: x.member_type == "Mentor", memberships))
for membership in memberships_as_mentor:
batch = frappe.get_doc("LMS Batch", membership.batch)
mentor_batches.append(batch)
for batch in mentor_batches:
if getdate(batch.start_date) < getdate():
batch.status = "active"
batch.badge_class = "green_badge"
else:
batch.status = "scheduled"
batch.badge_class = "yellow_badge"
mentor_batches = get_batch_mentors(mentor_batches)
return mentor_batches
def is_mentor(course):
try:
member = frappe.db.get_value("Community Member", {"email": frappe.session.user}, ["name"])
except frappe.DoesNotExistError:
return False
mapping = frappe.get_all("LMS Course Mentor Mapping", {"course": course, "mentor": member})
if len(mapping):
return True

View File

@@ -26,11 +26,11 @@
{% macro course_card(course) %} {% macro course_card(course) %}
<div class="card mb-5 w-100"> <div class="card mb-5 w-100">
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><a href="/courses/{{course.slug}}">{{course.title}}</a></h5> <h5 class="card-title"><a href="/courses/{{course.name}}">{{course.title}}</a></h5>
{% if course.description %} {% if course.description %}
<p class="card-text">{{ frappe.utils.md_to_html(course.description[:250]) }}</p> <p class="card-text">{{ frappe.utils.md_to_html(course.description[:250]) }}</p>
{% endif %} {% endif %}
<a href="/courses/{{course.slug}}" class="card-link">See more &rarr;</a> <a href="/courses/{{course.name}}" class="card-link">See more &rarr;</a>
</div> </div>
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -7,7 +7,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{{ Sidebar(course, batch_code) }} {{ Sidebar(course.name, batch.name) }}
<div class="container"> <div class="container">
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -1,10 +1,21 @@
import frappe import frappe
from community.www.courses.utils import redirect_if_not_a_member from community.lms.models import Course
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
context.course = frappe.form_dict["course"]
context.batch_code = frappe.form_dict["batch"]
redirect_if_not_a_member(context.course, context.batch_code)
print(context) course_name = frappe.form_dict["course"]
batch_name = frappe.form_dict["batch"]
course = Course.find(course_name)
if not course:
context.template = "www/404.html"
return
batch = course.get_batch(batch_name)
if not batch:
frappe.local.flags.redirect_location = "/courses/" + course_name
raise frappe.Redirect
context.course = course
context.batch = batch

View File

@@ -14,12 +14,14 @@ def get_member_with_name(name):
def get_batch(code): def get_batch(code):
try: try:
return frappe.db.get_value("LMS Batch", {"code": code}, ["name", "description"], as_dict=True) print("get_batch", code)
return frappe.db.get_value("LMS Batch", {"name": code}, ["name", "description"], as_dict=True)
except frappe.DoesNotExistError: except frappe.DoesNotExistError:
print("Error: notfound")
return return
def is_member_of_batch(batch_code): def is_member_of_batch(batch_code):
membership = frappe.get_all("LMS Batch Membership", {"batch": get_batch(batch_code).name, "member": get_member_with_email()}) membership = frappe.get_all("LMS Batch Membership", {"batch": batch_code, "member": get_member_with_email()})
if len(membership): if len(membership):
return True return True
return False return False
@@ -29,9 +31,9 @@ def redirect_if_not_a_member(course,batch_code):
frappe.local.flags.redirect_location = "/courses/" + course frappe.local.flags.redirect_location = "/courses/" + course
raise frappe.Redirect raise frappe.Redirect
def get_course(slug): def get_course(name):
try: try:
return frappe.get_doc("LMS Course", {"slug": slug}) return frappe.get_doc("LMS Course", {"name": name})
except frappe.DoesNotExistError: except frappe.DoesNotExistError:
return return

View File

@@ -182,8 +182,8 @@
{% for course in courses %} {% for course in courses %}
<div class="dashboard__course"> <div class="dashboard__course">
<div class="dashboard__courseHeader"> <div class="dashboard__courseHeader">
<a class="text-decoration-none" target="_blank" href="/courses/{{course.slug}}"> <a class="text-decoration-none" target="_blank" href="/courses/{{course.name}}">
<h5 class="w-75">{{ course.name }}</h5> <h5 class="w-75">{{ course.title }}</h5>
</a> </a>
{% if course.member_type %} {% if course.member_type %}
<div class="dashboard__badge"> <div class="dashboard__badge">

View File

@@ -1,38 +1,42 @@
import frappe import frappe
from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches from community.lms.models import Sketch
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
context.member = frappe.get_all("Community Member", {"email": frappe.session.user}, ["name", "email", "photo", "full_name", "abbr"])[0] if frappe.session.user == "Guest":
context.memberships = get_memberships(context.member.name) frappe.local.flags.redirect_location = "/login"
context.courses = get_courses(context.memberships) raise frappe.Redirect
context.activity = get_activity(context.memberships) context.member = frappe.get_all("Community Member", {"email": frappe.session.user}, ["name", "email", "photo", "full_name", "abbr"])[0]
context.sketches = list(filter(lambda x: x.owner == frappe.session.user, get_recent_sketches())) context.memberships = get_memberships(context.member.name)
context.courses = get_courses(context.memberships)
context.activity = get_activity(context.memberships)
context.sketches = list(filter(lambda x: x.owner == frappe.session.user, Sketch.get_recent_sketches(owner=context.member.email)))
def get_memberships(member): def get_memberships(member):
return frappe.get_all("LMS Batch Membership", {"member": member}, ["batch", "member_type", "creation"]) return frappe.get_all("LMS Batch Membership", {"member": member}, ["batch", "member_type", "creation"])
def get_courses(memberships): def get_courses(memberships):
courses = [] courses = []
for membership in memberships: for membership in memberships:
course = frappe.db.get_value("LMS Batch", membership.batch, "course") course = frappe.db.get_value("LMS Batch", membership.batch, "course")
course_details = frappe.get_doc("LMS Course", course) course_details = frappe.get_doc("LMS Course", course)
course_in_list = list(filter(lambda x: x.name == course_details.name, courses)) course_in_list = list(filter(lambda x: x.name == course_details.name, courses))
if not len(course_in_list): if not len(course_in_list):
course_details.description = course_details.description[0:100] + "..." course_details.description = course_details.description[0:100] + "..."
course_details.joining = membership.creation course_details.joining = membership.creation
if membership.member_type != "Student": if membership.member_type != "Student":
course_details.member_type = membership.member_type course_details.member_type = membership.member_type
courses.append(course_details) courses.append(course_details)
return courses return courses
def get_activity(memberships): def get_activity(memberships):
messages, courses = [], {} messages, courses = [], {}
batches = [x.batch for x in memberships] batches = [x.batch for x in memberships]
for batch in batches: for batch in batches:
courses[batch] = frappe.db.get_value("LMS Batch", batch, "course") courses[batch] = frappe.db.get_value("LMS Batch", batch, "course")
messages = frappe.get_all("LMS Message", {"batch": ["in", ",".join(batches)]}, ["message", "author", "creation", "batch"], order_by='creation desc') messages = frappe.get_all("LMS Message", {"batch": ["in", ",".join(batches)]}, ["message", "author", "creation", "batch"], order_by='creation desc')
for message in messages: for message in messages:
message.course = courses[message.batch] message.course = courses[message.batch]
message.profile, message.full_name, message.abbr = frappe.db.get_value("Community Member", message.author, ["photo", "full_name", "abbr"]) message.profile, message.full_name, message.abbr = frappe.db.get_value("Community Member", message.author, ["photo", "full_name", "abbr"])
return messages return messages

View File

@@ -10,7 +10,7 @@
<section id="hero"> <section id="hero">
<div class="container"> <div class="container">
<div class="jumbotron"> <div class="jumbotron">
<h1 class="display-4">Guided online courses, with a mentor at your back.</h1> <h1 class="display-4">Guided online courses, with a <br />mentor at your back.</h1>
<p class="lead">Hands-on online courses designed by experts, delivered by passionate mentors.</p> <p class="lead">Hands-on online courses designed by experts, delivered by passionate mentors.</p>
{{ widgets.RequestInvite() }} {{ widgets.RequestInvite() }}
</div> </div>

View File

@@ -1,32 +1,37 @@
{% macro InstructorsSection(instructor) %} {% macro InstructorsSection(instructor) %}
<h3>Instructor</h3> <h3>Instructor</h3>
<div class="instructor"> <div class="instructor">
<div class="instructor-title">{{instructor.full_name}}</div> <div class="instructor-title">{{instructor.full_name}}</div>
<div class="instructor-subtitle">Created {{instructor.course_count}} courses</div> <div class="instructor-subtitle">Created {{instructor.get_course_count()}} courses</div>
</div> </div>
{% endmacro %} {% endmacro %}
{% macro MentorsSection(mentors, is_mentor) %} {% macro MentorsSection(mentors, is_mentor, course_name) %}
<h3>Mentors</h3> <h3>Mentors</h3>
{% for m in mentors %} {% for m in mentors %}
<div class="instructor"> <div class="instructor">
<div class="instructor-title">{{m.full_name}}</div> <div class="instructor-title">{{m.full_name}}</div>
<div class="instructor-subtitle">Mentored {{m.batch_count}} batches</div> <div class="instructor-subtitle">Mentored {{m.get_batch_count()}} batches</div>
</div> </div>
{% endfor %} {% endfor %}
{% if not is_mentor %} {% if not is_mentor %}
<div class="notice"> <div id="mentor-request" class="notice">
Interested to become a mentor? Interested to become a mentor?
<div><a href="#">Apply Now!</a></div> <div><a id="apply-now" data-course="{{course_name | urlencode}}" href="">Apply Now!</a></div>
</div> </div>
{% endif %} <div id="already-applied" class="notice hide">
You've applied to become a mentor for this course. Your request is currently under review.
If you are not any more interested to mentor this course, you can <a id="cancel-request" data-course="{{course_name | urlencode}}" href="">cancel your application</a>.
</div>
{% endif %}
{% endmacro %} {% endmacro %}
{% macro BatchHearder(course_name, member_count) %} {% macro BatchHearder(course_name, member_count) %}
<div class="border p-3"> <div class="border p-3">
<h3>{{course_name}}</h3> <h3>{{course_name}}</h3>
<div class="text-muted">{{member_count}} members</div> <div class="text-muted">{{member_count}} members</div>
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -1,5 +1,5 @@
import frappe import frappe
from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches from community.lms.models import Sketch
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
@@ -8,7 +8,7 @@ def get_context(context):
if not context.member: if not context.member:
context.template = "www/404.html" context.template = "www/404.html"
else: else:
context.sketches = list(filter(lambda x: x.owner == context.member.email, get_recent_sketches())) context.sketches = Sketch.get_recent_sketches(owner=context.member.email)
def get_member(username): def get_member(username):
try: try:

View File

@@ -1 +1 @@
License: MIT License: AGPL