feat: added home page
- Refactored the lms_course page and added find_all method to find courses - Added CourseTeaser widget - Added /home as a portal page
This commit is contained in:
@@ -150,6 +150,7 @@ primary_rules = [
|
||||
|
||||
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
|
||||
whitelist = [
|
||||
"/home",
|
||||
"/login",
|
||||
"/update-password",
|
||||
"/update-profile",
|
||||
|
||||
@@ -88,3 +88,15 @@ class LMSCourse(Document):
|
||||
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_instructor(self):
|
||||
return frappe.get_doc("User", self.owner)
|
||||
|
||||
@staticmethod
|
||||
def find_all():
|
||||
"""Returns all published courses.
|
||||
"""
|
||||
rows = frappe.db.get_all("LMS Course",
|
||||
filters={"is_published": True},
|
||||
fields='*')
|
||||
return [frappe.get_doc(dict(row, doctype='LMS Course')) for row in rows]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
from .lms_course import LMSCourse
|
||||
import unittest
|
||||
|
||||
class TestLMSCourse(unittest.TestCase):
|
||||
@@ -26,6 +27,23 @@ class TestLMSCourse(unittest.TestCase):
|
||||
assert course.slug == "test-course"
|
||||
assert course.get_mentors() == []
|
||||
|
||||
def test_find_all(self):
|
||||
courses = LMSCourse.find_all()
|
||||
assert courses == []
|
||||
|
||||
# new couse, but not published
|
||||
course = self.new_course("Test Course")
|
||||
assert courses == []
|
||||
|
||||
# publish the course
|
||||
course.is_published = True
|
||||
course.save()
|
||||
|
||||
# now we should find one course
|
||||
courses = LMSCourse.find_all()
|
||||
assert [c.slug for c in courses] == [course.slug]
|
||||
|
||||
# disabled this test as it is failing
|
||||
def _test_add_mentors(self):
|
||||
course = self.new_course("Test Course")
|
||||
assert course.get_mentors() == []
|
||||
@@ -47,4 +65,4 @@ def new_user(name, email):
|
||||
email=email,
|
||||
first_name=name))
|
||||
doc.insert()
|
||||
return doc
|
||||
return doc
|
||||
|
||||
11
community/lms/widgets/CourseTeaser.html
Normal file
11
community/lms/widgets/CourseTeaser.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<div class="course-preview">
|
||||
<h3 class="course-title"><a href="/courses/{{ course.slug }}">{{ course.title }}</a></h3>
|
||||
<div class="course-intro">
|
||||
{{ course.short_introduction or "" }}
|
||||
</div>
|
||||
<div class="course-footer">
|
||||
<div class="course-author">
|
||||
{{ course.get_instructor().full_name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
39
community/www/home/index.html
Normal file
39
community/www/home/index.html
Normal file
@@ -0,0 +1,39 @@
|
||||
{% extends "templates/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
{{ HeroSection() }}
|
||||
{{ ExploreCourses(courses) }}
|
||||
{{ RecentSketches(recent_sketches) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% macro HeroSection() %}
|
||||
<div>TODO: Hero
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro ExploreCourses(courses) %}
|
||||
<div id="explore-courses">
|
||||
<h2>Explore Courses</h2>
|
||||
<div class="row">
|
||||
{% for course in courses %}
|
||||
<div class="col-md-6">
|
||||
{{ widgets.CoursePreview(course=course) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro RecentSketches(sketches) %}
|
||||
<div id="recet-sketches">
|
||||
<h2>Recent Sketches</h2>
|
||||
<div class="row">
|
||||
{% for sketch in sketches %}
|
||||
<div class="col-md-3">
|
||||
{{ widgets.SketchPreview(sketch=sketch) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
7
community/www/home/index.py
Normal file
7
community/www/home/index.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import frappe
|
||||
from community.lms.models import Course, Sketch
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
context.courses = Course.find_all()
|
||||
context.recent_sketches = Sketch.get_recent_sketches(limit=8)
|
||||
Reference in New Issue
Block a user