Commit 09c2468f by Clinton Blackburn Committed by Clinton Blackburn

Added view for developers to preview emails in browser

This is a quick-and-dirty view for developers to paste code and preview
email content. It is not intended for public consumption of any form.

EDUCATOR-815
parent 0ed68ccd
"""
URLs for the course publisher views.
"""
from django.conf.urls import include, url from django.conf.urls import include, url
from course_discovery.apps.publisher import views from course_discovery.apps.publisher import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.Dashboard.as_view(), name='publisher_dashboard'), url(r'^$', views.Dashboard.as_view(), name='publisher_dashboard'),
url(r'^admin/importcourses/$', views.AdminImportCourse.as_view(), name='publisher_admin_import_course'),
url(r'^api/', include('course_discovery.apps.publisher.api.urls', namespace='api')), url(r'^api/', include('course_discovery.apps.publisher.api.urls', namespace='api')),
url(r'^courses/$', views.CourseListView.as_view(), name='publisher_courses'), url(r'^courses/$', views.CourseListView.as_view(), name='publisher_courses'),
url(r'^courses/new/$', views.CreateCourseView.as_view(), name='publisher_courses_new'), url(r'^courses/new/$', views.CreateCourseView.as_view(), name='publisher_courses_new'),
...@@ -24,7 +22,6 @@ urlpatterns = [ ...@@ -24,7 +22,6 @@ urlpatterns = [
views.CreateRunFromDashboardView.as_view(), views.CreateRunFromDashboardView.as_view(),
name='publisher_create_run_from_dashboard' name='publisher_create_run_from_dashboard'
), ),
url( url(
r'^user/toggle/email_settings/$', r'^user/toggle/email_settings/$',
views.ToggleEmailNotification.as_view(), views.ToggleEmailNotification.as_view(),
...@@ -32,6 +29,5 @@ urlpatterns = [ ...@@ -32,6 +29,5 @@ urlpatterns = [
), ),
url(r'^courses/(?P<pk>\d+)/revisions/(?P<revision_id>\d+)/$', views.CourseRevisionView.as_view(), url(r'^courses/(?P<pk>\d+)/revisions/(?P<revision_id>\d+)/$', views.CourseRevisionView.as_view(),
name='publisher_course_revision'), name='publisher_course_revision'),
url(r'^email_preview/$', views.EmailPreviewView.as_view(), name='email_preview'),
url(r'^admin/importcourses/$', views.AdminImportCourse.as_view(), name='publisher_admin_import_course'),
] ]
...@@ -39,7 +39,6 @@ from course_discovery.apps.publisher.wrappers import CourseRunWrapper ...@@ -39,7 +39,6 @@ from course_discovery.apps.publisher.wrappers import CourseRunWrapper
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
ROLE_WIDGET_HEADINGS = { ROLE_WIDGET_HEADINGS = {
PublisherUserRole.PartnerManager: _('PARTNER MANAGER'), PublisherUserRole.PartnerManager: _('PARTNER MANAGER'),
PublisherUserRole.ProjectCoordinator: _('PROJECT COORDINATOR'), PublisherUserRole.ProjectCoordinator: _('PROJECT COORDINATOR'),
...@@ -1138,3 +1137,45 @@ class AdminImportCourse(mixins.LoginRequiredMixin, TemplateView): ...@@ -1138,3 +1137,45 @@ class AdminImportCourse(mixins.LoginRequiredMixin, TemplateView):
messages.error(request, str(ex)) messages.error(request, str(ex))
return super(AdminImportCourse, self).get(request, args, **kwargs) return super(AdminImportCourse, self).get(request, args, **kwargs)
class EmailPreviewView(mixins.LoginRequiredMixin, TemplateView): # pragma: no cover
template_name = 'publisher/email_preview.html'
def get_email_content(self):
# NOTE: It is up to you, the developer, to place content here.
# The simplest approach is to simply copy the code from publisher.emails
# and paste it here.
# txt_template = 'publisher/email/course_run/preview_available.txt'
# html_template = 'publisher/email/course_run/preview_available.html'
# course_run = CourseRun.objects.first()
# site = Site.objects.first()
# course_key = CourseKey.from_string(course_run.lms_course_id)
# context = {
# 'sender_role': PublisherUserRole.Publisher,
# 'recipient_name': 'DEMO USER',
# 'course_run': course_run,
# 'course_run_key': course_key,
# 'course_run_publisher_url': 'https://{host}{path}'.format(
# host=site.domain.strip('/'), path=course_run.get_absolute_url()),
# 'contact_us_email': 'demo@example.com',
# 'platform_name': settings.PLATFORM_NAME,
# }
# template = get_template(txt_template)
# plain_content = template.render(context)
# template = get_template(html_template)
# html_content = template.render(context)
#
# return plain_content, html_content
raise NotImplementedError
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
text_content, html_content = self.get_email_content()
context.update({
'html_content': html_content,
'text_content': text_content,
})
return context
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Email Preview</title>
</head>
<body>
<h1>HTML</h1>
{{ html_content|safe }}
<h1>Text</h1>
<pre>
{{ text_content }}
</pre>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment