diff --git a/.gitignore b/.gitignore index f6a99e30..222921e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ tags community/docs/current community/public/dist +__pycache__/ +*.py[cod] +*$py.class diff --git a/community/hooks.py b/community/hooks.py index 5666dd53..dbf8f2a2 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -165,7 +165,8 @@ whitelist = [ "/add-a-new-batch", "/new-sign-up", "/message", - "/about" + "/about", + "/lms-course-review" ] whitelist_rules = [{"from_route": p, "to_route": p[1:]} for p in whitelist] diff --git a/community/lms/doctype/lms_course/lms_course.py b/community/lms/doctype/lms_course/lms_course.py index a98a5e63..613c5a6c 100644 --- a/community/lms/doctype/lms_course/lms_course.py +++ b/community/lms/doctype/lms_course/lms_course.py @@ -199,7 +199,12 @@ class LMSCourse(Document): } if batch: filters["batch"] = batch - membership = frappe.db.get_value("LMS Batch Membership", filters, ["name","batch", "current_lesson"], as_dict=True) + + membership = frappe.db.get_value("LMS Batch Membership", + filters, + ["name", "batch", "current_lesson", "member_type"], + as_dict=True) + if membership and membership.batch: membership.batch_title = frappe.db.get_value("LMS Batch", membership.batch, "title") return membership @@ -241,6 +246,32 @@ class LMSCourse(Document): member_names = [m['member'] for m in memberships] return find_all("User", name=["IN", member_names]) + def get_reviews(self): + reviews = frappe.get_all("LMS Course Review", + { + "course": self.name + }, + ["review", "rating", "owner"], + order_by= "creation desc") + + for review in reviews: + review.owner_details = frappe.get_doc("User", review.owner) + + return reviews + + def is_eligibleto_review(self, membership): + """ Checks if user is eligible to review the course """ + if not membership: + return False + if frappe.db.count("LMS Course Review", + { + "course": self.name, + "owner": frappe.session.user + }): + return False + return True + + def get_outline(self): return CourseOutline(self) diff --git a/community/lms/doctype/lms_course_review/__init__.py b/community/lms/doctype/lms_course_review/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/community/lms/doctype/lms_course_review/lms_course_review.js b/community/lms/doctype/lms_course_review/lms_course_review.js new file mode 100644 index 00000000..8382eb52 --- /dev/null +++ b/community/lms/doctype/lms_course_review/lms_course_review.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, FOSS United and contributors +// For license information, please see license.txt + +frappe.ui.form.on('LMS Course Review', { + // refresh: function(frm) { + + // } +}); diff --git a/community/lms/doctype/lms_course_review/lms_course_review.json b/community/lms/doctype/lms_course_review/lms_course_review.json new file mode 100644 index 00000000..c2684bbe --- /dev/null +++ b/community/lms/doctype/lms_course_review/lms_course_review.json @@ -0,0 +1,54 @@ +{ + "actions": [], + "creation": "2021-06-28 13:36:36.146718", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "review", + "rating", + "course" + ], + "fields": [ + { + "fieldname": "review", + "fieldtype": "Small Text", + "label": "Review" + }, + { + "fieldname": "rating", + "fieldtype": "Rating", + "label": "Rating" + }, + { + "fieldname": "course", + "fieldtype": "Link", + "label": "Course", + "options": "LMS Course" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-06-28 15:00:35.146196", + "modified_by": "Administrator", + "module": "LMS", + "name": "LMS Course Review", + "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", + "track_changes": 1 +} \ No newline at end of file diff --git a/community/lms/doctype/lms_course_review/lms_course_review.py b/community/lms/doctype/lms_course_review/lms_course_review.py new file mode 100644 index 00000000..e2361ad0 --- /dev/null +++ b/community/lms/doctype/lms_course_review/lms_course_review.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class LMSCourseReview(Document): + pass diff --git a/community/lms/doctype/lms_course_review/test_lms_course_review.py b/community/lms/doctype/lms_course_review/test_lms_course_review.py new file mode 100644 index 00000000..da8a1450 --- /dev/null +++ b/community/lms/doctype/lms_course_review/test_lms_course_review.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, FOSS United and Contributors +# See license.txt + +# import frappe +import unittest + +class TestLMSCourseReview(unittest.TestCase): + pass diff --git a/community/lms/widgets/Reviews.html b/community/lms/widgets/Reviews.html new file mode 100644 index 00000000..5c20d42b --- /dev/null +++ b/community/lms/widgets/Reviews.html @@ -0,0 +1,61 @@ +