Merge branch 'main' into mentor-request-email-templates

This commit is contained in:
Anand Chitipothu
2021-05-06 15:38:53 +05:30
committed by GitHub
26 changed files with 325 additions and 207 deletions

View File

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

View File

@@ -6,6 +6,7 @@ from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from community.www.courses.utils import get_member_with_email
from community.query import find, find_all
class LMSBatch(Document):
def validate(self):
@@ -23,10 +24,16 @@ class LMSBatch(Document):
"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
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()
def get_messages(batch):

View File

@@ -40,6 +40,6 @@ def create_membership(batch, course=None, member=None, member_type="Student", ro
"member": member
}).save(ignore_permissions=True)
if course:
course_slug = frappe.db.get_value("LMS Course", {"title": 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": [],
"allow_guest_to_view": 1,
"allow_rename": 1,
"autoname": "field:title",
"creation": "2021-03-01 16:49:33.622422",
"doctype": "DocType",
"editable_grid": 1,
@@ -94,7 +93,7 @@
"link_fieldname": "course"
}
],
"modified": "2021-05-05 14:17:26.297602",
"modified": "2021-05-06 11:15:45.728976",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",

View File

@@ -6,13 +6,18 @@ from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from ...utils import slugify
from community.query import find, find_all
class LMSCourse(Document):
@staticmethod
def find(slug):
"""Returns the course with specified slug.
def find(name):
"""Returns the course with specified name.
"""
return find("LMS Course", is_published=True, slug=slug)
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():
@@ -20,10 +25,6 @@ class LMSCourse(Document):
"""
return find_all("LMS Course", is_published=True)
def before_save(self):
if not self.slug:
self.slug = self.generate_slug(title=self.title)
def generate_slug(self, title):
result = frappe.get_all(
'LMS Course',
@@ -32,7 +33,7 @@ class LMSCourse(Document):
return slugify(title, used_slugs=slugs)
def __repr__(self):
return f"<Course#{self.name} {self.slug}>"
return f"<Course#{self.name}>"
def get_topic(self, slug):
"""Returns the topic with given slug in this course as a Document.
@@ -123,6 +124,9 @@ class LMSCourse(Document):
# 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:
@@ -139,24 +143,8 @@ class LMSCourse(Document):
now = frappe.utils.nowdate()
batches = find_all("LMS Batch",
course=self.name,
start_date=[">", now])
start_date=[">", now],
status="Active",
visibility="Public")
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

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

View File

@@ -1,6 +1,6 @@
<div class="chapter-teaser">
<div class="teaser-body">
<h3 class="chapter-title">{{ chapter.title }}</h3>
<h3 class="chapter-title"><span class="chapter-number">{{index}}</span> {{ chapter.title }}</h3>
<div class="chapter-description">
{{ chapter.description or "" }}
</div>

View File

@@ -1,6 +1,6 @@
<div class="course-teaser">
<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">
{{ course.short_introduction or "" }}
</div>