fix: certificate share
This commit is contained in:
@@ -9,6 +9,7 @@ def after_install():
|
||||
def after_sync():
|
||||
create_lms_roles()
|
||||
set_default_home()
|
||||
set_default_certificate_print_format()
|
||||
add_all_roles_to("Administrator")
|
||||
|
||||
|
||||
@@ -76,7 +77,7 @@ def create_course_creator_role():
|
||||
"desk_access": 0,
|
||||
}
|
||||
)
|
||||
role.save(ignore_permissions=True)
|
||||
role.save()
|
||||
|
||||
|
||||
def create_moderator_role():
|
||||
@@ -89,7 +90,7 @@ def create_moderator_role():
|
||||
"desk_access": 0,
|
||||
}
|
||||
)
|
||||
role.save(ignore_permissions=True)
|
||||
role.save()
|
||||
|
||||
|
||||
def create_evaluator_role():
|
||||
@@ -102,7 +103,26 @@ def create_evaluator_role():
|
||||
"desk_access": 0,
|
||||
}
|
||||
)
|
||||
role.save(ignore_permissions=True)
|
||||
role.save()
|
||||
|
||||
|
||||
def set_default_certificate_print_format():
|
||||
filters = {
|
||||
"doc_type": "LMS Certificate",
|
||||
"property": "default_print_format",
|
||||
}
|
||||
if not frappe.db.exists("Property Setter", filters):
|
||||
filters.update(
|
||||
{
|
||||
"doctype_or_field": "DocType",
|
||||
"property_type": "Data",
|
||||
"value": "Certificate",
|
||||
}
|
||||
)
|
||||
|
||||
doc = frappe.new_doc("Property Setter")
|
||||
doc.update(filters)
|
||||
doc.save()
|
||||
|
||||
|
||||
def delete_custom_fields():
|
||||
|
||||
@@ -24,17 +24,15 @@ class LMSCertificate(Document):
|
||||
_("{0} is already certified for the course {1}").format(full_name, course_name)
|
||||
)
|
||||
|
||||
def after_insert(self):
|
||||
share = frappe.get_doc(
|
||||
{
|
||||
"doctype": "DocShare",
|
||||
"read": 1,
|
||||
"share_doctype": "LMS Certificate",
|
||||
"share_name": self.name,
|
||||
"user": self.member,
|
||||
}
|
||||
def on_update(self):
|
||||
frappe.share.add_docshare(
|
||||
self.doctype,
|
||||
self.name,
|
||||
self.member,
|
||||
write=1,
|
||||
share=1,
|
||||
flags={"ignore_share_permission": True},
|
||||
)
|
||||
share.save(ignore_permissions=True)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
@@ -30,7 +30,7 @@ def get_context(context):
|
||||
)
|
||||
context.url = f"{get_url()}/courses/{context.course.name}/{context.doc.name}"
|
||||
|
||||
default_print_format = frappe.db.get_value(
|
||||
print_format = frappe.db.get_value(
|
||||
"Property Setter",
|
||||
{
|
||||
"doc_type": "LMS Certificate",
|
||||
@@ -40,8 +40,11 @@ def get_context(context):
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
if not print_format:
|
||||
print_format = "Certificate"
|
||||
|
||||
template = frappe.db.get_value(
|
||||
"Print Format", default_print_format.value, ["html", "css"], as_dict=True
|
||||
"Print Format", print_format.value, ["html", "css"], as_dict=True
|
||||
)
|
||||
merged_template = "<style> " + template.css + " </style>" + template.html
|
||||
final_template = render_template(merged_template, context)
|
||||
|
||||
Reference in New Issue
Block a user