From 49edad692c6313ffe5238b9b8ce25857566cad3c Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Tue, 25 Jan 2022 17:42:07 +0530 Subject: [PATCH 1/2] Added doctype for implementing tasks in courses. Issue #94 --- .../doctype/course_task/__init__.py | 0 .../doctype/course_task/course_task.js | 8 ++ .../doctype/course_task/course_task.json | 113 ++++++++++++++++++ .../doctype/course_task/course_task.py | 8 ++ .../doctype/course_task/test_course_task.py | 8 ++ .../doctype/course_task_input/__init__.py | 0 .../course_task_input/course_task_input.json | 43 +++++++ .../course_task_input/course_task_input.py | 8 ++ .../doctype/course_task_response/__init__.py | 0 .../course_task_response.js | 8 ++ .../course_task_response.json | 69 +++++++++++ .../course_task_response.py | 8 ++ .../test_course_task_response.py | 8 ++ 13 files changed, 281 insertions(+) create mode 100644 mon_school/mon_school/doctype/course_task/__init__.py create mode 100644 mon_school/mon_school/doctype/course_task/course_task.js create mode 100644 mon_school/mon_school/doctype/course_task/course_task.json create mode 100644 mon_school/mon_school/doctype/course_task/course_task.py create mode 100644 mon_school/mon_school/doctype/course_task/test_course_task.py create mode 100644 mon_school/mon_school/doctype/course_task_input/__init__.py create mode 100644 mon_school/mon_school/doctype/course_task_input/course_task_input.json create mode 100644 mon_school/mon_school/doctype/course_task_input/course_task_input.py create mode 100644 mon_school/mon_school/doctype/course_task_response/__init__.py create mode 100644 mon_school/mon_school/doctype/course_task_response/course_task_response.js create mode 100644 mon_school/mon_school/doctype/course_task_response/course_task_response.json create mode 100644 mon_school/mon_school/doctype/course_task_response/course_task_response.py create mode 100644 mon_school/mon_school/doctype/course_task_response/test_course_task_response.py diff --git a/mon_school/mon_school/doctype/course_task/__init__.py b/mon_school/mon_school/doctype/course_task/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mon_school/mon_school/doctype/course_task/course_task.js b/mon_school/mon_school/doctype/course_task/course_task.js new file mode 100644 index 0000000..341176d --- /dev/null +++ b/mon_school/mon_school/doctype/course_task/course_task.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, FOSS United and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Course Task', { + // refresh: function(frm) { + + // } +}); diff --git a/mon_school/mon_school/doctype/course_task/course_task.json b/mon_school/mon_school/doctype/course_task/course_task.json new file mode 100644 index 0000000..aa78b5a --- /dev/null +++ b/mon_school/mon_school/doctype/course_task/course_task.json @@ -0,0 +1,113 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "format:{slug} ({course})", + "creation": "2022-01-25 11:37:35.969330", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "slug", + "title", + "course", + "column_break_4", + "description", + "section_break_6", + "inputs", + "button_label", + "section_break_10", + "javascript", + "column_break_12", + "test" + ], + "fields": [ + { + "fieldname": "title", + "fieldtype": "Data", + "in_list_view": 1, + "in_preview": 1, + "label": "Title" + }, + { + "fieldname": "course", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Course", + "options": "LMS Course" + }, + { + "fieldname": "description", + "fieldtype": "Small Text", + "label": "Description" + }, + { + "default": "Verify", + "fieldname": "button_label", + "fieldtype": "Data", + "label": "Button Label" + }, + { + "fieldname": "inputs", + "fieldtype": "Table", + "label": "Inputs", + "options": "Course Task Input" + }, + { + "fieldname": "slug", + "fieldtype": "Data", + "label": "Slug" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_6", + "fieldtype": "Section Break" + }, + { + "fieldname": "section_break_10", + "fieldtype": "Section Break" + }, + { + "fieldname": "javascript", + "fieldtype": "Code", + "label": "Javascript" + }, + { + "fieldname": "test", + "fieldtype": "Code", + "label": "Test" + }, + { + "fieldname": "column_break_12", + "fieldtype": "Column Break" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-01-25 12:41:32.778631", + "modified_by": "Administrator", + "module": "Mon School", + "name": "Course Task", + "naming_rule": "Expression", + "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", + "states": [] +} \ No newline at end of file diff --git a/mon_school/mon_school/doctype/course_task/course_task.py b/mon_school/mon_school/doctype/course_task/course_task.py new file mode 100644 index 0000000..f0c9d2c --- /dev/null +++ b/mon_school/mon_school/doctype/course_task/course_task.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CourseTask(Document): + pass diff --git a/mon_school/mon_school/doctype/course_task/test_course_task.py b/mon_school/mon_school/doctype/course_task/test_course_task.py new file mode 100644 index 0000000..4807d8b --- /dev/null +++ b/mon_school/mon_school/doctype/course_task/test_course_task.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, FOSS United and Contributors +# See license.txt + +# import frappe +import unittest + +class TestCourseTask(unittest.TestCase): + pass diff --git a/mon_school/mon_school/doctype/course_task_input/__init__.py b/mon_school/mon_school/doctype/course_task_input/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mon_school/mon_school/doctype/course_task_input/course_task_input.json b/mon_school/mon_school/doctype/course_task_input/course_task_input.json new file mode 100644 index 0000000..8873796 --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_input/course_task_input.json @@ -0,0 +1,43 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2022-01-25 11:42:57.632621", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "id", + "type", + "label" + ], + "fields": [ + { + "fieldname": "id", + "fieldtype": "Data", + "label": "ID" + }, + { + "fieldname": "type", + "fieldtype": "Select", + "label": "Type", + "options": "Data" + }, + { + "fieldname": "label", + "fieldtype": "Data", + "label": "Label" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2022-01-25 12:23:12.374844", + "modified_by": "Administrator", + "module": "Mon School", + "name": "Course Task Input", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/mon_school/mon_school/doctype/course_task_input/course_task_input.py b/mon_school/mon_school/doctype/course_task_input/course_task_input.py new file mode 100644 index 0000000..deb08eb --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_input/course_task_input.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CourseTaskInput(Document): + pass diff --git a/mon_school/mon_school/doctype/course_task_response/__init__.py b/mon_school/mon_school/doctype/course_task_response/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mon_school/mon_school/doctype/course_task_response/course_task_response.js b/mon_school/mon_school/doctype/course_task_response/course_task_response.js new file mode 100644 index 0000000..55b3639 --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_response/course_task_response.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, FOSS United and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Course Task Response', { + // refresh: function(frm) { + + // } +}); diff --git a/mon_school/mon_school/doctype/course_task_response/course_task_response.json b/mon_school/mon_school/doctype/course_task_response/course_task_response.json new file mode 100644 index 0000000..6c486c9 --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_response/course_task_response.json @@ -0,0 +1,69 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2022-01-25 11:45:01.855293", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "task", + "user", + "status", + "message", + "response" + ], + "fields": [ + { + "fieldname": "task", + "fieldtype": "Link", + "label": "Task", + "options": "Course Task" + }, + { + "fieldname": "user", + "fieldtype": "Link", + "label": "User", + "options": "User" + }, + { + "fieldname": "status", + "fieldtype": "Select", + "label": "Status", + "options": "Success\nFailed" + }, + { + "fieldname": "message", + "fieldtype": "Data", + "label": "Message" + }, + { + "fieldname": "response", + "fieldtype": "Code", + "label": "Response" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-01-25 11:51:58.485145", + "modified_by": "Administrator", + "module": "Mon School", + "name": "Course Task Response", + "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", + "states": [] +} \ No newline at end of file diff --git a/mon_school/mon_school/doctype/course_task_response/course_task_response.py b/mon_school/mon_school/doctype/course_task_response/course_task_response.py new file mode 100644 index 0000000..4f319ce --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_response/course_task_response.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CourseTaskResponse(Document): + pass diff --git a/mon_school/mon_school/doctype/course_task_response/test_course_task_response.py b/mon_school/mon_school/doctype/course_task_response/test_course_task_response.py new file mode 100644 index 0000000..eb06ea5 --- /dev/null +++ b/mon_school/mon_school/doctype/course_task_response/test_course_task_response.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, FOSS United and Contributors +# See license.txt + +# import frappe +import unittest + +class TestCourseTaskResponse(unittest.TestCase): + pass From 61e60009104ced1ea3136aff676aeef45506490c Mon Sep 17 00:00:00 2001 From: Anand Chitipothu Date: Tue, 25 Jan 2022 17:47:41 +0530 Subject: [PATCH 2/2] Added Task macro to embed tasks. Issue #94 --- mon_school/hooks.py | 1 + mon_school/mon_school/plugins.py | 9 +++++++ .../templates/livecode/extension_footer.html | 4 +++ .../templates/livecode/extension_header.html | 25 +++++++++++++++++++ mon_school/templates/task.html | 25 +++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 mon_school/templates/task.html diff --git a/mon_school/hooks.py b/mon_school/hooks.py index ebabda0..f58debd 100644 --- a/mon_school/hooks.py +++ b/mon_school/hooks.py @@ -210,6 +210,7 @@ "Image": "mon_school.mon_school.plugins.image_renderer", "YouTubeVideo": "mon_school.mon_school.plugins.youtube_video_renderer", "Widget": "mon_school.mon_school.plugins.widget_renderer", + "Task": "mon_school.mon_school.plugins.task_renderer", } # Install custom page renderers diff --git a/mon_school/mon_school/plugins.py b/mon_school/mon_school/plugins.py index b7c38dd..4b49e72 100644 --- a/mon_school/mon_school/plugins.py +++ b/mon_school/mon_school/plugins.py @@ -88,3 +88,12 @@ def widget_renderer(widget_id): t = html.escape(json.dumps(doc.template)) return f"
" + +def task_renderer(argument): + """Renders a task. + """ + task = frappe.get_doc("Course Task", argument) + user = frappe.get_cached_doc("User", frappe.session.user) + context = dict(task=task, user=user) + return frappe.render_template("templates/task.html", context) + diff --git a/mon_school/templates/livecode/extension_footer.html b/mon_school/templates/livecode/extension_footer.html index 71614cd..ec8e4a6 100644 --- a/mon_school/templates/livecode/extension_footer.html +++ b/mon_school/templates/livecode/extension_footer.html @@ -205,6 +205,10 @@ $(e).html(t); }); }); + + $(function() { + monschool.run_load_hooks(); + });