diff --git a/community/www/courses/course.html b/community/www/courses/course.html new file mode 100644 index 00000000..43077b2e --- /dev/null +++ b/community/www/courses/course.html @@ -0,0 +1,35 @@ +{% extends "templates/base.html" %} +{% block title %}{{ 'Courses' }}{% endblock %} +{% from "www/courses/macros/card.html" import course_card, topic_card %} +{% block head_include %} + + + +{% endblock %} + +{% block content %} +
+
+ +

{{ course.title }}

+ +
{{ course.description }}
+
+ +
+
+ {% for topic in course.topics %} +
+
{{topic.title}}
+
{{topic.description}}
+
+ {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/community/www/courses/course.py b/community/www/courses/course.py new file mode 100644 index 00000000..13426bea --- /dev/null +++ b/community/www/courses/course.py @@ -0,0 +1,23 @@ +import frappe + +def get_context(context): + context.no_cache = 1 + try: + course_id = frappe.form_dict['course'] + except KeyError: + frappe.local.flags.redirect_location = '/courses' + raise frappe.Redirect + context.course = get_course(course_id) + +def get_course(name): + course = frappe.db.get_value('Community Course', name, + ['name', 'title', 'description'], as_dict=1) + course['topics'] = frappe.db.get_all('Community Course Topic', + filters={ + 'course': name + }, + fields=['name', 'title', 'description'], + order_by='creation' + ) + print(course) + return course \ No newline at end of file diff --git a/community/www/courses/index.html b/community/www/courses/index.html new file mode 100644 index 00000000..052c5921 --- /dev/null +++ b/community/www/courses/index.html @@ -0,0 +1,24 @@ +{% extends "templates/base.html" %} +{% block title %}{{ 'Courses' }}{% endblock %} +{% from "www/courses/macros/card.html" import course_card %} +{% block head_include %} + + + +{% endblock %} + +{% block content %} +
+
+

{{ 'Courses' }}

+
+
+
+ {% for course in courses %} + {{ course_card(course) }} + {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/community/www/courses/index.py b/community/www/courses/index.py new file mode 100644 index 00000000..487b8f60 --- /dev/null +++ b/community/www/courses/index.py @@ -0,0 +1,13 @@ +import frappe + +def get_context(context): + context.no_cache = 1 + context.courses = get_courses() + +def get_courses(): + courses = frappe.get_all( + "Community Course", + fields=['name', 'title', 'description'] + ) + print(courses) + return courses \ No newline at end of file diff --git a/community/www/courses/macros/card.html b/community/www/courses/macros/card.html new file mode 100644 index 00000000..9a3257a1 --- /dev/null +++ b/community/www/courses/macros/card.html @@ -0,0 +1,19 @@ +{% macro course_card(course) %} +
+
+
{{course.title}}
+

{{course.description}}

+ See more → +
+
+{% endmacro %} + +{% macro topic_card(course, topic) %} +
+
+
{{topic.title}}
+

{{topic.description}}

+
+
+{% endmacro %} + diff --git a/community/www/courses/topic.html b/community/www/courses/topic.html new file mode 100644 index 00000000..5771c006 --- /dev/null +++ b/community/www/courses/topic.html @@ -0,0 +1,25 @@ +{% extends "templates/base.html" %} +{% block title %}{{topic.title}} ({{course.title}}){% endblock %} +{% block head_include %} + + + +{% endblock %} + +{% block content %} +
+
+ + +

{{ topic.title }}

+ +
{{ topic.description }}
+
+
+{% endblock %} \ No newline at end of file diff --git a/community/www/courses/topic.py b/community/www/courses/topic.py new file mode 100644 index 00000000..3ae6a6c7 --- /dev/null +++ b/community/www/courses/topic.py @@ -0,0 +1,34 @@ +import frappe + +def get_context(context): + context.no_cache = 1 + course_name = get_queryparam("course", '/courses') + context.course = get_course(course_name) + + topic_name = get_queryparam("topic", '/courses?course=' + course_name) + context.topic = get_topic(course_name, topic_name) + + print("topic", context.topic) + +def get_queryparam(name, redirect_when_not_found): + try: + return frappe.form_dict[name] + except KeyError: + frappe.local.flags.redirect_location = redirect_when_not_found + raise frappe.Redirect + +def get_course(name): + try: + course = frappe.get_doc('Community Course', name) + except frappe.exceptions.DoesNotExistError: + raise frappe.NotFound + return course + +def get_topic(course_name, topic_name): + try: + topic = frappe.get_doc('Community Course Topic', topic_name) + except frappe.exceptions.DoesNotExistError: + raise frappe.NotFound + if topic.course != course_name: + raise frappe.NotFound + return topic