fix: assignment submission email
This commit is contained in:
@@ -5,12 +5,17 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import validate_url
|
from frappe.utils import validate_url
|
||||||
|
from frappe.email.doctype.email_template.email_template import get_email_template
|
||||||
|
|
||||||
|
|
||||||
class LMSAssignmentSubmission(Document):
|
class LMSAssignmentSubmission(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_duplicates()
|
self.validate_duplicates()
|
||||||
|
|
||||||
|
def after_insert(self):
|
||||||
|
if not frappe.flags.in_test:
|
||||||
|
self.send_mail()
|
||||||
|
|
||||||
def validate_duplicates(self):
|
def validate_duplicates(self):
|
||||||
if frappe.db.exists(
|
if frappe.db.exists(
|
||||||
"LMS Assignment Submission",
|
"LMS Assignment Submission",
|
||||||
@@ -23,6 +28,35 @@ class LMSAssignmentSubmission(Document):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def send_mail(self):
|
||||||
|
subject = _("New Assignment Submission")
|
||||||
|
template = "assignment_submission"
|
||||||
|
custom_template = frappe.db.get_single_value(
|
||||||
|
"LMS Settings", "assignment_submission_template"
|
||||||
|
)
|
||||||
|
|
||||||
|
args = {
|
||||||
|
"member_name": self.member_name,
|
||||||
|
"assignment_name": self.assignment,
|
||||||
|
"assignment_title": self.assignment_title,
|
||||||
|
"submission_name": self.name,
|
||||||
|
}
|
||||||
|
|
||||||
|
moderators = frappe.get_all("Has Role", {"role": "Moderator"}, pluck="parent")
|
||||||
|
print(moderators)
|
||||||
|
if custom_template:
|
||||||
|
email_template = get_email_template(custom_template, args)
|
||||||
|
subject = email_template.get("subject")
|
||||||
|
content = email_template.get("message")
|
||||||
|
frappe.sendmail(
|
||||||
|
recipients="jannat@frappe.io",
|
||||||
|
subject=subject,
|
||||||
|
template=template if not custom_template else None,
|
||||||
|
content=content if custom_template else None,
|
||||||
|
args=args,
|
||||||
|
header=[subject, "green"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def upload_assignment(
|
def upload_assignment(
|
||||||
|
|||||||
@@ -10,14 +10,12 @@
|
|||||||
"is_onboarding_complete",
|
"is_onboarding_complete",
|
||||||
"column_break_zdel",
|
"column_break_zdel",
|
||||||
"livecode_url",
|
"livecode_url",
|
||||||
"certification_template",
|
|
||||||
"course_settings_section",
|
"course_settings_section",
|
||||||
"search_placeholder",
|
"search_placeholder",
|
||||||
"column_break_iqxy",
|
"column_break_iqxy",
|
||||||
"portal_course_creation",
|
"portal_course_creation",
|
||||||
"section_break_szgq",
|
"section_break_szgq",
|
||||||
"send_calendar_invite_for_evaluations",
|
"send_calendar_invite_for_evaluations",
|
||||||
"batch_confirmation_template",
|
|
||||||
"allow_student_progress",
|
"allow_student_progress",
|
||||||
"column_break_2",
|
"column_break_2",
|
||||||
"show_dashboard",
|
"show_dashboard",
|
||||||
@@ -51,7 +49,12 @@
|
|||||||
"default_currency",
|
"default_currency",
|
||||||
"show_usd_equivalent",
|
"show_usd_equivalent",
|
||||||
"apply_rounding",
|
"apply_rounding",
|
||||||
"exception_country"
|
"exception_country",
|
||||||
|
"email_templates_tab",
|
||||||
|
"certification_template",
|
||||||
|
"batch_confirmation_template",
|
||||||
|
"column_break_uwsp",
|
||||||
|
"assignment_submission_template"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -323,12 +326,27 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Certificate Email Template",
|
"label": "Certificate Email Template",
|
||||||
"options": "Email Template"
|
"options": "Email Template"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "email_templates_tab",
|
||||||
|
"fieldtype": "Tab Break",
|
||||||
|
"label": "Email Templates"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "assignment_submission_template",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Assignment Submission Template",
|
||||||
|
"options": "Email Template"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_uwsp",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-11-01 22:38:38.380325",
|
"modified": "2023-11-07 11:23:14.257687",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Settings",
|
"name": "LMS Settings",
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"attach_print": 0,
|
|
||||||
"channel": "Email",
|
|
||||||
"creation": "2023-03-27 16:34:03.505647",
|
|
||||||
"days_in_advance": 0,
|
|
||||||
"docstatus": 0,
|
|
||||||
"doctype": "Notification",
|
|
||||||
"document_type": "LMS Assignment Submission",
|
|
||||||
"enabled": 1,
|
|
||||||
"event": "New",
|
|
||||||
"idx": 0,
|
|
||||||
"is_standard": 1,
|
|
||||||
"message": "<h3> {{ _(\"Assignment Submission\") }}\n\n{% set title = frappe.db.get_value(\"Course Lesson\", doc.lesson, \"title\") %}\n\n<p> {{ _(\"{0} has submitted their assignment for the lesson {1}\").format(doc.member_name, title) }} </p>\n\n <p> {{ _(\" Please evaluate and grade the assignment. \") }} </p>",
|
|
||||||
"modified": "2023-03-27 16:46:44.564007",
|
|
||||||
"modified_by": "Administrator",
|
|
||||||
"module": "LMS",
|
|
||||||
"name": "Assignment Submission Notification",
|
|
||||||
"owner": "Administrator",
|
|
||||||
"recipients": [
|
|
||||||
{
|
|
||||||
"receiver_by_document_field": "evaluator"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"send_system_notification": 0,
|
|
||||||
"send_to_all_assignees": 0,
|
|
||||||
"subject": "Assignment Submission"
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<div style="background-color: #f4f5f6; padding: 1rem;">
|
|
||||||
<div style="background-color: #ffffff; width: 75%; margin: 0 auto; padding: 1rem;">
|
|
||||||
<h3> {{ _("Assignment Submission") }} </h3>
|
|
||||||
{% set title = frappe.db.get_value("Course Lesson", doc.lesson, "title") %}
|
|
||||||
<br>
|
|
||||||
<p> {{ _("{0} has submitted their assignment for the lesson {1}").format(frappe.bold(doc.member_name), frappe.bold(title)) }}
|
|
||||||
</p>
|
|
||||||
<p> {{ _(" Please evaluate and grade the assignment.") }} </p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import frappe
|
|
||||||
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
# do your magic here
|
|
||||||
pass
|
|
||||||
@@ -80,4 +80,5 @@ lms.patches.v1_0.add_certificate_template #26-10-2023
|
|||||||
lms.patches.v1_0.create_batch_source
|
lms.patches.v1_0.create_batch_source
|
||||||
|
|
||||||
[post_model_sync]
|
[post_model_sync]
|
||||||
lms.patches.v1_0.batch_tabs_settings
|
lms.patches.v1_0.batch_tabs_settings
|
||||||
|
execute:frappe.delete_doc("Notification", "Assignment Submission Notification")
|
||||||
10
lms/templates/emails/assignment_submission.html
Normal file
10
lms/templates/emails/assignment_submission.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<p>
|
||||||
|
{{ _("{0} has submitted the assignment {1}").format(frappe.bold(member_name), frappe.bold(assignment_title)) }}
|
||||||
|
</p>
|
||||||
|
<br>
|
||||||
|
<p> {{ _(" Please evaluate and grade it.") }} </p>
|
||||||
|
<br>`
|
||||||
|
<a href="/assignment-submission/{{ assignment_name }}/{{ submission_name }}">
|
||||||
|
{{ _("Open Assignment") }}
|
||||||
|
</a>
|
||||||
|
|
||||||
Reference in New Issue
Block a user