From ce9c258f8b981a5f8ef24308805e6dfe365949ab Mon Sep 17 00:00:00 2001 From: Will Daly Date: Tue, 3 Feb 2015 08:59:32 -0500 Subject: [PATCH] Update country access message end-points to be backwards compatible with embargo theme templates Move default country access messages out of static_templates, so they are not served by other Django views. --- common/djangoapps/embargo/messages.py | 13 +++++++++++-- common/djangoapps/embargo/tests/test_views.py | 19 +++++++++++++++++++ common/djangoapps/embargo/views.py | 9 +++++++-- .../default_courseware.html} | 0 .../default_enrollment.html} | 0 5 files changed, 37 insertions(+), 4 deletions(-) rename lms/templates/{static_templates/courseware_access_block.html => embargo/default_courseware.html} (100%) rename lms/templates/{static_templates/enrollment_access_block.html => embargo/default_enrollment.html} (100%) diff --git a/common/djangoapps/embargo/messages.py b/common/djangoapps/embargo/messages.py index dd2764ad25..e8af1f4783 100644 --- a/common/djangoapps/embargo/messages.py +++ b/common/djangoapps/embargo/messages.py @@ -19,7 +19,7 @@ BlockedMessage = namedtuple('BlockedMessage', [ ENROLL_MESSAGES = { 'default': BlockedMessage( description='Default', - template='static_templates/enrollment_access_block.html' + template='embargo/default_enrollment.html' ), 'embargo': BlockedMessage( description='Embargo', @@ -31,10 +31,19 @@ ENROLL_MESSAGES = { COURSEWARE_MESSAGES = { 'default': BlockedMessage( description='Default', - template='static_templates/courseware_access_block.html' + template='embargo/default_courseware.html' ), 'embargo': BlockedMessage( description='Embargo', template='static_templates/embargo.html' ) } + +# Backwards compatibility with themes +# created for earlier implementations of the embargo app. +CUSTOM_THEME_OVERRIDES = { + 'embargo': BlockedMessage( + description='Embargo', + template='static_templates/theme-embargo.html' + ) +} diff --git a/common/djangoapps/embargo/tests/test_views.py b/common/djangoapps/embargo/tests/test_views.py index 1af91517aa..74c1caa5ef 100644 --- a/common/djangoapps/embargo/tests/test_views.py +++ b/common/djangoapps/embargo/tests/test_views.py @@ -5,6 +5,7 @@ from mock import patch from django.test import TestCase from django.core.urlresolvers import reverse from django.conf import settings +from mako.exceptions import TopLevelLookupException import ddt from util.testing import UrlResetMixin @@ -47,6 +48,24 @@ class CourseAccessMessageViewTest(UrlResetMixin, TestCase): def test_invalid_message_key(self, access_point): self._load_page(access_point, 'invalid', expected_status=404) + @patch.dict(settings.FEATURES, {'USE_CUSTOM_THEME': True}) + @ddt.data('enrollment', 'courseware') + def test_custom_theme_override(self, access_point): + # Custom override specified for the "embargo" message + # for backwards compatibility with previous versions + # of the embargo app. + # This template isn't available by default, but we can at least + # verify that the view will look for it when the USE_CUSTOM_THEME + # feature flag is specified. + with self.assertRaisesRegexp(TopLevelLookupException, 'static_templates/theme-embargo.html'): + self._load_page(access_point, 'embargo') + + @patch.dict(settings.FEATURES, {'USE_CUSTOM_THEME': True}) + @ddt.data('enrollment', 'courseware') + def test_custom_theme_override_not_specified(self, access_point): + # No custom override specified for the "default" message + self._load_page(access_point, 'default') + def _load_page(self, access_point, message_key, expected_status=200): """Load the message page and check the status code. """ url = reverse('embargo_blocked_message', kwargs={ diff --git a/common/djangoapps/embargo/views.py b/common/djangoapps/embargo/views.py index d18ec4e1cd..5ac2fb9966 100644 --- a/common/djangoapps/embargo/views.py +++ b/common/djangoapps/embargo/views.py @@ -2,6 +2,7 @@ from django.http import Http404 from django.views.generic.base import View +from django.conf import settings from edxmako.shortcuts import render_to_response @@ -55,14 +56,18 @@ class CourseAccessMessageView(View): """ message_dict = dict() + # Backwards compatibility with themes created for + # earlier implementations of the embargo app. + if settings.FEATURES.get('USE_CUSTOM_THEME') and message_key in messages.CUSTOM_THEME_OVERRIDES: + message_dict = messages.CUSTOM_THEME_OVERRIDES + # The access point determines which set of messages to use. # This allows us to show different messages to students who # are enrolling in a course than we show to students # who are enrolled and accessing courseware. - if access_point == self.ENROLLMENT_ACCESS_POINT: + elif access_point == self.ENROLLMENT_ACCESS_POINT: message_dict = messages.ENROLL_MESSAGES elif access_point == self.COURSEWARE_ACCESS_POINT: message_dict = messages.COURSEWARE_MESSAGES - # Return the message corresponding to the given key if one is available. return message_dict.get(message_key) diff --git a/lms/templates/static_templates/courseware_access_block.html b/lms/templates/embargo/default_courseware.html similarity index 100% rename from lms/templates/static_templates/courseware_access_block.html rename to lms/templates/embargo/default_courseware.html diff --git a/lms/templates/static_templates/enrollment_access_block.html b/lms/templates/embargo/default_enrollment.html similarity index 100% rename from lms/templates/static_templates/enrollment_access_block.html rename to lms/templates/embargo/default_enrollment.html