Merge branch 'main' of https://github.com/frappe/lms into new-design-system
This commit is contained in:
@@ -2,25 +2,70 @@
|
||||
{% block title %} {{ member.full_name }} - {{ course.title }} {% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="common-page-style">
|
||||
<div class="container certificate-page">
|
||||
|
||||
{% if certificate.member == frappe.session.user %}
|
||||
<div class="button is-secondary pull-right" id="export-as-pdf" data-certificate="{{ certificate.name }}"
|
||||
data-certificate-name="{{ member.full_name }} - {{ course.title }}">{{ _("Export") }}</div>
|
||||
{% endif %}
|
||||
<div class="common-page-style lms-page-style">
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a class="dark-links" href="/courses">{{ _("All Courses") }}</a>
|
||||
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
|
||||
<a class="dark-links" href="/courses/{{ course.name }}">{{ course.title }}</a>
|
||||
</div>
|
||||
{% if custom_template %}
|
||||
{{ custom_template }}
|
||||
{% else %}
|
||||
{% include "lms/templates/certificate.html" %}
|
||||
{% endif %}
|
||||
<script src="/assets/lms/js/html2canvas.js"></script>
|
||||
|
||||
<div class="certificate-parent">
|
||||
|
||||
<div>
|
||||
{{ final_template }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
{% if doc.member == frappe.session.user %}
|
||||
<div class="">
|
||||
<a class="btn btn-default btn-sm" target="_blank" href="/api/method/frappe.utils.print_format.download_pdf?doctype=LMS%20Certificate&name={{ doc.name }}&_lang=en">
|
||||
{{ _("Download") }}
|
||||
</a>
|
||||
|
||||
<!-- <a class="btn btn-default btn-sm ml-2" target="_blank" href="https://www.linkedin.com/sharing/share-offsite?url={{ url | urlencode }}">
|
||||
{{ _("Share") }}
|
||||
</a> -->
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-heading mt-4">
|
||||
{{ _("Certificate Recipient") }}:
|
||||
</div>
|
||||
|
||||
<div class="certificate-recipient">
|
||||
{{ widgets.Avatar(member=member, avatar_class="avatar-small") }}
|
||||
<span class="ml-2">
|
||||
{{ member.full_name }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="card-heading mt-4">
|
||||
{{ _("Issued On") }}:
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ frappe.utils.format_date(doc.issue_date, "medium") }}
|
||||
</div>
|
||||
|
||||
<div class="card-heading mt-4">
|
||||
{{ _("About the Course") }}:
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ course.title }}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
frappe.ready(() => {
|
||||
$("#export-as-pdf").click((e) => {
|
||||
export_as_png(e);
|
||||
});
|
||||
});
|
||||
|
||||
const export_as_pdf = (e) => {
|
||||
var formData = new FormData();
|
||||
|
||||
//Push the HTML content into an element
|
||||
formData.append("html", $("#certificate-card").html());
|
||||
|
||||
var blob = new Blob([], { type: "text/xml" });
|
||||
formData.append("blob", blob);
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(
|
||||
"POST",
|
||||
"/api/method/lms.lms.doctype.lms_certificate.lms_certificate.get_certificate_pdf"
|
||||
);
|
||||
xhr.setRequestHeader("X-Frappe-CSRF-Token", frappe.csrf_token);
|
||||
xhr.responseType = "arraybuffer";
|
||||
|
||||
xhr.onload = function (success) {
|
||||
if (this.status === 200) {
|
||||
var blob = new Blob([success.currentTarget.response], {
|
||||
type: "application/pdf",
|
||||
});
|
||||
var objectUrl = URL.createObjectURL(blob);
|
||||
|
||||
//Open report in a new window
|
||||
window.open(objectUrl);
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
const export_as_png = (e) => {
|
||||
let button = $(e.currentTarget);
|
||||
button.text(__("Exporting..."));
|
||||
|
||||
html2canvas(document.querySelector("#certificate-card"), {
|
||||
scrollY: -window.scrollY,
|
||||
scrollX: 0,
|
||||
})
|
||||
.then(function (canvas) {
|
||||
let dataURL = canvas.toDataURL("image/png");
|
||||
let a = document.createElement("a");
|
||||
a.href = dataURL;
|
||||
a.download = button.attr("data-certificate-name");
|
||||
a.click();
|
||||
})
|
||||
.finally(() => {
|
||||
button.text(__("Export"));
|
||||
});
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
import frappe
|
||||
from frappe.utils.jinja import render_template
|
||||
|
||||
from lms.lms.utils import get_instructors
|
||||
from frappe.utils import get_url
|
||||
|
||||
|
||||
def get_context(context):
|
||||
@@ -13,32 +12,40 @@ def get_context(context):
|
||||
except KeyError:
|
||||
redirect_to_course_list()
|
||||
|
||||
context.certificate = frappe.db.get_value(
|
||||
context.doc = frappe.db.get_value(
|
||||
"LMS Certificate",
|
||||
certificate_name,
|
||||
["name", "member", "issue_date", "expiry_date", "course"],
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
if context.certificate.course != course_name:
|
||||
if context.doc.course != course_name:
|
||||
redirect_to_course_list()
|
||||
|
||||
context.course = frappe.db.get_value(
|
||||
"LMS Course", course_name, ["title", "name", "image"], as_dict=True
|
||||
)
|
||||
context.instructors = (", ").join([x.full_name for x in get_instructors(course_name)])
|
||||
context.member = frappe.db.get_value(
|
||||
"User", context.certificate.member, ["full_name"], as_dict=True
|
||||
"User", context.doc.member, ["full_name", "username"], as_dict=True
|
||||
)
|
||||
context.url = f"{get_url()}/courses/{context.course.name}/{context.doc.name}"
|
||||
|
||||
default_print_format = frappe.db.get_value(
|
||||
"Property Setter",
|
||||
{
|
||||
"doc_type": "LMS Certificate",
|
||||
"property": "default_print_format",
|
||||
},
|
||||
["value"],
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
context.logo = frappe.db.get_single_value("Website Settings", "banner_image")
|
||||
template_name = frappe.db.get_single_value(
|
||||
"LMS Settings", "custom_certificate_template"
|
||||
template = frappe.db.get_value(
|
||||
"Print Format", default_print_format.value, ["html", "css"], as_dict=True
|
||||
)
|
||||
context.custom_certificate_template = frappe.db.get_value(
|
||||
"Web Template", template_name, "template"
|
||||
)
|
||||
context.custom_template = render_template(context.custom_certificate_template, context)
|
||||
merged_template = "<style> " + template.css + " </style>" + template.html
|
||||
final_template = render_template(merged_template, context)
|
||||
context.final_template = final_template
|
||||
|
||||
|
||||
def redirect_to_course_list():
|
||||
|
||||
Reference in New Issue
Block a user