Merge pull request #657 from pateljannat/course-certificates

feat: certificate template
This commit is contained in:
Jannat Patel
2023-10-25 14:15:54 +05:30
committed by GitHub
6 changed files with 55 additions and 6 deletions

View File

@@ -10,6 +10,14 @@ frappe.ui.form.on("LMS Certificate", {
},
};
});
frm.set_query("template", function (doc) {
return {
filters: {
doc_type: "LMS Certificate",
},
};
});
},
refresh: (frm) => {
if (frm.doc.name)

View File

@@ -8,11 +8,12 @@
"course",
"member",
"member_name",
"published",
"template",
"column_break_3",
"issue_date",
"expiry_date",
"batch_name"
"batch_name",
"published"
],
"fields": [
{
@@ -67,11 +68,18 @@
"fieldname": "published",
"fieldtype": "Check",
"label": "Publish on Participant Page"
},
{
"fieldname": "template",
"fieldtype": "Link",
"label": "Template",
"options": "Print Format",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-13 11:03:23.479255",
"modified": "2023-10-25 12:20:56.091979",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Certificate",

View File

@@ -48,6 +48,15 @@ def create_certificate(course):
if expires_after_yrs:
expiry_date = add_years(nowdate(), expires_after_yrs)
default_certificate_template = frappe.db.get_value(
"Property Setter",
{
"doc_type": "LMS Certificate",
"property": "default_print_format",
},
"value",
)
certificate = frappe.get_doc(
{
"doctype": "LMS Certificate",
@@ -55,6 +64,7 @@ def create_certificate(course):
"course": course,
"issue_date": nowdate(),
"expiry_date": expiry_date,
"template": default_certificate_template,
}
)
certificate.save(ignore_permissions=True)

View File

@@ -74,4 +74,5 @@ execute:frappe.permissions.reset_perms("LMS Enrollment")
lms.patches.v1_0.create_student_role
lms.patches.v1_0.mark_confirmation_for_batch_students
lms.patches.v1_0.create_quiz_questions
lms.patches.v1_0.add_default_marks #16-10-2023
lms.patches.v1_0.add_default_marks #16-10-2023
lms.patches.v1_0.add_certificate_template #25-10-2023

View File

@@ -0,0 +1,19 @@
import frappe
def execute():
default_certificate_template = frappe.db.get_value(
"Property Setter",
{
"doc_type": "LMS Certificate",
"property": "default_print_format",
},
"value",
)
if frappe.db.exists("Print Format", default_certificate_template):
certificates = frappe.get_all("LMS Certificate", pluck="name")
for certificate in certificates:
frappe.db.set_value(
"LMS Certificate", certificate, "template", default_certificate_template
)

View File

@@ -16,7 +16,7 @@ def get_context(context):
context.doc = frappe.db.get_value(
"LMS Certificate",
certificate_name,
["name", "member", "issue_date", "expiry_date", "course"],
["name", "member", "issue_date", "expiry_date", "course", "template"],
as_dict=True,
)
@@ -31,7 +31,10 @@ def get_context(context):
)
context.url = f"{get_url()}/courses/{context.course.name}/{context.doc.name}"
print_format = get_print_format()
if context.doc.template:
print_format = context.doc.template
else:
print_format = get_print_format()
template = frappe.db.get_value(
"Print Format", print_format, ["html", "css"], as_dict=True