diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index 183079f0..22bbd2e8 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -7,7 +7,6 @@ import frappe from frappe.model.document import Document from frappe import _ from lms.lms.doctype.lms_batch_membership.lms_batch_membership import create_membership -from lms.query import find, find_all from lms.lms.utils import is_mentor class LMSBatch(Document): diff --git a/lms/lms/doctype/lms_course/lms_course.js b/lms/lms/doctype/lms_course/lms_course.js index f9280ab2..2fc82620 100644 --- a/lms/lms/doctype/lms_course/lms_course.js +++ b/lms/lms/doctype/lms_course/lms_course.js @@ -24,7 +24,7 @@ frappe.ui.form.on('LMS Course', { frm.set_query("course", "related_courses", function () { return { filters: { - "is_published": true, + "published": true, } }; }); diff --git a/lms/lms/doctype/lms_course/lms_course.json b/lms/lms/doctype/lms_course/lms_course.json index b3429c05..f07718eb 100644 --- a/lms/lms/doctype/lms_course/lms_course.json +++ b/lms/lms/doctype/lms_course/lms_course.json @@ -22,7 +22,7 @@ "tags", "status", "section_break_7", - "is_published", + "published", "column_break_10", "upcoming", "column_break_12", @@ -54,7 +54,7 @@ }, { "default": "0", - "fieldname": "is_published", + "fieldname": "published", "fieldtype": "Check", "label": "Published" }, @@ -93,7 +93,7 @@ "default": "0", "fieldname": "upcoming", "fieldtype": "Check", - "label": "Is an Upcoming Course" + "label": "Upcoming" }, { "fieldname": "chapters", @@ -163,7 +163,7 @@ "fieldtype": "Column Break" } ], - "is_published_field": "is_published", + "is_published_field": "published", "links": [ { "group": "Chapters", @@ -186,7 +186,7 @@ "link_fieldname": "course" } ], - "modified": "2022-03-15 10:16:53.796878", + "modified": "2022-03-24 13:09:37.228855", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course", diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index f814ce50..5e4a5df2 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -6,7 +6,6 @@ import frappe from frappe.model.document import Document import json from ...utils import slugify -from lms.query import find, find_all from frappe.utils import flt, cint from lms.lms.utils import get_chapters @@ -27,7 +26,7 @@ class LMSCourse(Document): }).save(ignore_permissions=True) def validate_status(self): - if self.is_published: + if self.published: self.status = "Approved" def on_update(self): @@ -64,18 +63,12 @@ class LMSCourse(Document): def find(name): """Returns the course with specified name. """ - return find("LMS Course", is_published=True, name=name) + return find("LMS Course", published=True, name=name) def autoname(self): if not self.name: self.name = self.generate_slug(title=self.title) - @staticmethod - def find_all(): - """Returns all published courses. - """ - return find_all("LMS Course", is_published=True) - def generate_slug(self, title): result = frappe.get_all( 'LMS Course', @@ -135,7 +128,7 @@ class LMSCourse(Document): return batch_name and frappe.get_doc("LMS Batch", batch_name) def get_batches(self, mentor=None): - batches = find_all("LMS Batch", course=self.name) + batches = frappe.get_all("LMS Batch", {"course": self.name}) if mentor: # TODO: optimize this memberships = frappe.db.get_all( @@ -146,7 +139,7 @@ class LMSCourse(Document): return [b for b in batches if b.name in batch_names] def get_cohorts(self): - return find_all("Cohort", course=self.name, order_by="creation") + return frappe.get_all("Cohort", {"course": self.name}, order_by="creation") def get_cohort(self, cohort_slug): name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug}) @@ -183,7 +176,7 @@ def search_course(text): search_courses = [] courses = frappe.get_all("LMS Course", filters= { - "is_published": True + "published": True }, or_filters = { "title": ["like", "%{0}%".format(text)], diff --git a/lms/lms/doctype/lms_course/test_lms_course.py b/lms/lms/doctype/lms_course/test_lms_course.py index 1dcefab0..ab456553 100644 --- a/lms/lms/doctype/lms_course/test_lms_course.py +++ b/lms/lms/doctype/lms_course/test_lms_course.py @@ -17,22 +17,6 @@ class TestLMSCourse(unittest.TestCase): assert course.title == "Test Course" assert course.name == "test-course" - def test_find_all(self): - courses = LMSCourse.find_all() - assert courses == [] - - # new couse, but not published - course = 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.name for c in courses] == [course.name] - # disabled this test as it is failing def _test_add_mentors(self): course = new_course("Test Course") diff --git a/lms/lms/utils.py b/lms/lms/utils.py index af175462..c90d652e 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -333,7 +333,7 @@ def get_signup_optin_checks(): return (", ").join(links) def get_popular_courses(): - courses = frappe.get_all("LMS Course", {"is_published": 1, "upcoming": 0}) + courses = frappe.get_all("LMS Course", {"published": 1, "upcoming": 0}) course_membership = [] for course in courses: diff --git a/lms/lms/workspace/lms/lms.json b/lms/lms/workspace/lms/lms.json index 4f3bf870..71c8805c 100644 --- a/lms/lms/workspace/lms/lms.json +++ b/lms/lms/workspace/lms/lms.json @@ -144,7 +144,7 @@ "format": "{} Published", "label": "Courses", "link_to": "LMS Course", - "stats_filter": "{\"is_published\": 1}", + "stats_filter": "{\"published\": 1}", "type": "DocType" }, { diff --git a/lms/lms/workspace/school/school.json b/lms/lms/workspace/school/school.json index 9efa29c6..b11f4f35 100644 --- a/lms/lms/workspace/school/school.json +++ b/lms/lms/workspace/school/school.json @@ -105,7 +105,7 @@ "format": "{} Published", "label": "Course", "link_to": "LMS Course", - "stats_filter": "{\"is_published\":[\"=\",1]}", + "stats_filter": "{\"published\":[\"=\",1]}", "type": "DocType" }, { diff --git a/lms/overrides/user.py b/lms/overrides/user.py index 19d968bf..1858083f 100644 --- a/lms/overrides/user.py +++ b/lms/overrides/user.py @@ -113,7 +113,7 @@ class CustomUser(User): ) for map in mapping: - if frappe.db.get_value("LMS Course", map.course, "is_published"): + if frappe.db.get_value("LMS Course", map.course, "published"): course = frappe.db.get_value("LMS Course", map.course, ["name", "upcoming", "title", "image", "enable_certification"], as_dict=True) mentored_courses.append(course) @@ -159,7 +159,7 @@ def get_authored_courses(member, only_published=True): "instructor": member } if only_published: - filters["is_published"] = True + filters["published"] = True courses = frappe.get_all('LMS Course', filters) for course in courses: diff --git a/lms/patches/v0_0/set_status_in_course.py b/lms/patches/v0_0/set_status_in_course.py index d123e073..abf24a1b 100644 --- a/lms/patches/v0_0/set_status_in_course.py +++ b/lms/patches/v0_0/set_status_in_course.py @@ -2,7 +2,7 @@ import frappe def execute(): frappe.reload_doc("lms", "doctype", "lms_course") - courses = frappe.get_all("LMS Course", {"status": ("is", "not set")}, ["name", "is_published"]) + courses = frappe.get_all("LMS Course", {"status": ("is", "not set")}, ["name", "published"]) for course in courses: - status = "Approved" if course.is_published else "In Progress" + status = "Approved" if course.published else "In Progress" frappe.db.set_value("LMS Course", course.name, "status", status) diff --git a/lms/query.py b/lms/query.py deleted file mode 100644 index b2eb58d3..00000000 --- a/lms/query.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Utilities to find docs. -""" -import frappe - -def find_all(doctype, order_by=None, **filters): - """Queries the database for documents of a doctype matching given filters. - """ - rows = frappe.db.get_all(doctype, - filters=filters, - fields='*', - order_by=order_by) - return [frappe.get_doc(dict(row, doctype=doctype)) for row in rows] - -def find(doctype, **filters): - """Queries the database for a document of given doctype matching given filters. - """ - rows = frappe.db.get_all(doctype, - filters=filters, - fields='*') - if rows: - row = rows[0] - return frappe.get_doc(dict(row, doctype=doctype)) diff --git a/lms/www/courses/course.html b/lms/www/courses/course.html index 1b6825fa..96cda3f9 100644 --- a/lms/www/courses/course.html +++ b/lms/www/courses/course.html @@ -155,7 +155,7 @@ - {% elif is_instructor(course.name) and not course.is_published and course.status != "Under Review" %} + {% elif is_instructor(course.name) and not course.published and course.status != "Under Review" %}
{{ _("Submit for Review") }} diff --git a/lms/www/courses/course.py b/lms/www/courses/course.py index 0e82e470..ef969cdd 100644 --- a/lms/www/courses/course.py +++ b/lms/www/courses/course.py @@ -12,7 +12,7 @@ def get_context(context): raise frappe.Redirect course = frappe.db.get_value("LMS Course", course_name, - ["name", "title", "image", "short_introduction", "description", "is_published", "upcoming", + ["name", "title", "image", "short_introduction", "description", "published", "upcoming", "disable_self_learning", "video_link", "enable_certification", "status"], as_dict=True) diff --git a/lms/www/courses/index.py b/lms/www/courses/index.py index 5b82d844..3c6c7c96 100644 --- a/lms/www/courses/index.py +++ b/lms/www/courses/index.py @@ -14,7 +14,7 @@ def get_context(context): def get_courses(): courses = frappe.get_all("LMS Course", - filters={"is_published": True}, + filters={"published": True}, fields=["name", "upcoming", "title", "image", "enable_certification"]) live_courses, upcoming_courses = [], []