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