diff --git a/lms/lms/print_format/certificate/certificate.json b/lms/lms/print_format/certificate/certificate.json index 0040359b..acf11b9e 100644 --- a/lms/lms/print_format/certificate/certificate.json +++ b/lms/lms/print_format/certificate/certificate.json @@ -1,7 +1,7 @@ { "absolute_value": 0, "align_labels_right": 0, - "creation": "2023-02-22 21:36:54.560420", + "creation": "2023-08-09 16:46:41.214175", "css": ".outer-border {\n font-family: \"Inter\" sans-serif;\n font-size: 16px;\n border-radius: 0.5rem;\n border: 1px solid #E2E6E9;\n padding: 1rem;\n}\n\n.inner-border {\n border: 10px solid #0089FF;\n border-radius: 8px;\n text-align: center;\n padding: 6rem 4rem;\n background-color: #FFFFFF;\n}\n\n.certificate-logo {\n height: 1.5rem;\n margin-bottom: 4rem;\n}\n\n.certificate-name {\n font-size: 2rem;\n font-weight: 500;\n color: #192734;\n margin-bottom: 0.5rem;\n}\n\n.certificate-footer {\n margin: 4rem auto 0;\n width: 70%;\n text-align: center;\n}\n\n.certificate-footer-item {\n color: #192734;\n}\n\n.cursive-font {\n font-family: cursive;\n font-weight: 600;\n}\n\n.certificate-divider {\n margin: 0.5rem 0;\n}\n\n.certificate-expiry {\n margin-left: 2rem;\n}", "custom_format": 1, "disabled": 0, @@ -17,7 +17,7 @@ "margin_left": 0.0, "margin_right": 0.0, "margin_top": 0.0, - "modified": "2023-08-09 16:29:07.233894", + "modified": "2023-08-09 16:46:41.214175", "modified_by": "Administrator", "module": "LMS", "name": "Certificate", diff --git a/lms/www/courses/certificate.py b/lms/www/courses/certificate.py index 55144da6..dccb9515 100644 --- a/lms/www/courses/certificate.py +++ b/lms/www/courses/certificate.py @@ -1,4 +1,5 @@ import frappe +from frappe import _ from frappe.utils.jinja import render_template from frappe.utils import get_url @@ -30,18 +31,7 @@ def get_context(context): ) context.url = f"{get_url()}/courses/{context.course.name}/{context.doc.name}" - print_format = frappe.db.get_value( - "Property Setter", - { - "doc_type": "LMS Certificate", - "property": "default_print_format", - }, - ["value"], - as_dict=True, - ) - - if not print_format: - print_format = "Certificate" + print_format = get_print_format() template = frappe.db.get_value( "Print Format", print_format.value, ["html", "css"], as_dict=True @@ -54,3 +44,30 @@ def get_context(context): def redirect_to_course_list(): frappe.local.flags.redirect_location = "/courses" raise frappe.Redirect + + +def get_print_format(): + print_format = None + default = frappe.db.get_value( + "Property Setter", + { + "doc_type": "LMS Certificate", + "property": "default_print_format", + }, + "value", + ) + + if frappe.db.exists("Print Format", default): + print_format = default + + if not print_format and frappe.db.exists("Print Format", "Certificate"): + print_format = "Certificate" + + if not print_format: + raise ValueError( + _( + "Default Print Format is not set for Certificate. Please contact the Administrator." + ) + ) + + return print_format