-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Implement themed enrollment email feature #6081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abdae82
4654593
69fd063
7acb131
21dd99c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,21 @@ | |
| import json | ||
| from json.encoder import JSONEncoder | ||
|
|
||
| from django.conf import settings | ||
| from mako.template import Template | ||
| from opaque_keys.edx.keys import CourseKey | ||
| from opaque_keys.edx.locations import Location | ||
| from xmodule.modulestore.exceptions import ItemNotFoundError | ||
| from contentstore.utils import course_image_url | ||
| from contentstore.utils import ( | ||
| course_image_url, | ||
| get_lms_link_for_about_page, | ||
| get_lms_link_for_dashboard, | ||
| get_lms_link_for_login, | ||
| ) | ||
| from models.settings import course_grading | ||
| from xmodule.fields import Date | ||
| from xmodule.modulestore.django import modulestore | ||
| from edxmako.shortcuts import render_to_string | ||
|
|
||
| # This list represents the attribute keys for a course's 'about' info. | ||
| # Note: The 'video' attribute is intentionally excluded as it must be | ||
|
|
@@ -19,14 +28,18 @@ | |
| 'short_description', | ||
| 'overview', | ||
| 'effort', | ||
| 'pre_enrollment_email', | ||
| 'post_enrollment_email', | ||
| 'pre_enrollment_email_subject', | ||
| 'post_enrollment_email_subject', | ||
| ] | ||
|
|
||
|
|
||
| class CourseDetails(object): | ||
| def __init__(self, org, course_id, run): | ||
| # still need these for now b/c the client's screen shows these 3 fields | ||
| self.org = org | ||
| self.course_id = course_id | ||
| self.course_id = course_id # This actually holds the course number. | ||
| self.run = run | ||
| self.start_date = None # 'start' | ||
| self.end_date = None # 'end' | ||
|
|
@@ -35,10 +48,15 @@ def __init__(self, org, course_id, run): | |
| self.syllabus = None # a pdf file asset | ||
| self.short_description = "" | ||
| self.overview = "" # html to render as the overview | ||
| self.pre_enrollment_email = CourseDetails.get_default_pre_enrollment_email(CourseKey.from_string(u'/'.join([self.org, self.course_id, self.run]))) | ||
| self.post_enrollment_email = CourseDetails.get_default_post_enrollment_email() | ||
| self.pre_enrollment_email_subject = "Thanks for Enrolling in {}".format(self.course_id) | ||
| self.post_enrollment_email_subject = "Thanks for Enrolling in {}".format(self.course_id) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i18n. Use named placeholders eg You're going to have to be careful how you i18n these strings so they show up in the user's language. You might need to use lazy translations. I'm not positive - you can test locally though! https://github.com/edx/edx-platform/blob/master/docs/en_us/developers/source/i18n.rst#building-and-testing-your-code |
||
| self.intro_video = None # a video pointer | ||
| self.effort = None # int hours/week | ||
| self.course_image_name = "" | ||
| self.course_image_asset_path = "" # URL of the course image | ||
| self.enable_enrollment_email = False | ||
|
|
||
| @classmethod | ||
| def _fetch_about_attribute(cls, course_key, attribute): | ||
|
|
@@ -66,6 +84,7 @@ def fetch(cls, course_key): | |
| course_details.enrollment_end = descriptor.enrollment_end | ||
| course_details.course_image_name = descriptor.course_image | ||
| course_details.course_image_asset_path = course_image_url(descriptor) | ||
| course_details.enable_enrollment_email = descriptor.enable_enrollment_email | ||
|
|
||
| for attribute in ABOUT_ATTRIBUTES: | ||
| value = cls._fetch_about_attribute(course_key, attribute) | ||
|
|
@@ -116,6 +135,11 @@ def update_from_json(cls, course_key, jsondict, user): | |
| # setter expects as input. | ||
| date = Date() | ||
|
|
||
| # Added to allow admins to enable/disable enrollment emails | ||
| if 'enable_enrollment_email' in jsondict: | ||
| descriptor.enable_enrollment_email = jsondict['enable_enrollment_email'] | ||
| dirty = True | ||
|
|
||
| if 'start_date' in jsondict: | ||
| converted = date.from_json(jsondict['start_date']) | ||
| else: | ||
|
|
@@ -200,6 +224,34 @@ def recompose_video_tag(video_key): | |
| video_key + '?rel=0" frameborder="0" allowfullscreen=""></iframe>' | ||
| return result | ||
|
|
||
| @staticmethod | ||
| def get_default_pre_enrollment_email(course_key): | ||
| """ | ||
| Returns the rendered default email body on enrolling before course starts. | ||
| """ | ||
| enroll_email_dict = { | ||
| 'dashboard_url': get_lms_link_for_dashboard(), | ||
| 'about_url': u"https:{}".format(get_lms_link_for_about_page(course_key)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We conditionalize use of |
||
| } | ||
| if settings.DEFAULT_PRE_ENROLLMENT_EMAIL: | ||
| return Template(settings.DEFAULT_PRE_ENROLLMENT_EMAIL).render_unicode(**enroll_email_dict) | ||
| else: | ||
| return render_to_string('emails/default_pre_enrollment_message.txt', enroll_email_dict) | ||
|
|
||
| @staticmethod | ||
| def get_default_post_enrollment_email(): | ||
| """ | ||
| Returns the rendered default email body on enrolling after course starts. | ||
| """ | ||
| enroll_email_dict = { | ||
| 'dashboard_url': get_lms_link_for_dashboard(), | ||
| 'signin_url': get_lms_link_for_login(), | ||
| } | ||
| if settings.DEFAULT_POST_ENROLLMENT_EMAIL: | ||
| return Template(settings.DEFAULT_POST_ENROLLMENT_EMAIL).render_unicode(**enroll_email_dict) | ||
| else: | ||
| return render_to_string('emails/default_post_enrollment_message.txt', enroll_email_dict) | ||
|
|
||
|
|
||
| # TODO move to a more general util? | ||
| class CourseSettingsEncoder(json.JSONEncoder): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| Test that theming works (for enrollment email template). | ||
| """ | ||
| from django.test import TestCase | ||
| from django.test.utils import override_settings | ||
|
|
||
| from opaque_keys.edx.locations import SlashSeparatedCourseKey | ||
| from models.settings.course_details import CourseDetails | ||
|
|
||
|
|
||
| class EnrollmentEmailThemingTestCase(TestCase): | ||
| """ | ||
| Tests that theming for enrollment email works. | ||
| """ | ||
| @override_settings(DEFAULT_PRE_ENROLLMENT_EMAIL='This is a test pre enrollment email template.') | ||
| def test_pre_enrollment_email_theming(self): | ||
| """ | ||
| Test that settings override template is used for default email on enrolling before course start. | ||
| """ | ||
| course_key = SlashSeparatedCourseKey('mitX', '101', 'test') | ||
| template = CourseDetails.get_default_pre_enrollment_email(course_key) | ||
| self.assertIn(u'This is a test pre enrollment email template.', template) | ||
|
|
||
| @override_settings(DEFAULT_POST_ENROLLMENT_EMAIL='This is a test post enrollment email template.') | ||
| def test_post_enrollment_email_theming(self): | ||
| """ | ||
| Test that settings override template is used for default email on enrolling after course start. | ||
| """ | ||
| template = CourseDetails.get_default_post_enrollment_email() | ||
| self.assertIn(u'This is a test post enrollment email template.', template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docstrings should describe the behavior that would lead to
Nonebeing returned.