Skip to content

Commit

Permalink
Merge pull request #657 from pateljannat/course-certificates
Browse files Browse the repository at this point in the history
feat: certificate template
  • Loading branch information
pateljannat authored Oct 25, 2023
2 parents 48982e8 + 6d70de2 commit c073d22
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lms/lms/doctype/lms_certificate/lms_certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions lms/lms/doctype/lms_certificate/lms_certificate.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"course",
"member",
"member_name",
"published",
"template",
"column_break_3",
"issue_date",
"expiry_date",
"batch_name"
"batch_name",
"published"
],
"fields": [
{
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions lms/lms/doctype/lms_certificate/lms_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,23 @@ 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",
"member": frappe.session.user,
"course": course,
"issue_date": nowdate(),
"expiry_date": expiry_date,
"template": default_certificate_template,
}
)
certificate.save(ignore_permissions=True)
Expand Down
3 changes: 2 additions & 1 deletion lms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions lms/patches/v1_0/add_certificate_template.py
Original file line number Diff line number Diff line change
@@ -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
)
7 changes: 5 additions & 2 deletions lms/www/courses/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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
Expand Down

0 comments on commit c073d22

Please sign in to comment.