From ebfa49ed8eed3595d8be870b52d341adb99b6746 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 1 Apr 2022 18:56:57 +0530 Subject: [PATCH] chore: renamed lms certification to lms certificate --- .../__init__.py | 0 .../lms_certificate.js} | 2 +- .../lms_certificate.json} | 33 ++++++++++--------- .../lms_certificate.py} | 12 +++---- .../test_lms_certificate.py} | 8 ++--- .../lms_certificate_evaluation.js | 17 +++++----- .../lms_certificate_evaluation.py | 14 ++++++-- lms/lms/utils.py | 4 +-- lms/patches.txt | 2 ++ .../v0_0/certification_member_field_data.py | 7 ++++ .../v0_0/move_certification_to_certificate.py | 12 +++++++ lms/www/batch/learn.js | 2 +- lms/www/courses/certificate.py | 2 +- lms/www/courses/course.js | 2 +- 14 files changed, 76 insertions(+), 41 deletions(-) rename lms/lms/doctype/{lms_certification => lms_certificate}/__init__.py (100%) rename lms/lms/doctype/{lms_certification/lms_certification.js => lms_certificate/lms_certificate.js} (87%) rename lms/lms/doctype/{lms_certification/lms_certification.json => lms_certificate/lms_certificate.json} (82%) rename lms/lms/doctype/{lms_certification/lms_certification.py => lms_certificate/lms_certificate.py} (79%) rename lms/lms/doctype/{lms_certification/test_lms_certification.py => lms_certificate/test_lms_certificate.py} (71%) create mode 100644 lms/patches/v0_0/certification_member_field_data.py create mode 100644 lms/patches/v0_0/move_certification_to_certificate.py diff --git a/lms/lms/doctype/lms_certification/__init__.py b/lms/lms/doctype/lms_certificate/__init__.py similarity index 100% rename from lms/lms/doctype/lms_certification/__init__.py rename to lms/lms/doctype/lms_certificate/__init__.py diff --git a/lms/lms/doctype/lms_certification/lms_certification.js b/lms/lms/doctype/lms_certificate/lms_certificate.js similarity index 87% rename from lms/lms/doctype/lms_certification/lms_certification.js rename to lms/lms/doctype/lms_certificate/lms_certificate.js index 7a264e1e..c8a688a5 100644 --- a/lms/lms/doctype/lms_certification/lms_certification.js +++ b/lms/lms/doctype/lms_certificate/lms_certificate.js @@ -1,7 +1,7 @@ // Copyright (c) 2021, FOSS United and contributors // For license information, please see license.txt -frappe.ui.form.on('LMS Certification', { +frappe.ui.form.on('LMS Certificate', { onload: function (frm) { frm.set_query("student", function (doc) { return { diff --git a/lms/lms/doctype/lms_certification/lms_certification.json b/lms/lms/doctype/lms_certificate/lms_certificate.json similarity index 82% rename from lms/lms/doctype/lms_certification/lms_certification.json rename to lms/lms/doctype/lms_certificate/lms_certificate.json index 0c16244f..55ec8803 100644 --- a/lms/lms/doctype/lms_certification/lms_certification.json +++ b/lms/lms/doctype/lms_certificate/lms_certificate.json @@ -6,25 +6,18 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "student", - "issue_date", - "column_break_3", "course", + "member", + "column_break_3", + "issue_date", "expiry_date" ], "fields": [ - { - "fieldname": "student", - "fieldtype": "Link", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Student", - "options": "User" - }, { "fieldname": "issue_date", "fieldtype": "Date", - "label": "Issue Date" + "label": "Issue Date", + "reqd": 1 }, { "fieldname": "column_break_3", @@ -36,20 +29,30 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Course", - "options": "LMS Course" + "options": "LMS Course", + "reqd": 1 }, { "fieldname": "expiry_date", "fieldtype": "Date", "label": "Expiry Date" + }, + { + "fieldname": "member", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Member", + "options": "User", + "reqd": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2022-04-01 16:41:10.213765", + "modified": "2022-04-01 18:40:27.651944", "modified_by": "Administrator", "module": "LMS", - "name": "LMS Certification", + "name": "LMS Certificate", "naming_rule": "Expression", "owner": "Administrator", "permissions": [ diff --git a/lms/lms/doctype/lms_certification/lms_certification.py b/lms/lms/doctype/lms_certificate/lms_certificate.py similarity index 79% rename from lms/lms/doctype/lms_certification/lms_certification.py rename to lms/lms/doctype/lms_certificate/lms_certificate.py index 1c5d9f51..0a6e9b19 100644 --- a/lms/lms/doctype/lms_certification/lms_certification.py +++ b/lms/lms/doctype/lms_certificate/lms_certificate.py @@ -8,16 +8,16 @@ from frappe import _ from frappe.utils.pdf import get_pdf from lms.lms.utils import is_certified -class LMSCertification(Document): +class LMSCertificate(Document): def validate(self): - certificates = frappe.get_all("LMS Certification", { - "student": self.student, + certificates = frappe.get_all("LMS Certificate", { + "member": self.member, "course": self.course, "expiry_date": [">", nowdate()] }) if len(certificates): - full_name = frappe.db.get_value("User", self.student, "full_name") + full_name = frappe.db.get_value("User", self.member, "full_name") course_name = frappe.db.get_value("LMS Course", self.course, "title") frappe.throw(_("There is already a valid certificate for user {0} for the course {1}").format(full_name, course_name)) @@ -35,8 +35,8 @@ def create_certificate(course): expiry_date = add_years(nowdate(), expires_after_yrs) certificate = frappe.get_doc({ - "doctype": "LMS Certification", - "student": frappe.session.user, + "doctype": "LMS Certificate", + "member": frappe.session.user, "course": course, "issue_date": nowdate(), "expiry_date": expiry_date diff --git a/lms/lms/doctype/lms_certification/test_lms_certification.py b/lms/lms/doctype/lms_certificate/test_lms_certificate.py similarity index 71% rename from lms/lms/doctype/lms_certification/test_lms_certification.py rename to lms/lms/doctype/lms_certificate/test_lms_certificate.py index 7a757f01..b527f357 100644 --- a/lms/lms/doctype/lms_certification/test_lms_certification.py +++ b/lms/lms/doctype/lms_certificate/test_lms_certificate.py @@ -4,19 +4,19 @@ import frappe import unittest from lms.lms.doctype.lms_course.test_lms_course import new_course -from lms.lms.doctype.lms_certification.lms_certification import create_certificate +from lms.lms.doctype.lms_certificate.lms_certificate import create_certificate from frappe.utils import nowdate, add_years, cint -class TestLMSCertification(unittest.TestCase): +class TestLMSCertificate(unittest.TestCase): def test_certificate_creation(self): course = new_course("Test Certificate", 1, 2) certificate = create_certificate(course.name) - self.assertEqual(certificate.student, "Administrator") + self.assertEqual(certificate.member, "Administrator") self.assertEqual(certificate.course, course.name) self.assertEqual(certificate.issue_date, nowdate()) self.assertEqual(certificate.expiry_date, add_years(nowdate(), cint(course.expiry))) - frappe.db.delete("LMS Certification", certificate.name) + frappe.db.delete("LMS Certificate", certificate.name) frappe.db.delete("LMS Course", course.name) diff --git a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.js b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.js index 094b2345..752c06e7 100644 --- a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.js +++ b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.js @@ -2,6 +2,15 @@ // For license information, please see license.txt frappe.ui.form.on('LMS Certificate Evaluation', { + refresh: function(frm) { + frm.add_custom_button(__("Create LMS Certificate"), () => { + frappe.model.open_mapped_doc({ + method: "lms.lms.doctype.lms_certificate_evaluation.lms_certificate_evaluation.create_lms_certificate", + frm: frm + }); + }); + }, + onload: function(frm) { frm.set_query("course", function(doc) { return { @@ -11,13 +20,5 @@ frappe.ui.form.on('LMS Certificate Evaluation', { } }; }); - - frm.set_query("member", function(doc) { - return { - filters: { - "course": doc.course, - } - }; - }); } }); diff --git a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py index 86a2d1fd..5cb730f6 100644 --- a/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py +++ b/lms/lms/doctype/lms_certificate_evaluation/lms_certificate_evaluation.py @@ -1,8 +1,18 @@ # Copyright (c) 2022, Frappe and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document +from frappe.model.mapper import get_mapped_doc class LMSCertificateEvaluation(Document): - pass + pass + +@frappe.whitelist() +def create_lms_certificate(source_name, target_doc=None): + doc = get_mapped_doc("LMS Certificate Evaluation", source_name, { + "LMS Certificate Evaluation": { + "doctype": "LMS Certificate" + } + }, target_doc) + return doc diff --git a/lms/lms/utils.py b/lms/lms/utils.py index c90d652e..dab2518a 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -170,9 +170,9 @@ def get_sorted_reviews(course): return rating_percent def is_certified(course): - certificate = frappe.get_all("LMS Certification", + certificate = frappe.get_all("LMS Certificate", { - "student": frappe.session.user, + "member": frappe.session.user, "course": course }) if len(certificate): diff --git a/lms/patches.txt b/lms/patches.txt index 571f435d..40e8cd1b 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -26,3 +26,5 @@ 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 #25-03-2022 execute:frappe.delete_doc("Workspace", "School", ignore_missing=True, force=True) +lms.patches.v0_0.certification_member_field_data #01-04-2022 +lms.patches.v0_0.move_certification_to_certificate diff --git a/lms/patches/v0_0/certification_member_field_data.py b/lms/patches/v0_0/certification_member_field_data.py new file mode 100644 index 00000000..c1015703 --- /dev/null +++ b/lms/patches/v0_0/certification_member_field_data.py @@ -0,0 +1,7 @@ +import frappe + +def execute(): + frappe.reload_doc("lms", "doctype", "lms_certification") + certificates = frappe.get_all("LMS Certification", fields=["name", "student"]) + for certificate in certificates: + frappe.db.set_value("LMS Certification", certificate.name, "member", certificate.student) diff --git a/lms/patches/v0_0/move_certification_to_certificate.py b/lms/patches/v0_0/move_certification_to_certificate.py new file mode 100644 index 00000000..a928536d --- /dev/null +++ b/lms/patches/v0_0/move_certification_to_certificate.py @@ -0,0 +1,12 @@ +import frappe + +def execute(): + old = frappe.get_all("LMS Certification", fields=["name", "course", "member", "student", "issue_date", "expiry_date"]) + for data in old: + frappe.get_doc({ + "doctype": "LMS Certificate", + "course": data.course, + "member": data.member or data.student, + "issue_date": data.issue_date, + "expiry_date": data.expiry_date + }).save(ignore_permissions=True) diff --git a/lms/www/batch/learn.js b/lms/www/batch/learn.js index 4bde13fb..21521e2f 100644 --- a/lms/www/batch/learn.js +++ b/lms/www/batch/learn.js @@ -244,7 +244,7 @@ const create_certificate = (e) => { e.preventDefault(); course = $(".title").attr("data-course"); frappe.call({ - method: "lms.lms.doctype.lms_certification.lms_certification.create_certificate", + method: "lms.lms.doctype.lms_certificate.lms_certificate.create_certificate", args: { "course": course }, diff --git a/lms/www/courses/certificate.py b/lms/www/courses/certificate.py index aae2ba10..5945c537 100644 --- a/lms/www/courses/certificate.py +++ b/lms/www/courses/certificate.py @@ -9,7 +9,7 @@ def get_context(context): except KeyError: redirect_to_course_list() - context.certificate = frappe.db.get_value("LMS Certification", certificate_name, + context.certificate = frappe.db.get_value("LMS Certificate", certificate_name, ["name", "student", "issue_date", "expiry_date", "course"], as_dict=True) if context.certificate.course != course_name: diff --git a/lms/www/courses/course.js b/lms/www/courses/course.js index 0977a914..90a08f39 100644 --- a/lms/www/courses/course.js +++ b/lms/www/courses/course.js @@ -197,7 +197,7 @@ const create_certificate = (e) => { e.preventDefault(); course = $(e.currentTarget).attr("data-course"); frappe.call({ - method: "lms.lms.doctype.lms_certification.lms_certification.create_certificate", + method: "lms.lms.doctype.lms_certificate.lms_certificate.create_certificate", args: { "course": course },