Added ability to change header and content of static pages in two ways.

1. Using the pageheader and pagecontent block names.
2. Setting SiteConfiguration settings for each individual html page.

Co-authored by: Tomasz Gargas <tomasz@opencraft.com>
This commit is contained in:
Mike
2017-10-20 12:56:52 -05:00
committed by Tomasz Gargas
parent 9800ea2b5b
commit 0e2b667bb4
20 changed files with 229 additions and 75 deletions

View File

@@ -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"<i>Very Unique Test Header</i>"
test_content = u"<i>Very Unique Test Content</i>"
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.

View File

@@ -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

View File

@@ -10,11 +10,21 @@ from openedx.core.djangolib.markup import HTML, Text
<main id="main" aria-label="Content" tabindex="-1">
<section class="outside-app">
<h1>${_("Page not found")}</h1>
<p>${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('<a href="/">'),
link_end=HTML('</a>'),
email=HTML('<a href="mailto:{email}">{email}</a>').format(email=Text(static.get_tech_support_email_address()))
)}</p>
<h1>
<%block name="pageheader">${page_header or _("Page not found")}</%block>
</h1>
<p>
<%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('<a href="/">'),
link_end=HTML('</a>'),
email=HTML('<a href="mailto:{email}">{email}</a>').format(email=Text(static.get_tech_support_email_address()))
)}
% endif
</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("About")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("About")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Blog")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Blog")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Contact")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Contact")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Donate")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Donate")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -9,14 +9,20 @@ from openedx.core.djangolib.markup import HTML, Text
<main id="main" aria-label="Content" tabindex="-1">
<section class="outside-app">
<p>
${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),
)}
</p>
% if page_header:
<h1>
<%block name="pageheader">${page_header}</%block>
</h1>
% endif
<p>
<%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),
)}}
</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("FAQ")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("FAQ")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Help")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Help")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Honor Code")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Honor Code")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Jobs")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Jobs")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Cntent" tabindex="-1">
<section class="container about">
<h1>${_("Media Kit")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Media Kit")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -7,7 +7,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("In the Press")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("In the Press")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -7,7 +7,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("In the Press")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("In the Press")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -7,7 +7,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Privacy Policy")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Privacy Policy")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>

View File

@@ -8,15 +8,28 @@ from openedx.core.djangolib.markup import HTML, Text
<main id="main" aria-label="Content" tabindex="-1">
<section class="outside-app">
<h1>
${Text(_("Currently the {platform_name} servers are down")).format(
platform_name=HTML(u"<em>{}</em>").format(Text(static.get_platform_name()))
)}
</h1>
<p>
${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('<a href="mailto:{0}">{0}</a>').format(Text(static.get_tech_support_email_address()))
)}</p>
<h1>
<%block name="pageheader">
% if page_header:
${page_header}
% else:
${Text(_("Currently the {platform_name} servers are down")).format(
platform_name=HTML(u"<em>{}</em>").format(Text(static.get_platform_name()))
)}
% endif
</%block>
</h1>
<p>
<%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('<a href="mailto:{0}">{0}</a>').format(Text(static.get_tech_support_email_address()))
)}
% endif
</%block>
</p>
</section>
</main>

View File

@@ -8,17 +8,29 @@ from openedx.core.djangolib.markup import HTML, Text
<main id="main" aria-label="Content" tabindex="-1">
<section class="outside-app">
<h1>
${Text(_(u"There has been a 500 error on the {platform_name} servers")).format(
platform_name=HTML("<em>{platform_name}</em>").format(platform_name=Text(static.get_platform_name()))
)}
</h1>
<p>
${Text(_('Please wait a few seconds and then reload the page. If the problem persists, please email us at {email}.')).format(
email=HTML('<a href="mailto:{email}">{email}</a>').format(
email=Text(static.get_tech_support_email_address())
)
)}
</p>
<h1>
<%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("<em>{platform_name}</em>").format(platform_name=Text(static.get_platform_name()))
)}
% endif
</%block>
</h1>
<p>
<%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('<a href="mailto:{email}">{email}</a>').format(
email=Text(static.get_tech_support_email_address())
)
)}
% endif
</%block>
</p>
</section>
</main>

View File

@@ -8,16 +8,28 @@ from openedx.core.djangolib.markup import HTML, Text
<main id="main" aria-label="Content" tabindex="-1">
<section class="outside-app">
<h1>
${Text(_("Currently the {platform_name} servers are overloaded")).format(
platform_name=HTML("<em>{}</em>").format(platform_name=Text(static.get_platform_name()))
)}
</h1>
<p>
${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('<a href="mailto:{0}">{0}</a>').format(tech_support_email=Text(static.get_tech_support_email_address()))
)}
</p>
<h1>
<%block name="pageheader">
% if page_header:
${page_header}
% else:
${Text(_("Currently the {platform_name} servers are overloaded")).format(
platform_name=HTML("<em>{}</em>").format(platform_name=Text(static.get_platform_name()))
)}
% endif
</%block>
</h1>
<p>
<%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('<a href="mailto:{0}">{0}</a>').format(tech_support_email=Text(static.get_tech_support_email_address()))
)}
% endif
</%block>
</p>
</section>
</main>

View File

@@ -6,7 +6,11 @@
<main id="main" aria-label="Content" tabindex="-1">
<section class="container about">
<h1>${_("Terms of Service")}</h1>
<p>${_("This page left intentionally blank. Feel free to add your own content.")}</p>
<h1>
<%block name="pageheader">${page_header or _("Terms of Service")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>