Compare commits

..

16 Commits

Author SHA1 Message Date
pateljannat
45ec16d9e4 fix: reverted error message 2021-05-04 17:43:09 +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
34 changed files with 507 additions and 373 deletions

View File

@@ -11,54 +11,71 @@ import random
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 __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

@@ -136,7 +136,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 +163,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]

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):
@@ -55,6 +55,7 @@ def create_invite_request(invite_email):
except frappe.UniqueValidationError: except frappe.UniqueValidationError:
frappe.throw(_("Email {0} has already been used to request an invite").format(invite_email)) 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):
data = frappe._dict(json.loads(data)) if type(data) == str else frappe._dict(data) data = frappe._dict(json.loads(data)) if type(data) == str else frappe._dict(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

@@ -8,14 +8,25 @@ 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
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"])
for membership in memberships:
member = frappe.db.get_value("Community Member", membership.member, ["full_name", "photo", "abbr"], as_dict=1)
mentors.append(member)
return mentors
@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}, ["slug"])
return course_slug
return "OK"

View File

@@ -74,8 +74,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 +89,7 @@
"link_fieldname": "course" "link_fieldname": "course"
} }
], ],
"modified": "2021-04-21 14:45:41.658056", "modified": "2021-05-03 05:52:30.396824",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Course", "name": "LMS Course",

View File

@@ -8,6 +8,18 @@ from frappe.model.document import Document
from ...utils import slugify from ...utils import slugify
class LMSCourse(Document): class LMSCourse(Document):
@staticmethod
def find(slug):
"""Returns the course with specified slug.
"""
return find("LMS Course", is_published=True, slug=slug)
@staticmethod
def find_all():
"""Returns all published courses.
"""
return find_all("LMS Course", is_published=True)
def before_save(self): def before_save(self):
if not self.slug: if not self.slug:
self.slug = self.generate_slug(title=self.title) self.slug = self.generate_slug(title=self.title)
@@ -50,7 +62,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 +101,62 @@ 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_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])
return batches
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

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

@@ -287,6 +287,7 @@ img.profile-photo {
} }
.message-section { .message-section {
margin-left: 5%; margin-left: 3%;
display: inline-block; display: inline-block;
width: 95%;
} }

View File

@@ -4,6 +4,13 @@
background: white; background: white;
border-radius: 10px; border-radius: 10px;
border: 1px solid #ddd; border: 1px solid #ddd;
.teaser-body {
padding: 20px;
}
.teaser-footer {
padding: 20px;
}
} }
.sketch-teaser { .sketch-teaser {
@@ -67,6 +74,17 @@ section.lightgray {
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;

View File

@@ -16,7 +16,7 @@
{% if batch.description %} {% if batch.description %}
{{ BatchDetails(batch.description) }} {{ BatchDetails(batch.description) }}
{% endif %} {% endif %}
{{ MentorsSection(mentors, True) }} {{ MentorsSection(mentors, True, course.name) }}
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -11,13 +11,11 @@ def get_context(context):
context.instructor = get_instructor(context.course.owner) context.instructor = get_instructor(context.course.owner)
context.batch = get_batch(context.batch_code) context.batch = get_batch(context.batch_code)
context.mentors = get_mentors(context.batch.name) context.mentors = get_mentors(context.batch.name)
print(context.mentors)
def get_mentors(batch): def get_mentors(batch):
mentors = [] mentors = []
memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"]) memberships = frappe.get_all("LMS Batch Membership", {"batch": batch, "member_type": "Mentor"}, ["member"])
for membership in memberships: for membership in memberships:
member = frappe.db.get_value("Community Member", membership.member, ["name","full_name"], as_dict=True) member = frappe.get_doc("Community Member", membership.member)
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
mentors.append(member) mentors.append(member)
return mentors return mentors

View File

@@ -10,25 +10,25 @@
<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> </div>
<div class="row"> <div class="row">
<div class="col-lg-9 col-md-12"> <div class="col-lg-9 col-md-12">
<div class="course-details"> <div class="course-details">
{{ 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-3 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>
@@ -57,11 +57,11 @@
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro BatchSection(course, is_mentor, upcoming_batches, mentor_batches) %} {% macro BatchSection(course) %}
{% if is_mentor %} {% if course.is_mentor(frappe.session.user) %}
{{ BatchSectionForMentors(course, mentor_batches) }} {{ 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,7 +74,7 @@
<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 %} {% if m.photo_url %}
<img class="profile-photo" src="{{m.photo_url}}"> <img class="profile-photo" src="{{m.photo_url}}">
@@ -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> <button >Manage</button>
{% 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(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_slug = 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_slug)
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

@@ -6,5 +6,3 @@ def get_context(context):
context.course = frappe.form_dict["course"] context.course = frappe.form_dict["course"]
context.batch_code = frappe.form_dict["batch"] context.batch_code = frappe.form_dict["batch"]
redirect_if_not_a_member(context.course, context.batch_code) redirect_if_not_a_member(context.course, context.batch_code)
print(context)

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

@@ -2,23 +2,28 @@
<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 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> </div>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
@@ -26,7 +31,7 @@
{% 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