Skip to content

Commit

Permalink
Merge pull request #674 from pateljannat/assignment-fix
Browse files Browse the repository at this point in the history
fix: assignment submission email
  • Loading branch information
pateljannat authored Nov 7, 2023
2 parents 9d65e5e + 41b076c commit b5258b6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
// For license information, please see license.txt

frappe.ui.form.on("LMS Assignment Submission", {
// refresh: function(frm) {
// }
onload: function (frm) {
frm.set_query("member", function (doc) {
return {
filters: {
ignore_user_type: 1,
},
};
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
from frappe import _
from frappe.model.document import Document
from frappe.utils import validate_url
from frappe.email.doctype.email_template.email_template import get_email_template


class LMSAssignmentSubmission(Document):
def validate(self):
self.validate_duplicates()

def after_insert(self):
if not frappe.flags.in_test:
self.send_mail()

def validate_duplicates(self):
if frappe.db.exists(
"LMS Assignment Submission",
Expand All @@ -23,6 +28,35 @@ def validate_duplicates(self):
)
)

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")

if custom_template:
email_template = get_email_template(custom_template, args)
subject = email_template.get("subject")
content = email_template.get("message")
frappe.sendmail(
recipients=moderators,
subject=subject,
template=template if not custom_template else None,
content=content if custom_template else None,
args=args,
header=[subject, "green"],
)


@frappe.whitelist()
def upload_assignment(
Expand Down
26 changes: 22 additions & 4 deletions lms/lms/doctype/lms_settings/lms_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
"is_onboarding_complete",
"column_break_zdel",
"livecode_url",
"certification_template",
"course_settings_section",
"search_placeholder",
"column_break_iqxy",
"portal_course_creation",
"section_break_szgq",
"send_calendar_invite_for_evaluations",
"batch_confirmation_template",
"allow_student_progress",
"column_break_2",
"show_dashboard",
Expand Down Expand Up @@ -51,7 +49,12 @@
"default_currency",
"show_usd_equivalent",
"apply_rounding",
"exception_country"
"exception_country",
"email_templates_tab",
"certification_template",
"batch_confirmation_template",
"column_break_uwsp",
"assignment_submission_template"
],
"fields": [
{
Expand Down Expand Up @@ -323,12 +326,27 @@
"fieldtype": "Link",
"label": "Certificate 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,
"issingle": 1,
"links": [],
"modified": "2023-11-01 22:38:38.380325",
"modified": "2023-11-07 11:23:14.257687",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Settings",
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion lms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ lms.patches.v1_0.add_certificate_template #26-10-2023
lms.patches.v1_0.create_batch_source

[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 changes: 10 additions & 0 deletions lms/templates/emails/assignment_submission.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit b5258b6

Please sign in to comment.