Merge pull request #313 from pateljannat/course-creation-through-ui

This commit is contained in:
Jannat Patel
2022-03-19 14:19:25 +05:30
committed by GitHub
44 changed files with 827 additions and 186 deletions

View File

@@ -26,4 +26,4 @@ indent_style = tab
# HTML, CSS, javascript, JSON and YAML
[*.{html,css,js,json,yml,yaml}]
indent_size = 2
indent_size = 4

View File

@@ -162,6 +162,8 @@ update_website_context = [
jinja = {
"methods": [
"school.page_renderers.get_profile_url",
"school.overrides.user.get_enrolled_courses",
"school.overrides.user.get_course_membership",
"school.overrides.user.get_authored_courses",
"school.overrides.user.get_palette",
"school.lms.utils.get_membership",
@@ -186,7 +188,8 @@ jinja = {
"school.lms.utils.get_sorted_reviews",
"school.lms.utils.is_instructor",
"school.lms.utils.convert_number_to_character",
"school.lms.utils.get_signup_optin_checks"
"school.lms.utils.get_signup_optin_checks",
"school.lms.utils.get_popular_courses"
],
"filters": []
}

View File

@@ -1,5 +1,6 @@
{
"actions": [],
"autoname": "hash",
"creation": "2021-07-27 16:25:02.903245",
"doctype": "DocType",
"editable_grid": 1,
@@ -20,13 +21,15 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-30 10:35:30.014950",
"modified": "2022-03-15 09:39:41.937565",
"modified_by": "Administrator",
"module": "LMS",
"name": "Chapter Reference",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@@ -59,7 +59,7 @@
"link_fieldname": "chapter"
}
],
"modified": "2021-09-29 15:33:44.611229",
"modified": "2022-03-14 17:57:00.707416",
"modified_by": "Administrator",
"module": "LMS",
"name": "Course Chapter",
@@ -77,11 +77,26 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"email": 1,
"export": 1,
"if_owner": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "All",
"select": 1,
"share": 1,
"write": 1
}
],
"search_fields": "title",
"show_title_field_in_link": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"title_field": "title",
"track_changes": 1
}
}

View File

@@ -1,6 +1,6 @@
{
"actions": [],
"allow_import": 1,
"allow_events_in_timeline": 1,
"allow_rename": 1,
"autoname": "format:{####} {title}",
"creation": "2021-05-03 06:21:12.995984",
@@ -9,6 +9,7 @@
"engine": "InnoDB",
"field_order": [
"chapter",
"course",
"include_in_preview",
"column_break_4",
"title",
@@ -69,11 +70,20 @@
{
"fieldname": "help",
"fieldtype": "HTML"
},
{
"fetch_from": "chapter.course",
"fieldname": "course",
"fieldtype": "Link",
"hidden": 1,
"label": "Course",
"options": "LMS Course",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-10-11 15:07:38.134808",
"modified": "2022-03-14 18:56:31.969801",
"modified_by": "Administrator",
"module": "LMS",
"name": "Course Lesson",
@@ -89,11 +99,26 @@
"read": 1,
"report": 1,
"role": "System Manager",
"select": 1,
"share": 1,
"write": 1
},
{
"create": 1,
"email": 1,
"export": 1,
"if_owner": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "All",
"select": 1,
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

View File

@@ -6,7 +6,7 @@ from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from ...md import find_macros
from school.lms.utils import get_course_progress
from school.lms.utils import get_course_progress, get_lesson_url
class CourseLesson(Document):
def validate(self):
@@ -108,3 +108,7 @@ def save_progress(lesson, course, status):
progress = get_course_progress(course)
frappe.db.set_value("LMS Batch Membership", membership, "progress", progress)
return progress
@frappe.whitelist()
def get_lesson_info(chapter):
return frappe.db.get_value("Course Chapter", chapter, "course")

View File

@@ -1,5 +1,6 @@
{
"actions": [],
"autoname": "hash",
"creation": "2021-07-27 16:25:48.269536",
"doctype": "DocType",
"editable_grid": 1,
@@ -20,13 +21,15 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-09-30 10:35:47.832547",
"modified": "2022-03-15 09:39:29.495991",
"modified_by": "Administrator",
"module": "LMS",
"name": "Lesson Reference",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@@ -7,10 +7,9 @@
"label": "Reindex Exercises"
}
],
"allow_guest_to_view": 1,
"allow_import": 1,
"allow_rename": 1,
"creation": "2022-02-08 16:34:42.721203",
"creation": "2022-02-22 15:28:26.091549",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
@@ -21,13 +20,14 @@
"column_break_3",
"instructors",
"tags",
"status",
"section_break_7",
"is_published",
"column_break_9",
"column_break_10",
"upcoming",
"column_break_11",
"column_break_12",
"disable_self_learning",
"section_break_5",
"section_break_18",
"short_introduction",
"description",
"chapters",
@@ -43,7 +43,8 @@
"in_list_view": 1,
"label": "Title",
"reqd": 1,
"unique": 1
"unique": 1,
"width": "200"
},
{
"fieldname": "description",
@@ -66,10 +67,6 @@
"fieldtype": "Data",
"label": "Video Embed Link"
},
{
"fieldname": "section_break_5",
"fieldtype": "Section Break"
},
{
"fieldname": "short_introduction",
"fieldtype": "Small Text",
@@ -109,6 +106,7 @@
"fieldtype": "Table MultiSelect",
"in_standard_filter": 1,
"label": "Instructors",
"max_height": "50px",
"options": "Course Instructor"
},
{
@@ -116,14 +114,6 @@
"fieldtype": "Section Break",
"label": "Course Settings"
},
{
"fieldname": "column_break_9",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_11",
"fieldtype": "Column Break"
},
{
"fieldname": "certification_section",
"fieldtype": "Section Break",
@@ -148,9 +138,31 @@
"fieldtype": "Table",
"label": "Related Courses",
"options": "Related Courses"
},
{
"default": "In Progress",
"fieldname": "status",
"fieldtype": "Select",
"hidden": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Status",
"options": "In Progress\nUnder Review\nApproved",
"read_only": 1
},
{
"fieldname": "section_break_18",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_10",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_12",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"is_published_field": "is_published",
"links": [
{
@@ -174,7 +186,7 @@
"link_fieldname": "course"
}
],
"modified": "2022-02-16 11:50:20.661085",
"modified": "2022-03-15 10:16:53.796878",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Course",
@@ -189,6 +201,20 @@
"read": 1,
"report": 1,
"role": "System Manager",
"select": 1,
"share": 1,
"write": 1
},
{
"create": 1,
"email": 1,
"export": 1,
"if_owner": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "All",
"select": 1,
"share": 1,
"write": 1
}

View File

@@ -12,6 +12,24 @@ from school.lms.utils import get_chapters
class LMSCourse(Document):
def validate(self):
self.validate_instructors()
self.validate_status()
def validate_instructors(self):
if self.is_new() and not self.instructors:
frappe.get_doc({
"doctype": "Course Instructor",
"instructor": self.owner,
"parent": self.name,
"parentfield": "instructors",
"parenttype": "LMS Course"
}).save(ignore_permissions=True)
def validate_status(self):
if self.is_published:
self.status = "Approved"
def on_update(self):
if not self.upcoming and self.has_value_changed("upcoming"):
self.send_email_to_interested_users()
@@ -184,3 +202,11 @@ def search_course(text):
}) """
return courses
@frappe.whitelist()
def submit_for_review(course):
chapters = frappe.get_all("Chapter Reference", {"parent": course})
if not len(chapters):
return "No Chp"
frappe.db.set_value("LMS Course", course, "status", "Under Review")
return "OK"

View File

@@ -12,8 +12,6 @@ class TestLMSCourse(unittest.TestCase):
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
frappe.db.sql('delete from `tabLMS Course`')
def test_new_course(self):
course = new_course("Test Course")
assert course.title == "Test Course"

View File

@@ -6,6 +6,7 @@
"engine": "InnoDB",
"field_order": [
"show_search",
"portal_course_creation",
"search_placeholder",
"column_break_2",
"force_profile_completion",
@@ -107,8 +108,14 @@
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_9",
"fieldtype": "Column Break"
"default": "0",
"fieldname": "portal_course_creation",
"fieldtype": "Check",
"label": "Enable Course Creation from Portal"
},
{
"fieldname": "column_break_9",
"fieldtype": "Column Break"
},
{
"default": "0",
@@ -128,7 +135,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2022-03-09 12:40:27.464136",
"modified": "2022-03-10 18:45:58.372370",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Settings",
@@ -149,4 +156,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

View File

@@ -5,9 +5,10 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _
class LMSSettings(Document):
pass
pass
@frappe.whitelist()
def check_profile_restriction():

View File

@@ -331,3 +331,16 @@ def get_signup_optin_checks():
links.append("<a href='/" + route + "'>" + mapper[check].get("title") + "</a>")
return (", ").join(links)
def get_popular_courses():
courses = frappe.get_all("LMS Course", {"is_published": 1, "upcoming": 0})
course_membership = []
for course in courses:
course_membership.append({
"course": course.name,
"members": cint(frappe.db.count("LMS Batch Membership", {"course": course.name}))
})
course_membership = sorted(course_membership, key = lambda x: x.get("members"), reverse=True)
return course_membership[:3]

View File

View File

@@ -0,0 +1,8 @@
frappe.ready(function() {
frappe.web_form.after_save = () => {
frappe.msgprint(__("Chapter has been saved successfully. Go back to the course and add this chapter to the chapters table."))
setTimeout(() => {
window.location.href = `/courses/${frappe.web_form.doc.course}`;
}, 3000);
}
});

View File

@@ -0,0 +1,89 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 1,
"allow_incomplete": 0,
"allow_multiple": 1,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 1,
"button_label": "Save",
"creation": "2022-03-07 18:41:07.058806",
"doc_type": "Course Chapter",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"is_multi_step_form": 0,
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2022-03-14 18:48:01.704325",
"modified_by": "Administrator",
"module": "LMS",
"name": "chapter",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "chapter",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/chapter",
"title": "Chapter",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "course",
"fieldtype": "Link",
"hidden": 0,
"label": "Course",
"max_length": 0,
"max_value": 0,
"options": "LMS Course",
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "title",
"fieldtype": "Data",
"hidden": 0,
"label": "Title",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "description",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Description",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "lessons",
"fieldtype": "Table",
"hidden": 0,
"label": "Lessons",
"max_length": 0,
"max_value": 0,
"options": "Lesson Reference",
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
}
]
}

View File

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

View File

View File

@@ -0,0 +1,6 @@
frappe.ready(function() {
frappe.web_form.after_save = () => {
let route = frappe.web_form.doc.name ? `/courses/${frappe.web_form.doc.name}` : `/course`;
window.location.href = route;
}
});

View File

@@ -0,0 +1,147 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 1,
"allow_incomplete": 0,
"allow_multiple": 1,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 1,
"button_label": "Save",
"creation": "2022-03-07 14:40:41.262163",
"custom_css": "",
"doc_type": "LMS Course",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"is_multi_step_form": 0,
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2022-03-11 12:32:22.512115",
"modified_by": "Administrator",
"module": "LMS",
"name": "course",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "course",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/course",
"title": "Course",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "title",
"fieldtype": "Data",
"hidden": 0,
"label": "Title",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "tags",
"fieldtype": "Data",
"hidden": 0,
"label": "Tags",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "",
"fieldtype": "Column Break",
"hidden": 0,
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "video_link",
"fieldtype": "Data",
"hidden": 0,
"label": "Video Embed Link",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "image",
"fieldtype": "Attach Image",
"hidden": 0,
"label": "Preview Image",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "",
"fieldtype": "Section Break",
"hidden": 0,
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "short_introduction",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Short Introduction",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "description",
"fieldtype": "Text",
"hidden": 0,
"label": "Description",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "chapters",
"fieldtype": "Table",
"hidden": 0,
"label": "Chapters",
"max_length": 0,
"max_value": 0,
"options": "Chapter Reference",
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
}
]
}

View File

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

View File

View File

@@ -0,0 +1,16 @@
frappe.ready(function() {
frappe.web_form.after_save = () => {
frappe.call({
method: "school.lms.doctype.course_lesson.course_lesson.get_lesson_info",
args: {
"chapter": frappe.web_form.doc.chapter
},
callback: (data) => {
frappe.msgprint(__(`Lesson has been saved successfully. Go back to the chapter and add this lesson to the lessons table.`));
setTimeout(() => {
window.location.href = `/courses/${data.message}`;
}, 3000);
}
});
};
});

View File

@@ -0,0 +1,91 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 1,
"allow_incomplete": 0,
"allow_multiple": 1,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 1,
"button_label": "Save",
"creation": "2022-03-07 18:41:42.549831",
"custom_css": "",
"doc_type": "Course Lesson",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"introduction_text": "<div class=\"ql-editor read-mode\"><p><br></p><p><br></p><p>Create lessons for your course. You can add some additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p><p><br></p><table class=\"table table-bordered\"><tbody><tr><td data-row=\"row-wxk1\"><strong>Content Type</strong></td><td data-row=\"row-wxk1\"><strong>Syntax</strong></td></tr><tr><td data-row=\"row-lawj\">Video</td><td data-row=\"row-lawj\">{{ Video(\"url_of_source\") }}</td></tr><tr><td data-row=\"insert-table\">YouTube Video</td><td data-row=\"insert-table\">{{ YouTubeVideo(\"unique_embed_id\") }}</td></tr><tr><td data-row=\"insert-row-below\">Exercise</td><td data-row=\"insert-row-below\">{{ Exercise(\"exercise_name\") }}</td></tr><tr><td data-row=\"row-3b6n\">Quiz</td><td data-row=\"row-3b6n\">{{ Quiz(\"lms_quiz_name\") }}</td></tr><tr><td data-row=\"row-r57s\">Assignment</td><td data-row=\"row-r57s\">{{ Assignment(\"id-filetype\") }}</td></tr></tbody></table></div>",
"is_multi_step_form": 0,
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2022-03-14 18:49:33.526455",
"modified_by": "Administrator",
"module": "LMS",
"name": "lesson",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "lesson",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/lesson",
"title": "Lesson",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "chapter",
"fieldtype": "Link",
"hidden": 0,
"label": "Course Chapter",
"max_length": 0,
"max_value": 0,
"options": "Course Chapter",
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "title",
"fieldtype": "Data",
"hidden": 0,
"label": "Title",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"default": "0",
"fieldname": "include_in_preview",
"fieldtype": "Check",
"hidden": 0,
"label": "Include In Preview",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 0,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "body",
"fieldtype": "Text",
"hidden": 0,
"label": "Body",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
}
]
}

View File

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

View File

@@ -1,35 +1,27 @@
{% set member = frappe.get_doc("User", frappe.session.user) %}
<div class="mt-10">
{% set enrolled = member.get_enrolled_courses().in_progress + member.get_enrolled_courses().completed %}
{% if enrolled | length %}
<div class="mt-8">
<div class="course-home-headings">
{{ _("Courses Enrolled") }}
</div>
<div class="cards-parent">
{% for course in enrolled %}
{{ widgets.CourseCard(course=course) }}
{% endfor %}
</div>
</div>
{% else %}
{% set site_name = frappe.db.get_single_value("System Settings", "app_name") %}
<div class="empty-state">
<div class="empty-state-text">
<div class="text-center">
<div class="empty-state-heading">{{ _("You haven't enrolled for any courses") }}</div>
<div class="course-meta mb-6">{{ _("Here are a few courses we recommend for you to get started with {0}").format(site_name) }}</div>
</div>
{% set recommended_courses = [course1, course2, course3] %}
<div class="cards-parent">
{% for recommended_course in recommended_courses %}
{% if recommended_course %}
{% set course_details = frappe.get_doc("LMS Course", recommended_course) %}
{{ widgets.CourseCard(course=course_details) }}
{% endif %}
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% set enrolled = get_enrolled_courses().in_progress + get_enrolled_courses().completed %}
{% if enrolled | length %}
<div class="cards-parent">
{% for course in enrolled %}
{{ widgets.CourseCard(course=course) }}
{% endfor %}
</div>
{% else %}
{% set site_name = frappe.db.get_single_value("System Settings", "app_name") %}
<div class="empty-state">
<div class="empty-state-text">
<div class="text-center">
<div class="empty-state-heading">{{ _("You haven't enrolled for any courses") }}</div>
<div class="course-meta mb-6">{{ _("Here are a few courses we recommend for you to get started with {0}").format(site_name) }}</div>
</div>
{% set recommended_courses = get_popular_courses() %}
<div class="cards-parent">
{% for course in recommended_courses %}
{% if course %}
{% set course_details = frappe.get_doc("LMS Course", course.course) %}
{{ widgets.CourseCard(course=course_details) }}
{% endif %}
{% endfor %}
</div>
</div>
</div>
{% endif %}

View File

@@ -3,41 +3,9 @@
"creation": "2021-10-21 11:29:50.424865",
"docstatus": 0,
"doctype": "Web Template",
"fields": [
{
"__unsaved": 1,
"fieldname": "recommended_courses",
"fieldtype": "Section Break",
"label": "Recommended Courses for new users",
"reqd": 0
},
{
"__unsaved": 1,
"fieldname": "course1",
"fieldtype": "Link",
"label": "Course 1",
"options": "LMS Course",
"reqd": 1
},
{
"__unsaved": 1,
"fieldname": "course2",
"fieldtype": "Link",
"label": "Course 2",
"options": "LMS Course",
"reqd": 1
},
{
"__unsaved": 1,
"fieldname": "course3",
"fieldtype": "Link",
"label": "Course 3",
"options": "LMS Course",
"reqd": 1
}
],
"fields": [],
"idx": 0,
"modified": "2021-10-28 19:36:11.372396",
"modified": "2022-03-14 09:44:28.266320",
"modified_by": "Administrator",
"module": "LMS",
"name": "Courses Enrolled",

View File

@@ -25,8 +25,15 @@
</div>
{% endif %}
{% if course.status and course.status != "Approved"%}
{% set pill_color = "gray" if course.status == "In Progress" else "orange" %}
<div class="pull-right indicator-pill {{ pill_color }} "> {{ course.status }} </div>
{% endif %}
{% set student_count = get_students(course.name) | length %}
{% set avg_rating = get_average_rating(course.name) %}
{% if student_count and avg_rating %}
<div class="vertically-center">
{% set student_count = get_students(course.name) | length %}
{% if student_count %}
<div class="vertically-center">
<svg class="icon icon-md">
@@ -36,7 +43,6 @@
</div>
{% endif %}
{% set avg_rating = get_average_rating(course.name) %}
{% if avg_rating %}
<div class="vertically-center ml-3">
<svg class="icon icon-md">
@@ -46,6 +52,7 @@
</div>
{% endif %}
</div>
{% endif %}
</div>
<div class="course-card-title">{{ course.title }}</div>
@@ -59,7 +66,7 @@
<div class="progress-percent">{{ progress }}% Completed</div>
{% endif %}
<div class="zindex course-card-footer">
<div class="course-card-footer">
<span class="">
{% set instructors = get_instructors(course.name) %}
{% set ins_len = instructors | length %}

View File

@@ -94,14 +94,16 @@
<div class="course-meta">{{ _("Help us improve our course material.") }}</div>
</div>
<div>
{% if is_eligible_to_review(course.name, membership) %}
<span class="review-link button is-secondary">
{{ _("Write a review") }}
</span>
{% elif frappe.session.user == "Guest" %}
<a class="button is-primary" href="/login?redirect-to=/courses/{{ course.name }}"> {{ _("Login") }} </a>
{% elif not membership %}
<div class="button is-primary join-batch" data-course="{{ course.name | urlencode }}"> {{ _("Start Learning") }} </div>
{% if not is_instructor(course.name) %}
{% if is_eligible_to_review(course.name, membership) %}
<span class="review-link button is-secondary">
{{ _("Write a review") }}
</span>
{% elif frappe.session.user == "Guest" %}
<a class="button is-primary" href="/login?redirect-to=/courses/{{ course.name }}"> {{ _("Login") }} </a>
{% elif not membership %}
<div class="button is-primary join-batch" data-course="{{ course.name | urlencode }}"> {{ _("Start Learning") }} </div>
{% endif %}
{% endif %}
</div>
</div>

View File

@@ -102,16 +102,6 @@ class CustomUser(User):
"owner": self.name
})
def get_course_membership(self, member_type=None):
""" Returns all memberships of the user """
filters = {
"member": self.name
}
if member_type:
filters["member_type"] = member_type
return frappe.get_all("LMS Batch Membership", filters, ["name", "course", "progress"])
def get_mentored_courses(self):
""" Returns all courses mentored by this user """
mentored_courses = []
@@ -130,31 +120,53 @@ class CustomUser(User):
return mentored_courses
def get_enrolled_courses(self):
in_progress = []
completed = []
memberships = self.get_course_membership("Student")
for membership in memberships:
course = frappe.db.get_value("LMS Course", membership.course,
["name", "upcoming", "title", "image", "enable_certification"], as_dict=True)
progress = cint(membership.progress)
if progress < 100:
in_progress.append(course)
else:
completed.append(course)
return {
"in_progress": in_progress,
"completed": completed
}
def get_authored_courses(member):
def get_enrolled_courses():
in_progress = []
completed = []
memberships = get_course_membership(frappe.session.user, member_type="Student")
for membership in memberships:
course = frappe.db.get_value("LMS Course", membership.course,
["name", "upcoming", "title", "image", "enable_certification"], as_dict=True)
progress = cint(membership.progress)
if progress < 100:
in_progress.append(course)
else:
completed.append(course)
return {
"in_progress": in_progress,
"completed": completed
}
def get_course_membership(member, member_type=None):
""" Returns all memberships of the user """
filters = {
"member": member
}
if member_type:
filters["member_type"] = member_type
return frappe.get_all("LMS Batch Membership", filters, ["name", "course", "progress"])
def get_authored_courses(member, only_published=True):
"""Returns the number of courses authored by this user.
"""
return frappe.get_all(
'LMS Course', {
'instructor': member,
'is_published': True
})
course_details = []
filters = {
"instructor": member
}
if only_published:
filters["is_published"] = True
courses = frappe.get_all('LMS Course', filters)
for course in courses:
course_details.append(frappe.db.get_value("LMS Course", course,
["name", "upcoming", "title", "image", "enable_certification", "status"], as_dict=True))
return course_details
def get_palette(full_name):
"""

View File

@@ -22,3 +22,5 @@ school.patches.v0_0.add_progress_to_membership #20-10-2021
execute:frappe.delete_doc("Workspace", "LMS", ignore_missing=True, force=True) #24-10-2021
execute:frappe.delete_doc("Custom Field", "User-verify_age", ignore_missing=True, force=True)
school.patches.v0_0.multiple_instructors #11-02-2022
school.patches.v0_0.set_course_in_lesson #14-03-2022
school.patches.v0_0.set_status_in_course

View File

@@ -0,0 +1,7 @@
import frappe
def execute():
lessons = frappe.get_all("Course Lesson", fields=["name", "chapter"])
for lesson in lessons:
course = frappe.db.get_value("Course Chapter", lesson.chapter, "course")
frappe.db.set_value("Course Lesson", lesson.name, "course", course)

View File

@@ -0,0 +1,7 @@
import frappe
def execute():
courses = frappe.get_all("LMS Course", {"status": ("is", "not set")}, ["name", "is_published"])
for course in courses:
status = "Approved" if course.is_published else "In Progress"
frappe.db.set_value("LMS Course", course.name, "status", status)

View File

@@ -73,7 +73,7 @@ input[type=checkbox] {
}
.common-page-style {
padding-bottom: 5rem;
padding: 2rem 0 5rem;
min-height: 60vh;
padding-top: 3rem;
background-color: var(--bg-color);
@@ -343,7 +343,7 @@ input[type=checkbox] {
.is-secondary {
background: #FFFFFF;
color: inherit;
color: var(--gray-900);
}
.is-secondary:hover {
@@ -353,7 +353,7 @@ input[type=checkbox] {
.is-default {
background: var(--gray-100);
color: var(--gray-700);
color: var(--gray-900);
}
.is-default:disabled {
@@ -1384,6 +1384,28 @@ pre {
overflow: inherit;
}
.dashboard .nav-link {
color: var(--text-muted);
padding: 0 0 var(--padding-md);
margin-right: var(--margin-xl);
}
.dashboard .nav-link.active {
font-weight: 600;
border-bottom: 1px solid var(--primary);
color: var(--text-color);
}
.dashboard .nav-link:hover {
color: inherit;
}
.dashboard-button {
position: relative;
top: -50px;
margin-left: auto;
}
.course-card-wide .breadcrumb {
margin-bottom: 0;
}

View File

@@ -1,4 +0,0 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.4675 3.45802C13.4246 5.41507 13.4246 8.54635 11.4936 10.4773L7.97091 14L4.44822 10.4773C2.51726 8.54635 2.51726 5.41507 4.44822 3.48411L4.47431 3.45802C6.40527 1.52706 9.51046 1.50097 11.4675 3.45802ZM11.4675 3.45802C11.4414 3.43193 11.4414 3.43193 11.4675 3.45802Z" stroke="#687178" stroke-miterlimit="10"/>
<path d="M7.97072 8.25894C8.69128 8.25894 9.27542 7.6748 9.27542 6.95424C9.27542 6.23367 8.69128 5.64954 7.97072 5.64954C7.25015 5.64954 6.66602 6.23367 6.66602 6.95424C6.66602 7.6748 7.25015 8.25894 7.97072 8.25894Z" stroke="#687178" stroke-miterlimit="10"/>
</svg>

Before

Width:  |  Height:  |  Size: 693 B

View File

@@ -1,10 +1,10 @@
frappe.ready(() => {
hide_profile_for_guest_users();
hide_profile_and_dashboard_for_guest_users();
});
const hide_profile_for_guest_users = () => {
const hide_profile_and_dashboard_for_guest_users = () => {
if (frappe.session.user == "Guest") {
var link_array = $('.nav-link').filter((i, elem) => $(elem).text().trim() === "My Profile");
link_array.length && $(link_array[0]).addClass("hide");
let links = $('.nav-link').filter((i, elem) => $(elem).text().trim() === "My Profile" || $(elem).text().trim() === "Dashboard");
links.length && links.each((i, elem) => $(elem).addClass("hide"));
}
};

View File

@@ -0,0 +1,23 @@
{% set courses = get_authored_courses(frappe.session.user, only_published=False) %}
{% if courses | length %}
<div class="cards-parent">
{% for course in courses %}
{{ widgets.CourseCard(course=course) }}
{% endfor %}
</div>
{% else %}
<div class="empty-state">
<div>
<img class="icon icon-xl" src="/assets/school/icons/comment.svg">
</div>
<div class="empty-state-text">
<div class="empty-state-heading">{{ _("No courses created") }}</div>
<div class="course-meta">{{ _("Help others learn something new.") }}</div>
</div>
<div>
<a class="button is-secondary button-links" href="/course?new=1">
{{ _("Create a Course") }}
</a>
</div>
</div>
{% endif %}

View File

@@ -52,10 +52,13 @@
{% if membership or is_instructor %} eligible-for-submission {% endif %}" data-lesson="{{ lesson.name }}"
data-course="{{ course.name }}">{{ lesson.title }}</div>
<span class="lesson-progress {{hide if get_progress(course.name, lesson.name) != 'Complete' else ''}}">COMPLETED</span>
{% if is_instructor %}
<a class="button is-default button-links ml-auto" href="/lesson?name={{ lesson.name }}"> {{ _("Edit") }} </a>
{% endif %}
</div>
<div class="d-flex align-items-center">
{% set instructors = instructors %}
{% set ins_len = instructors | length %}
{% for instructor in instructors %}
{% if ins_len > 1 and loop.index == 1 %}

View File

@@ -1,10 +1,12 @@
{% extends "templates/base.html" %}
{% block title %}{{ course.title }}
{% endblock %}
{% block head_include %}
{% include "public/icons/symbol-defs.svg" %}
<link rel="stylesheet" href="/assets/frappe/css/font-awesome.css">
{% endblock %}
{% block content %}
<div class="common-page-style pt-0 pb-0">
<div class="course-home-top-container">
@@ -132,10 +134,30 @@
<div class="course-home-headings"> {{ course.title }} </div>
<div id="interest-alert" class="{% if not is_user_interested %} hide {% endif %}">
You have opted to be notified for this course. You will receive an email when the course becomes available.
{{ _("You have opted to be notified for this course. You will receive an email when the course becomes available.") }}
</div>
<div class="d-flex align-items-center mb-2">
{% if course.status == "Under Review" %}
<div class="mb-4">
{{ _("Your course is currently under review. Once the review is complete, the System Admins will publish it on the website.") }}
</div>
{% endif %}
<div class="vertically-center mb-4">
{% if is_instructor(course.name) %}
<a class="button is-default button-links mr-2" href="/course?name={{ course.name }}"> {{ _("Edit") }} </a>
<a class="button is-default button-links mr-2" href="/chapter">
<svg class="icon icon-sm mr-1"><use href="#icon-add"></use></svg>
{{ _("Add Chapter") }}
</a>
<a class="button is-default button-links mr-2" href="/lesson">
<svg class="icon icon-sm mr-1"><use href="#icon-add"></use></svg>
{{ _("Add Lesson") }}
</a>
{% endif %}
</div>
<div class="vertically-center mb-2">
<div class="">
<svg class="icon icon-md mr-1">
<use class="" href="#icon-users">
@@ -155,35 +177,45 @@
{% endif %}
</div>
{% if not course.disable_self_learning and not membership and not course.upcoming and not restriction.restrict %}
<div class="button wide-button start-learning is-primary join-batch" data-course="{{ course.name | urlencode }}">
{% set lesson_index = get_lesson_index(membership.current_lesson) if membership and
membership.current_lesson
else '1.1' %}
{% if show_start_learing_cta %}
<div class="button wide-button is-primary join-batch" data-course="{{ course.name | urlencode }}">
{{ _("Start Learning") }}
<img class="ml-2" src="/assets/school/icons/white-arrow.svg" />
</div>
{% endif %}
{% if membership %}
{% set lesson_index = get_lesson_index(membership.current_lesson) if membership and
membership.current_lesson
else '1.1' %}
{% elif is_instructor(course.name) and not course.is_published and course.status != "Under Review" %}
<div class="button wide-button is-primary" id="submit-for-review" data-course="{{ course.name | urlencode }}">
{{ _("Submit for Review") }}
<img class="ml-2" src="/assets/school/icons/white-arrow.svg" />
</div>
{% elif is_instructor(course.name) %}
<a class="button wide-button is-primary" id="continue-learning"
href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}">
Continue Learning <img class="ml-2" src="/assets/school/icons/white-arrow.svg" />
{{ _("Checkout Course") }} <img class="ml-2" src="/assets/school/icons/white-arrow.svg" />
</a>
{% endif %}
{% if course.upcoming and not is_user_interested %}
{% elif membership %}
<a class="button wide-button is-primary" id="continue-learning"
href="{{ get_lesson_url(course.name, lesson_index) }}{{ course.query_parameter }}">
{{ _("Continue Learning") }} <img class="ml-2" src="/assets/school/icons/white-arrow.svg" />
</a>
{% elif course.upcoming and not is_user_interested %}
<div class="button wide-button is-default"
id="notify-me" data-course="{{course.name | urlencode}}">
Notify me when available
{{ _("Notify me when available") }}
</div>
{% endif %}
{% if is_cohort_staff(course.name, frappe.session.user) %}
{% elif is_cohort_staff(course.name, frappe.session.user) %}
<a class="button wide-button is-secondary"
href="/courses/{{course.name}}/manage"
style="color: inherit;">
Manage the course
{{ _("Manage the course") }}
</a>
{% endif %}
@@ -247,12 +279,10 @@
<div class="slider-controls">
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
{% endif %}

View File

@@ -41,6 +41,10 @@ frappe.ready(() => {
create_certificate(e);
});
$("#submit-for-review").click((e) => {
submit_for_review(e);
});
$(document).scroll(function() {
let timer;
clearTimeout(timer);
@@ -237,7 +241,7 @@ const create_certificate = (e) => {
const element_not_in_viewport = (el) => {
const rect = el.getBoundingClientRect();
return rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight;
}
};
const handle_overlay_display = () => {
const element = $(".related-courses").length && $(".related-courses")[0];
@@ -255,4 +259,23 @@ const handle_overlay_display = () => {
"bottom": "5%"
});
}
};
const submit_for_review = (e) => {
let course = $(e.currentTarget).data("course");
frappe.call({
method: "school.lms.doctype.lms_course.lms_course.submit_for_review",
args: {
"course": course
},
callback: (data) => {
if (data.message == "No Chp") {
frappe.msgprint(__(`There are no chapters in this course.
Please add chapters and lessons to your course before you submit it for review.`));
} else if (data.message == "OK") {
frappe.msgprint(__("Your course has been submitted for review."))
window.location.reload();
}
}
})
}

View File

@@ -1,6 +1,6 @@
import frappe
from school.lms.doctype.lms_settings.lms_settings import check_profile_restriction
from school.lms.utils import get_membership
from school.lms.utils import get_membership, is_instructor
def get_context(context):
context.no_cache = 1
@@ -13,7 +13,7 @@ def get_context(context):
course = frappe.db.get_value("LMS Course", course_name,
["name", "title", "image", "short_introduction", "description", "is_published", "upcoming",
"disable_self_learning", "video_link", "enable_certification"],
"disable_self_learning", "video_link", "enable_certification", "status"],
as_dict=True)
related_courses = frappe.get_all("Related Courses", {"parent": course.name}, ["course"])
@@ -33,6 +33,7 @@ def get_context(context):
if context.course.upcoming:
context.is_user_interested = get_user_interest(context.course.name)
context.restriction = check_profile_restriction()
context.show_start_learing_cta = show_start_learing_cta(course, membership, context.restriction)
context.metatags = {
"title": course.title,
"image": course.image,
@@ -46,3 +47,6 @@ def get_user_interest(course):
"course": course,
"user": frappe.session.user
})
def show_start_learing_cta(course, membership, restriction):
return not course.disable_self_learning and not membership and not course.upcoming and not restriction.get("restrict") and not is_instructor(course.name)

View File

View File

@@ -0,0 +1,49 @@
{% extends "templates/base.html" %}
{% block title %}{{ _("Dashboard")}}
{% endblock %}
{% block content %}
{% set portal_course_creation = frappe.db.get_single_value("LMS Settings", "portal_course_creation") %}
<div class="common-page-style dashboard">
<div class="container">
{% if portal_course_creation %}
<a class="button is-default button-links pull-right hide" id="create-course-link" href="/course">
<svg class="icon icon-sm mr-1"><use href="#icon-add"></use></svg>
{{ _("New Course")}}
</a>
{% endif %}
<ul class="nav" id="courses-tab">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#courses-enrolled"> {{ _("Courses Enrolled") }} </a>
</li>
{% if portal_course_creation %}
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#courses-created">{{ _("Courses Created") }}
</a>
</li>
{% endif %}
</ul>
<div class="border-bottom mb-4"></div>
<div class="tab-content">
<div class="tab-pane active" id="courses-enrolled" role="tabpanel" aria-labelledby="courses-enrolled">
{% include "school/lms/web_template/courses_enrolled/courses_enrolled.html" %}
</div>
{% if portal_course_creation %}
<div class="tab-pane fade" id="courses-created" role="tabpanel" aria-labelledby="courses-created">
{% include "school/templates/courses_created.html" %}
</div>
{% endif %}
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script>
frappe.ready(() => {
$('#courses-tab a[data-toggle="tab"]').on('shown.bs.tab', (e) => {
let link = $("#create-course-link");
$(e.currentTarget).attr("href") == "#courses-created" ? link.removeClass("hide") : link.addClass("hide");
});
})
</script>
{% endblock %}

View File

@@ -29,7 +29,7 @@
{% macro ProfileBanner(member) %}
{% set cover_image = member.cover_image if member.cover_image else "/assets/school/images/profile-banner.png" %}
{% set enrollment = member.get_course_membership("Student") | length %}
{% set enrollment = get_course_membership(frappe.session.user, member_type="Student") | length %}
{% set enrollment_suffix = _("Courses") if enrollment > 1 else _("Course") %}
<div class="container">
<div class="profile-banner" style="background-image: url({{ cover_image }})">
@@ -77,9 +77,7 @@
<div class="course-home-headings"> {{ _("Courses Created") }} </div>
<div class="cards-parent">
{% for course in authored_courses %}
{% set course_details = frappe.db.get_value("LMS Course", course,
["name", "upcoming", "title", "image", "enable_certification"], as_dict=True) %}
{{ widgets.CourseCard(course=course_details, read_only=read_only) }}
{{ widgets.CourseCard(course=course, read_only=read_only) }}
{% endfor %}
</div>
</div>
@@ -100,7 +98,7 @@
{% endmacro %}
{% macro CoursesEnrolled(member, read_only) %}
{% set enrolled = member.get_enrolled_courses() %}
{% set enrolled = get_enrolled_courses() %}
{% if enrolled.completed | length %}
<div class="profile-courses">