Merge pull request #317 from pateljannat/field-name-uniformity

This commit is contained in:
Jannat Patel
2022-03-25 16:13:25 +05:30
committed by GitHub
17 changed files with 29 additions and 68 deletions

View File

@@ -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):

View File

@@ -24,7 +24,7 @@ frappe.ui.form.on('LMS Course', {
frm.set_query("course", "related_courses", function () {
return {
filters: {
"is_published": true,
"published": true,
}
};
});

View File

@@ -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",

View File

@@ -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)],

View File

@@ -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")

View File

@@ -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:

View File

@@ -144,7 +144,7 @@
"format": "{} Published",
"label": "Courses",
"link_to": "LMS Course",
"stats_filter": "{\"is_published\": 1}",
"stats_filter": "{\"published\": 1}",
"type": "DocType"
},
{

View File

@@ -105,7 +105,7 @@
"format": "{} Published",
"label": "Course",
"link_to": "LMS Course",
"stats_filter": "{\"is_published\":[\"=\",1]}",
"stats_filter": "{\"published\":[\"=\",1]}",
"type": "DocType"
},
{

View File

@@ -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:

View File

@@ -24,3 +24,4 @@ execute:frappe.delete_doc("Custom Field", "User-verify_age", ignore_missing=True
school.patches.v0_0.multiple_instructors #11-02-2022
school.patches.v0_0.set_course_in_lesson #21-03-2022
school.patches.v0_0.set_status_in_course #21-03-2022
lms.patches.v0_0.change_published_field_data

View File

@@ -0,0 +1,6 @@
import frappe
def execute():
courses = frappe.get_all("LMS Course", fields=["name", "is_published"])
for course in courses:
frappe.db.set_value("LMS Course", course.name, "published", course.is_published)

View File

@@ -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)

View File

@@ -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))

View File

@@ -111,7 +111,7 @@ const mark_progress = (e) => {
});
}
else
move_to_next_lesson(e);
move_to_next_lesson(status, e);
};
const change_progress_indicators = (status, e) => {

View File

@@ -155,7 +155,7 @@
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />
</div>
{% 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" %}
<div class="button wide-button is-primary" id="submit-for-review" data-course="{{ course.name | urlencode }}">
{{ _("Submit for Review") }}
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />

View File

@@ -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)

View File

@@ -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 = [], []