Merge pull request #317 from pateljannat/field-name-uniformity
This commit is contained in:
@@ -7,7 +7,6 @@ import frappe
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from lms.lms.doctype.lms_batch_membership.lms_batch_membership import create_membership
|
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
|
from lms.lms.utils import is_mentor
|
||||||
|
|
||||||
class LMSBatch(Document):
|
class LMSBatch(Document):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ frappe.ui.form.on('LMS Course', {
|
|||||||
frm.set_query("course", "related_courses", function () {
|
frm.set_query("course", "related_courses", function () {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"is_published": true,
|
"published": true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
"tags",
|
"tags",
|
||||||
"status",
|
"status",
|
||||||
"section_break_7",
|
"section_break_7",
|
||||||
"is_published",
|
"published",
|
||||||
"column_break_10",
|
"column_break_10",
|
||||||
"upcoming",
|
"upcoming",
|
||||||
"column_break_12",
|
"column_break_12",
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "is_published",
|
"fieldname": "published",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Published"
|
"label": "Published"
|
||||||
},
|
},
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "upcoming",
|
"fieldname": "upcoming",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Is an Upcoming Course"
|
"label": "Upcoming"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "chapters",
|
"fieldname": "chapters",
|
||||||
@@ -163,7 +163,7 @@
|
|||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"is_published_field": "is_published",
|
"is_published_field": "published",
|
||||||
"links": [
|
"links": [
|
||||||
{
|
{
|
||||||
"group": "Chapters",
|
"group": "Chapters",
|
||||||
@@ -186,7 +186,7 @@
|
|||||||
"link_fieldname": "course"
|
"link_fieldname": "course"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2022-03-15 10:16:53.796878",
|
"modified": "2022-03-24 13:09:37.228855",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Course",
|
"name": "LMS Course",
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import frappe
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
import json
|
import json
|
||||||
from ...utils import slugify
|
from ...utils import slugify
|
||||||
from lms.query import find, find_all
|
|
||||||
from frappe.utils import flt, cint
|
from frappe.utils import flt, cint
|
||||||
from lms.lms.utils import get_chapters
|
from lms.lms.utils import get_chapters
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ class LMSCourse(Document):
|
|||||||
}).save(ignore_permissions=True)
|
}).save(ignore_permissions=True)
|
||||||
|
|
||||||
def validate_status(self):
|
def validate_status(self):
|
||||||
if self.is_published:
|
if self.published:
|
||||||
self.status = "Approved"
|
self.status = "Approved"
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
@@ -64,18 +63,12 @@ class LMSCourse(Document):
|
|||||||
def find(name):
|
def find(name):
|
||||||
"""Returns the course with specified 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):
|
def autoname(self):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = self.generate_slug(title=self.title)
|
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):
|
def generate_slug(self, title):
|
||||||
result = frappe.get_all(
|
result = frappe.get_all(
|
||||||
'LMS Course',
|
'LMS Course',
|
||||||
@@ -135,7 +128,7 @@ class LMSCourse(Document):
|
|||||||
return batch_name and frappe.get_doc("LMS Batch", batch_name)
|
return batch_name and frappe.get_doc("LMS Batch", batch_name)
|
||||||
|
|
||||||
def get_batches(self, mentor=None):
|
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:
|
if mentor:
|
||||||
# TODO: optimize this
|
# TODO: optimize this
|
||||||
memberships = frappe.db.get_all(
|
memberships = frappe.db.get_all(
|
||||||
@@ -146,7 +139,7 @@ class LMSCourse(Document):
|
|||||||
return [b for b in batches if b.name in batch_names]
|
return [b for b in batches if b.name in batch_names]
|
||||||
|
|
||||||
def get_cohorts(self):
|
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):
|
def get_cohort(self, cohort_slug):
|
||||||
name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug})
|
name = frappe.get_value("Cohort", {"course": self.name, "slug": cohort_slug})
|
||||||
@@ -183,7 +176,7 @@ def search_course(text):
|
|||||||
search_courses = []
|
search_courses = []
|
||||||
courses = frappe.get_all("LMS Course",
|
courses = frappe.get_all("LMS Course",
|
||||||
filters= {
|
filters= {
|
||||||
"is_published": True
|
"published": True
|
||||||
},
|
},
|
||||||
or_filters = {
|
or_filters = {
|
||||||
"title": ["like", "%{0}%".format(text)],
|
"title": ["like", "%{0}%".format(text)],
|
||||||
|
|||||||
@@ -17,22 +17,6 @@ class TestLMSCourse(unittest.TestCase):
|
|||||||
assert course.title == "Test Course"
|
assert course.title == "Test Course"
|
||||||
assert course.name == "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
|
# disabled this test as it is failing
|
||||||
def _test_add_mentors(self):
|
def _test_add_mentors(self):
|
||||||
course = new_course("Test Course")
|
course = new_course("Test Course")
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ def get_signup_optin_checks():
|
|||||||
return (", ").join(links)
|
return (", ").join(links)
|
||||||
|
|
||||||
def get_popular_courses():
|
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 = []
|
course_membership = []
|
||||||
|
|
||||||
for course in courses:
|
for course in courses:
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
"format": "{} Published",
|
"format": "{} Published",
|
||||||
"label": "Courses",
|
"label": "Courses",
|
||||||
"link_to": "LMS Course",
|
"link_to": "LMS Course",
|
||||||
"stats_filter": "{\"is_published\": 1}",
|
"stats_filter": "{\"published\": 1}",
|
||||||
"type": "DocType"
|
"type": "DocType"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -105,7 +105,7 @@
|
|||||||
"format": "{} Published",
|
"format": "{} Published",
|
||||||
"label": "Course",
|
"label": "Course",
|
||||||
"link_to": "LMS Course",
|
"link_to": "LMS Course",
|
||||||
"stats_filter": "{\"is_published\":[\"=\",1]}",
|
"stats_filter": "{\"published\":[\"=\",1]}",
|
||||||
"type": "DocType"
|
"type": "DocType"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class CustomUser(User):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for map in mapping:
|
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,
|
course = frappe.db.get_value("LMS Course", map.course,
|
||||||
["name", "upcoming", "title", "image", "enable_certification"], as_dict=True)
|
["name", "upcoming", "title", "image", "enable_certification"], as_dict=True)
|
||||||
mentored_courses.append(course)
|
mentored_courses.append(course)
|
||||||
@@ -159,7 +159,7 @@ def get_authored_courses(member, only_published=True):
|
|||||||
"instructor": member
|
"instructor": member
|
||||||
}
|
}
|
||||||
if only_published:
|
if only_published:
|
||||||
filters["is_published"] = True
|
filters["published"] = True
|
||||||
courses = frappe.get_all('LMS Course', filters)
|
courses = frappe.get_all('LMS Course', filters)
|
||||||
|
|
||||||
for course in courses:
|
for course in courses:
|
||||||
|
|||||||
@@ -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.multiple_instructors #11-02-2022
|
||||||
school.patches.v0_0.set_course_in_lesson #21-03-2022
|
school.patches.v0_0.set_course_in_lesson #21-03-2022
|
||||||
school.patches.v0_0.set_status_in_course #21-03-2022
|
school.patches.v0_0.set_status_in_course #21-03-2022
|
||||||
|
lms.patches.v0_0.change_published_field_data
|
||||||
|
|||||||
6
lms/patches/v0_0/change_published_field_data.py
Normal file
6
lms/patches/v0_0/change_published_field_data.py
Normal 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)
|
||||||
@@ -2,7 +2,7 @@ import frappe
|
|||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc("lms", "doctype", "lms_course")
|
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:
|
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)
|
frappe.db.set_value("LMS Course", course.name, "status", status)
|
||||||
|
|||||||
22
lms/query.py
22
lms/query.py
@@ -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))
|
|
||||||
@@ -111,7 +111,7 @@ const mark_progress = (e) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
move_to_next_lesson(e);
|
move_to_next_lesson(status, e);
|
||||||
};
|
};
|
||||||
|
|
||||||
const change_progress_indicators = (status, e) => {
|
const change_progress_indicators = (status, e) => {
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />
|
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />
|
||||||
</div>
|
</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 }}">
|
<div class="button wide-button is-primary" id="submit-for-review" data-course="{{ course.name | urlencode }}">
|
||||||
{{ _("Submit for Review") }}
|
{{ _("Submit for Review") }}
|
||||||
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />
|
<img class="ml-2" src="/assets/lms/icons/white-arrow.svg" />
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ def get_context(context):
|
|||||||
raise frappe.Redirect
|
raise frappe.Redirect
|
||||||
|
|
||||||
course = frappe.db.get_value("LMS Course", course_name,
|
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"],
|
"disable_self_learning", "video_link", "enable_certification", "status"],
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def get_context(context):
|
|||||||
|
|
||||||
def get_courses():
|
def get_courses():
|
||||||
courses = frappe.get_all("LMS Course",
|
courses = frappe.get_all("LMS Course",
|
||||||
filters={"is_published": True},
|
filters={"published": True},
|
||||||
fields=["name", "upcoming", "title", "image", "enable_certification"])
|
fields=["name", "upcoming", "title", "image", "enable_certification"])
|
||||||
|
|
||||||
live_courses, upcoming_courses = [], []
|
live_courses, upcoming_courses = [], []
|
||||||
|
|||||||
Reference in New Issue
Block a user