diff --git a/lms/djangoapps/static_template_view/tests/test_views.py b/lms/djangoapps/static_template_view/tests/test_views.py index e6c6b5c1d9..0fafc0cc1f 100644 --- a/lms/djangoapps/static_template_view/tests/test_views.py +++ b/lms/djangoapps/static_template_view/tests/test_views.py @@ -5,11 +5,16 @@ from django.conf import settings from django.core.urlresolvers import reverse from django.test import TestCase +from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context + class MarketingSiteViewTests(TestCase): """ Tests for the marketing site views """ def _test_view(self, view_name, mimetype): + """ + Gets a view and tests that it exists. + """ resp = self.client.get(reverse(view_name)) self.assertEqual(resp.status_code, 200) self.assertEqual(resp['Content-Type'], mimetype) @@ -26,6 +31,36 @@ class MarketingSiteViewTests(TestCase): """ self._test_view('about', 'text/html') + def test_about_with_site_configuration(self): + """ + Test the about view with the header and content set in SiteConfiguration. + """ + test_header = u"Very Unique Test Header" + test_content = u"Very Unique Test Content" + test_header_key = u'static_template_about_header' + test_content_key = u'static_template_about_content' + response = None + configuration = {test_header_key: test_header, test_content_key: test_content} + with with_site_configuration_context(configuration=configuration): + response = self.client.get(reverse("about")) + self.assertIn(test_header.encode('utf-8'), response.content) + self.assertIn(test_content.encode('utf-8'), response.content) + + def test_about_with_site_configuration_and_html(self): + """ + Test the about view with html in the header. + """ + test_header = u"Very Unique Test Header" + test_content = u"Very Unique Test Content" + test_header_key = u'static_template_about_header' + test_content_key = u'static_template_about_content' + response = None + configuration = {test_header_key: test_header, test_content_key: test_content} + with with_site_configuration_context(configuration=configuration): + response = self.client.get(reverse("about")) + self.assertIn(test_header.encode('utf-8'), response.content) + self.assertIn(test_content.encode('utf-8'), response.content) + def test_404(self): """ Test the 404 view. diff --git a/lms/djangoapps/static_template_view/views.py b/lms/djangoapps/static_template_view/views.py index 5c1e2200db..0aa3b8831b 100644 --- a/lms/djangoapps/static_template_view/views.py +++ b/lms/djangoapps/static_template_view/views.py @@ -9,9 +9,12 @@ from django.conf import settings from django.http import Http404, HttpResponseNotFound, HttpResponseServerError from django.shortcuts import redirect from django.template import TemplateDoesNotExist +from django.utils.safestring import mark_safe from django.views.decorators.csrf import ensure_csrf_cookie +from mako.exceptions import TopLevelLookupException from edxmako.shortcuts import render_to_response, render_to_string +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from util.cache import cache_if_anonymous from util.views import fix_crum_request @@ -51,7 +54,18 @@ def render(request, template): # This is necessary for the dialog presented with the TOS in /register if template == 'honor.html': context['allow_iframing'] = True - return render_to_response('static_templates/' + template, context, content_type=content_type) + # Format Examples: static_template_about_header + configuration_base = 'static_template_' + template.replace('.html', '').replace('-', '_') + page_header = configuration_helpers.get_value(configuration_base + '_header') + page_content = configuration_helpers.get_value(configuration_base + '_content') + if page_header: + context['page_header'] = mark_safe(page_header) + if page_content: + context['page_content'] = mark_safe(page_content) + result = render_to_response('static_templates/' + template, context, content_type=content_type) + return result + except TopLevelLookupException: + raise Http404 except TemplateDoesNotExist: raise Http404 diff --git a/lms/templates/static_templates/404.html b/lms/templates/static_templates/404.html index 6bfbb411d5..28c01904bb 100644 --- a/lms/templates/static_templates/404.html +++ b/lms/templates/static_templates/404.html @@ -10,11 +10,21 @@ from openedx.core.djangolib.markup import HTML, Text
-

${_("Page not found")}

-

${Text(_('The page that you were looking for was not found. Go back to the {link_start}homepage{link_end} or let us know about any pages that may have been moved at {email}.')).format( - link_start=HTML(''), - link_end=HTML(''), - email=HTML('{email}').format(email=Text(static.get_tech_support_email_address())) - )}

+

+ <%block name="pageheader">${page_header or _("Page not found")} +

+

+ <%block name="pagecontent"> + % if page_content: + ${page_content} + % else: + ${Text(_('The page that you were looking for was not found. Go back to the {link_start}homepage{link_end} or let us know about any pages that may have been moved at {email}.')).format( + link_start=HTML(''), + link_end=HTML(''), + email=HTML('{email}').format(email=Text(static.get_tech_support_email_address())) + )} + % endif + +

diff --git a/lms/templates/static_templates/about.html b/lms/templates/static_templates/about.html index 1192644eb2..2bedeb61f6 100644 --- a/lms/templates/static_templates/about.html +++ b/lms/templates/static_templates/about.html @@ -6,7 +6,11 @@
-

${_("About")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("About")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/blog.html b/lms/templates/static_templates/blog.html index 77a38163f2..1256e97ee1 100644 --- a/lms/templates/static_templates/blog.html +++ b/lms/templates/static_templates/blog.html @@ -6,7 +6,11 @@
-

${_("Blog")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Blog")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/contact.html b/lms/templates/static_templates/contact.html index 6cebfe2792..d607dccb65 100644 --- a/lms/templates/static_templates/contact.html +++ b/lms/templates/static_templates/contact.html @@ -6,7 +6,11 @@
-

${_("Contact")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Contact")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/donate.html b/lms/templates/static_templates/donate.html index 57d4b0d64c..86d6e0812a 100644 --- a/lms/templates/static_templates/donate.html +++ b/lms/templates/static_templates/donate.html @@ -6,7 +6,11 @@
-

${_("Donate")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Donate")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/embargo.html b/lms/templates/static_templates/embargo.html index 3ec78df2b3..bb2188e7eb 100644 --- a/lms/templates/static_templates/embargo.html +++ b/lms/templates/static_templates/embargo.html @@ -9,14 +9,20 @@ from openedx.core.djangolib.markup import HTML, Text
-

- ${Text(_("Our system indicates that you are trying to access this {platform_name} " - "course from a country or region currently subject to U.S. economic and trade sanctions." - "Unfortunately, because {platform_name} is required to comply with export controls," - "we cannot allow you to access this course at this time." - )).format( - platform_name=Text(settings.PLATFORM_NAME), - )} -

+ % if page_header: +

+ <%block name="pageheader">${page_header} +

+ % endif +

+ <%block name="pagecontent">${page_content or Text(_("Our system indicates that you are trying to access this {platform_name} " + "course from a country or region currently subject to U.S. economic and trade sanctions." + "Unfortunately, because {platform_name} is required to comply with export controls," + "we cannot allow you to access this course at this time." + )).format( + platform_name=Text(settings.PLATFORM_NAME), + )}} + +

diff --git a/lms/templates/static_templates/faq.html b/lms/templates/static_templates/faq.html index e5be46d917..d4c413e02c 100644 --- a/lms/templates/static_templates/faq.html +++ b/lms/templates/static_templates/faq.html @@ -6,7 +6,11 @@
-

${_("FAQ")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("FAQ")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/help.html b/lms/templates/static_templates/help.html index 2bd7ade548..546f2e0410 100644 --- a/lms/templates/static_templates/help.html +++ b/lms/templates/static_templates/help.html @@ -6,7 +6,11 @@
-

${_("Help")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Help")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/honor.html b/lms/templates/static_templates/honor.html index d1fe410c3c..4fee7f2cee 100644 --- a/lms/templates/static_templates/honor.html +++ b/lms/templates/static_templates/honor.html @@ -6,7 +6,11 @@
-

${_("Honor Code")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Honor Code")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/jobs.html b/lms/templates/static_templates/jobs.html index 62a29d4a89..3a736dbab1 100644 --- a/lms/templates/static_templates/jobs.html +++ b/lms/templates/static_templates/jobs.html @@ -6,7 +6,11 @@
-

${_("Jobs")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Jobs")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/media-kit.html b/lms/templates/static_templates/media-kit.html index 857da112d4..4819bcaa9f 100644 --- a/lms/templates/static_templates/media-kit.html +++ b/lms/templates/static_templates/media-kit.html @@ -6,7 +6,11 @@
-

${_("Media Kit")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Media Kit")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/news.html b/lms/templates/static_templates/news.html index 9f6231808f..c7337a2ee6 100644 --- a/lms/templates/static_templates/news.html +++ b/lms/templates/static_templates/news.html @@ -7,7 +7,11 @@
-

${_("In the Press")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("In the Press")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/press.html b/lms/templates/static_templates/press.html index 9f6231808f..c7337a2ee6 100644 --- a/lms/templates/static_templates/press.html +++ b/lms/templates/static_templates/press.html @@ -7,7 +7,11 @@
-

${_("In the Press")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("In the Press")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/privacy.html b/lms/templates/static_templates/privacy.html index 03df8b8d2f..1c4830feee 100644 --- a/lms/templates/static_templates/privacy.html +++ b/lms/templates/static_templates/privacy.html @@ -7,7 +7,11 @@
-

${_("Privacy Policy")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Privacy Policy")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +

diff --git a/lms/templates/static_templates/server-down.html b/lms/templates/static_templates/server-down.html index aff93094fc..982bb1ea19 100644 --- a/lms/templates/static_templates/server-down.html +++ b/lms/templates/static_templates/server-down.html @@ -8,15 +8,28 @@ from openedx.core.djangolib.markup import HTML, Text
-

- ${Text(_("Currently the {platform_name} servers are down")).format( - platform_name=HTML(u"{}").format(Text(static.get_platform_name())) - )} -

-

- ${Text(_("Our staff is currently working to get the site back up as soon as possible. " - "Please email us at {tech_support_email} to report any problems or downtime.")).format( - tech_support_email=HTML('{0}').format(Text(static.get_tech_support_email_address())) - )}

+

+ <%block name="pageheader"> + % if page_header: + ${page_header} + % else: + ${Text(_("Currently the {platform_name} servers are down")).format( + platform_name=HTML(u"{}").format(Text(static.get_platform_name())) + )} + % endif + +

+

+ <%block name="pagecontent"> + % if page_content: + ${page_content} + % else: + ${Text(_("Our staff is currently working to get the site back up as soon as possible. " + "Please email us at {tech_support_email} to report any problems or downtime.")).format( + tech_support_email=HTML('{0}').format(Text(static.get_tech_support_email_address())) + )} + % endif + +

diff --git a/lms/templates/static_templates/server-error.html b/lms/templates/static_templates/server-error.html index c89ace1000..4a022d931b 100644 --- a/lms/templates/static_templates/server-error.html +++ b/lms/templates/static_templates/server-error.html @@ -8,17 +8,29 @@ from openedx.core.djangolib.markup import HTML, Text
-

- ${Text(_(u"There has been a 500 error on the {platform_name} servers")).format( - platform_name=HTML("{platform_name}").format(platform_name=Text(static.get_platform_name())) - )} -

-

- ${Text(_('Please wait a few seconds and then reload the page. If the problem persists, please email us at {email}.')).format( - email=HTML('{email}').format( - email=Text(static.get_tech_support_email_address()) - ) - )} -

+

+ <%block name="pageheader"> + % if page_header: + ${page_header} + % else: + ${Text(_(u"There has been a 500 error on the {platform_name} servers")).format( + platform_name=HTML("{platform_name}").format(platform_name=Text(static.get_platform_name())) + )} + % endif + +

+

+ <%block name="pagecontent"> + % if page_content: + ${page_content} + % else: + ${Text(_('Please wait a few seconds and then reload the page. If the problem persists, please email us at {email}.')).format( + email=HTML('{email}').format( + email=Text(static.get_tech_support_email_address()) + ) + )} + % endif + +

diff --git a/lms/templates/static_templates/server-overloaded.html b/lms/templates/static_templates/server-overloaded.html index d812fb0969..0b5d9c00bb 100644 --- a/lms/templates/static_templates/server-overloaded.html +++ b/lms/templates/static_templates/server-overloaded.html @@ -8,16 +8,28 @@ from openedx.core.djangolib.markup import HTML, Text
-

- ${Text(_("Currently the {platform_name} servers are overloaded")).format( - platform_name=HTML("{}").format(platform_name=Text(static.get_platform_name())) - )} -

-

- ${Text(_("Our staff is currently working to get the site back up as soon as possible. " - "Please email us at {tech_support_email} to report any problems or downtime.")).format( - tech_support_email=HTML('{0}').format(tech_support_email=Text(static.get_tech_support_email_address())) - )} -

+

+ <%block name="pageheader"> + % if page_header: + ${page_header} + % else: + ${Text(_("Currently the {platform_name} servers are overloaded")).format( + platform_name=HTML("{}").format(platform_name=Text(static.get_platform_name())) + )} + % endif + +

+

+ <%block name="pagecontent"> + % if page_content: + ${page_content} + % else: + ${Text(_("Our staff is currently working to get the site back up as soon as possible. " + "Please email us at {tech_support_email} to report any problems or downtime.")).format( + tech_support_email=HTML('{0}').format(tech_support_email=Text(static.get_tech_support_email_address())) + )} + % endif + +

diff --git a/lms/templates/static_templates/tos.html b/lms/templates/static_templates/tos.html index d48d437fd5..107b035943 100644 --- a/lms/templates/static_templates/tos.html +++ b/lms/templates/static_templates/tos.html @@ -6,7 +6,11 @@
-

${_("Terms of Service")}

-

${_("This page left intentionally blank. Feel free to add your own content.")}

+

+ <%block name="pageheader">${page_header or _("Terms of Service")} +

+

+ <%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")} +