From bc70b1d9da98eaf6bde8863e9e7760ba76d741a7 Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Wed, 4 Sep 2013 12:47:31 -0400 Subject: [PATCH] change formatting for email messages to use full_name instead of first_ and last_name fix templates --- lms/djangoapps/instructor/views/legacy.py | 20 ++++++++----- lms/templates/emails/activation_email.txt | 23 +++++++------- .../emails/activation_email_subject.txt | 4 ++- .../emails/enroll_email_allowedmessage.txt | 30 +++++++++++++++---- .../emails/enroll_email_allowedsubject.txt | 6 +++- .../emails/enroll_email_enrolledmessage.txt | 20 ++++++++++--- .../emails/enroll_email_enrolledsubject.txt | 6 +++- .../emails/unenroll_email_allowedmessage.txt | 13 ++++++-- .../emails/unenroll_email_enrolledmessage.txt | 17 ++++++++--- .../emails/unenroll_email_subject.txt | 6 +++- 10 files changed, 105 insertions(+), 40 deletions(-) diff --git a/lms/djangoapps/instructor/views/legacy.py b/lms/djangoapps/instructor/views/legacy.py index 5c9aa2b4cf..3e9ff96f1c 100644 --- a/lms/djangoapps/instructor/views/legacy.py +++ b/lms/djangoapps/instructor/views/legacy.py @@ -50,6 +50,7 @@ from instructor_task.views import get_task_completion_info from mitxmako.shortcuts import render_to_response from psychometrics import psychoanalyze from student.models import CourseEnrollment, CourseEnrollmentAllowed +from student.views import course_from_id import track.views from mitxmako.shortcuts import render_to_string from xblock.field_data import DictFieldData @@ -60,6 +61,7 @@ from bulk_email.models import CourseEmail from html_to_text import html_to_text from bulk_email import tasks + log = logging.getLogger(__name__) # internal commands for managing forum roles: @@ -1196,7 +1198,7 @@ def _do_enroll_students(course, course_id, students, overload=False, auto_enroll #Composition of email d = {'site_name': stripped_site_name, 'registration_url': registration_url, - 'course_id': course_id, + 'course': course, 'auto_enroll': auto_enroll, 'course_url': 'https://' + stripped_site_name + '/courses/' + course_id, } @@ -1246,8 +1248,7 @@ def _do_enroll_students(course, course_id, students, overload=False, auto_enroll if email_students: #User enrolled for first time, populate dict with user specific info d['email_address'] = student - d['first_name'] = user.first_name - d['last_name'] = user.last_name + d['full_name'] = user.profile.name d['message'] = 'enrolled_enroll' send_mail_ret = send_mail_to_student(student, d) status[student] += (', email sent' if send_mail_ret else '') @@ -1283,9 +1284,10 @@ def _do_unenroll_students(course_id, students, email_students=False): stripped_site_name = _remove_preview(settings.SITE_NAME) if email_students: + course = course_from_id(course_id) #Composition of email d = {'site_name': stripped_site_name, - 'course_id': course_id} + 'course': course} for student in old_students: @@ -1318,8 +1320,7 @@ def _do_unenroll_students(course_id, students, email_students=False): if email_students: #User was enrolled d['email_address'] = student - d['first_name'] = user.first_name - d['last_name'] = user.last_name + d['full_name'] = user.profile.name d['message'] = 'enrolled_unenroll' send_mail_ret = send_mail_to_student(student, d) status[student] += (', email sent' if send_mail_ret else '') @@ -1348,8 +1349,7 @@ def send_mail_to_student(student, param_dict): `auto_enroll`: user input option (a `str`) `course_url`: url of course (a `str`) `email_address`: email of student (a `str`) - `first_name`: student first name (a `str`) - `last_name`: student last name (a `str`) + `full_name`: student full name (a `str`) `message`: type of email to send and template to use (a `str`) ] Returns a boolean indicating whether the email was sent successfully. @@ -1365,9 +1365,13 @@ def send_mail_to_student(student, param_dict): subject = render_to_string(subject_template, param_dict) message = render_to_string(message_template, param_dict) + # Remove leading and trailing whitespace from body + message = message.strip() + # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [student], fail_silently=False) + return True else: return False diff --git a/lms/templates/emails/activation_email.txt b/lms/templates/emails/activation_email.txt index d6716dc764..c111159e00 100644 --- a/lms/templates/emails/activation_email.txt +++ b/lms/templates/emails/activation_email.txt @@ -1,8 +1,9 @@ <%namespace file="../main.html" import="stanford_theme_enabled" /> +<%! from django.utils.translation import ugettext as _ %> -Thank you for signing up for ${settings.PLATFORM_NAME}! To activate -your account, please copy and paste this address into your web -browser's address bar: +${_("Thank you for signing up for {platform_name}! To activate " +"your account, please copy and paste this address into your web " +"browser's address bar:").format(platform_name=settings.PLATFORM_NAME)} % if is_secure: https://${ site }/activate/${ key } @@ -12,13 +13,13 @@ browser's address bar: ## Temporary hack until we develop a better way to adjust language % if stanford_theme_enabled(): - If you didn't request this, you don't need to do anything; you won't - receive any more email from us. Please do not reply to this e-mail; - if you require assistance, check the about section of the - ${settings.PLATFORM_NAME} Courses web site. + ${_("If you didn't request this, you don't need to do anything; you won't " + "receive any more email from us. Please do not reply to this e-mail; " + "if you require assistance, check the about section of the " + "${platform_name} Courses web site.").format(platform_name=settings.PLATFORM_NAME)} % else: - If you didn't request this, you don't need to do anything; you won't - receive any more email from us. Please do not reply to this e-mail; - if you require assistance, check the help section of the - ${settings.PLATFORM_NAME} web site. + ${_("If you didn't request this, you don't need to do anything; you won't " + "receive any more email from us. Please do not reply to this e-mail; " + "if you require assistance, check the help section of the " + "${platform_name} web site.").format(platform_name=settings.PLATFORM_NAME)} % endif diff --git a/lms/templates/emails/activation_email_subject.txt b/lms/templates/emails/activation_email_subject.txt index e78a5a8dc3..cb78de9a2a 100644 --- a/lms/templates/emails/activation_email_subject.txt +++ b/lms/templates/emails/activation_email_subject.txt @@ -1 +1,3 @@ -Your account for ${settings.PLATFORM_NAME} +<%! from django.utils.translation import ugettext as _ %> + +${_("Your account for {platform_name}").format(platform_name=settings.PLATFORM_NAME)} diff --git a/lms/templates/emails/enroll_email_allowedmessage.txt b/lms/templates/emails/enroll_email_allowedmessage.txt index b7d65f0f2c..ad25c23eaf 100644 --- a/lms/templates/emails/enroll_email_allowedmessage.txt +++ b/lms/templates/emails/enroll_email_allowedmessage.txt @@ -1,13 +1,31 @@ -Dear student, +<%! from django.utils.translation import ugettext as _ %> -You have been invited to join ${course_id} at ${site_name} by a member of the course staff. +${_("Dear student,")} -To finish your registration, please visit ${registration_url} and fill out the registration form making sure to use ${email_address} in the E-mail field. +${_("You have been invited to join {course_name} at {site_name} by a " + "member of the course staff.").format( + course_name=course.display_name_with_default, + site_name=site_name + )} + +${_("To finish your registration, please visit {registration_url} and fill " + "out the registration form making sure to use {email_address} in the " + "E-mail field.").format( + registration_url=registration_url, + email_address=email_address + )} % if auto_enroll: -Once you have registered and activated your account, you will see ${course_id} listed on your dashboard. +${_("Once you have registered and activated your account, you will see " + "{course_name} listed on your dashboard.").format( + course_name=course.display_name_with_default + )} % else: -Once you have registered and activated your account, visit ${course_url} to join the course. +${_("Once you have registered and activated your account, visit {course_url} " + "to join the course.").format(course_url=course_url)} % endif ---- -This email was automatically sent from ${site_name} to ${email_address} \ No newline at end of file +${_("This email was automatically sent from {site_name} to " + "{email_address}").format( + site_name=site_name, email_address=email_address + )} \ No newline at end of file diff --git a/lms/templates/emails/enroll_email_allowedsubject.txt b/lms/templates/emails/enroll_email_allowedsubject.txt index 41da60d1db..6ed7ce61b5 100644 --- a/lms/templates/emails/enroll_email_allowedsubject.txt +++ b/lms/templates/emails/enroll_email_allowedsubject.txt @@ -1 +1,5 @@ -You have been invited to register for ${course_id} \ No newline at end of file +<%! from django.utils.translation import ugettext as _ %> + +${_("You have been invited to register for {course_name}").format( + course_name=course.display_name_with_default + )} \ No newline at end of file diff --git a/lms/templates/emails/enroll_email_enrolledmessage.txt b/lms/templates/emails/enroll_email_enrolledmessage.txt index 8e8f24efed..a0a817473e 100644 --- a/lms/templates/emails/enroll_email_enrolledmessage.txt +++ b/lms/templates/emails/enroll_email_enrolledmessage.txt @@ -1,8 +1,20 @@ -Dear ${first_name} ${last_name} +<%! from django.utils.translation import ugettext as _ %> -You have been enrolled in ${course_id} at ${site_name} by a member of the course staff. The course should now appear on your ${site_name} dashboard. +${_("Dear {full_name}").format(full_name=full_name)} -To start accessing course materials, please visit ${course_url} +${_("You have been enrolled in {course_name} at {site_name} by a member " + "of the course staff. The course should now appear on your {site_name} " + "dashboard.").format( + course_name=course.display_name_with_default, + site_name=site_name + )} + +${_("To start accessing course materials, please visit {course_url}").format( + course_url=course_url + )} ---- -This email was automatically sent from ${site_name} to ${first_name} ${last_name} \ No newline at end of file +${_("This email was automatically sent from {site_name} to " + "{full_name}").format( + site_name=site_name, full_name=full_name + )} \ No newline at end of file diff --git a/lms/templates/emails/enroll_email_enrolledsubject.txt b/lms/templates/emails/enroll_email_enrolledsubject.txt index db897a3299..f13675f99a 100644 --- a/lms/templates/emails/enroll_email_enrolledsubject.txt +++ b/lms/templates/emails/enroll_email_enrolledsubject.txt @@ -1 +1,5 @@ -You have been enrolled in ${course_id} \ No newline at end of file +<%! from django.utils.translation import ugettext as _ %> + +${_("You have been enrolled in {course_name}").format( + course_name=course.display_name_with_default + )} \ No newline at end of file diff --git a/lms/templates/emails/unenroll_email_allowedmessage.txt b/lms/templates/emails/unenroll_email_allowedmessage.txt index 9bd0bd3cfd..6e3386738e 100644 --- a/lms/templates/emails/unenroll_email_allowedmessage.txt +++ b/lms/templates/emails/unenroll_email_allowedmessage.txt @@ -1,6 +1,13 @@ -Dear Student, +<%! from django.utils.translation import ugettext as _ %> -You have been un-enrolled from course ${course_id} by a member of the course staff. Please disregard the invitation previously sent. +${_("Dear Student,")} + +${_("You have been un-enrolled from course {course_name} by a member " + "of the course staff. Please disregard the invitation " + "previously sent.").format(course_name=course.display_name_with_default)} ---- -This email was automatically sent from ${site_name} to ${email_address} \ No newline at end of file +${_("This email was automatically sent from {site_name} " + "to {email_address}").format( + site_name=site_name, email_address=email_address + )} \ No newline at end of file diff --git a/lms/templates/emails/unenroll_email_enrolledmessage.txt b/lms/templates/emails/unenroll_email_enrolledmessage.txt index 8a7f9f996e..f3e1bf8bdc 100644 --- a/lms/templates/emails/unenroll_email_enrolledmessage.txt +++ b/lms/templates/emails/unenroll_email_enrolledmessage.txt @@ -1,8 +1,17 @@ -Dear ${first_name} ${last_name} +<%! from django.utils.translation import ugettext as _ %> -You have been un-enrolled in ${course_id} at ${site_name} by a member of the course staff. The course will no longer appear on your ${site_name} dashboard. +${_("Dear {full_name}").format(full_name=full_name)} -Your other courses have not been affected. +${_("You have been un-enrolled in {course_name} at {site_name} by a member " + "of the course staff. The course will no longer appear on your " + "{site_name} dashboard.").format( + course_name=course.display_name_with_default, site_name=site_name + )} + +${_("Your other courses have not been affected.")} ---- -This email was automatically sent from ${site_name} to ${first_name} ${last_name} \ No newline at end of file +${_("This email was automatically sent from ${site_name} to " + "${full_name}").format( + full_name=full_name, site_name=site_name + )} \ No newline at end of file diff --git a/lms/templates/emails/unenroll_email_subject.txt b/lms/templates/emails/unenroll_email_subject.txt index f79218ff22..9dd348e2b6 100644 --- a/lms/templates/emails/unenroll_email_subject.txt +++ b/lms/templates/emails/unenroll_email_subject.txt @@ -1 +1,5 @@ -You have been un-enrolled from ${course_id} \ No newline at end of file +<%! from django.utils.translation import ugettext as _ %> + +${_("You have been un-enrolled from {course_name}").format( + course_name=course.display_name_with_default +)} \ No newline at end of file