From 6277bd27e68676695f0219bc033ba319e66bd408 Mon Sep 17 00:00:00 2001 From: Saleem Latif Date: Tue, 14 Jun 2016 13:31:45 +0500 Subject: [PATCH] Remove all usages of USE_CUSTOM_THEME and THEME_NAME from python files --- cms/envs/aws.py | 3 - cms/envs/bok_choy.env.json | 1 - cms/startup.py | 34 ---------- cms/tests/test_startup.py | 47 -------------- .../management/commands/preprocess_assets.py | 64 ------------------- common/djangoapps/embargo/messages.py | 9 --- common/djangoapps/embargo/tests/test_views.py | 24 ++++--- common/djangoapps/embargo/views.py | 7 +- .../templates/static_content.html | 5 -- .../templates/static_templates/embargo.html | 23 +++++++ .../courseware/tests/test_favicon.py | 15 ----- lms/envs/aws.py | 3 - lms/envs/bok_choy.env.json | 1 - lms/envs/common.py | 3 - lms/startup.py | 37 ----------- lms/static/sass/lms-course-rtl.scss | 4 -- lms/static/sass/lms-course.scss | 4 -- lms/static/sass/lms-footer-rtl.scss | 4 -- lms/static/sass/lms-footer.scss | 4 -- lms/static/sass/lms-main-v1-rtl.scss | 4 -- lms/static/sass/lms-main-v1.scss | 4 -- lms/static/themed_sass/README.rst | 2 - lms/templates/header.html | 2 +- lms/templates/main.html | 2 +- lms/templates/themable-footer.html | 11 ---- lms/urls.py | 55 +++++++--------- openedx/core/djangoapps/theming/helpers.py | 20 ------ .../tests/test_theme_style_overrides.py | 54 ++++++++++++++++ pavelib/assets.py | 18 ------ pavelib/paver_tests/test_servers.py | 13 ---- themes/README.rst | 14 ---- .../templates/embargo/default_courseware.html | 11 ++++ .../templates/embargo/default_enrollment.html | 11 ++++ .../stanford-style/lms/templates/footer.html | 2 +- .../templates/static_templates/embargo.html | 17 +++++ 35 files changed, 155 insertions(+), 377 deletions(-) delete mode 100644 cms/tests/test_startup.py delete mode 100644 common/djangoapps/edxmako/management/commands/preprocess_assets.py create mode 100644 common/test/test-theme/lms/templates/static_templates/embargo.html delete mode 100644 lms/static/themed_sass/README.rst delete mode 100644 lms/templates/themable-footer.html create mode 100644 themes/stanford-style/lms/templates/embargo/default_courseware.html create mode 100644 themes/stanford-style/lms/templates/embargo/default_enrollment.html create mode 100644 themes/stanford-style/lms/templates/static_templates/embargo.html diff --git a/cms/envs/aws.py b/cms/envs/aws.py index 8c0f75a8dd..964f7ba97a 100644 --- a/cms/envs/aws.py +++ b/cms/envs/aws.py @@ -209,9 +209,6 @@ COURSES_WITH_UNSAFE_CODE = ENV_TOKENS.get("COURSES_WITH_UNSAFE_CODE", []) ASSET_IGNORE_REGEX = ENV_TOKENS.get('ASSET_IGNORE_REGEX', ASSET_IGNORE_REGEX) -# Theme overrides -THEME_NAME = ENV_TOKENS.get('THEME_NAME', None) - # following setting is for backward compatibility if ENV_TOKENS.get('COMPREHENSIVE_THEME_DIR', None): COMPREHENSIVE_THEME_DIR = ENV_TOKENS.get('COMPREHENSIVE_THEME_DIR') diff --git a/cms/envs/bok_choy.env.json b/cms/envs/bok_choy.env.json index 8abd2fad4c..9c2fde40ee 100644 --- a/cms/envs/bok_choy.env.json +++ b/cms/envs/bok_choy.env.json @@ -101,7 +101,6 @@ "STATIC_URL_BASE": "/static/", "SYSLOG_SERVER": "", "TECH_SUPPORT_EMAIL": "technical@example.com", - "THEME_NAME": "", "TIME_ZONE": "America/New_York", "WIKI_ENABLED": true, "OAUTH_OIDC_ISSUER": "https://www.example.com/oauth2" diff --git a/cms/startup.py b/cms/startup.py index f51b3c1325..37baf3b88d 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -40,9 +40,6 @@ def run(): add_mimetypes() - if settings.FEATURES.get('USE_CUSTOM_THEME', False): - enable_theme() - # In order to allow descriptors to use a handler url, we need to # monkey-patch the x_module library. # TODO: Remove this code when Runtimes are no longer created by modulestores @@ -63,34 +60,3 @@ def add_mimetypes(): mimetypes.add_type('application/x-font-opentype', '.otf') mimetypes.add_type('application/x-font-ttf', '.ttf') mimetypes.add_type('application/font-woff', '.woff') - - -def enable_theme(): - """ - Enable the settings for a custom theme, whose files should be stored - in ENV_ROOT/themes/THEME_NAME (e.g., edx_all/themes/stanford). - At this moment this is actually just a fix for collectstatic, - (see https://openedx.atlassian.net/browse/TNL-726), - but can be improved with a full theming option also for Studio - in the future (see lms.startup) - """ - # Workaround for setting THEME_NAME to an empty - # string which is the default due to this ansible - # bug: https://github.com/ansible/ansible/issues/4812 - if settings.THEME_NAME == "": - settings.THEME_NAME = None - return - - assert settings.FEATURES['USE_CUSTOM_THEME'] - settings.FAVICON_PATH = 'themes/{name}/images/favicon.ico'.format( - name=settings.THEME_NAME - ) - - # Calculate the location of the theme's files - theme_root = settings.ENV_ROOT / "themes" / settings.THEME_NAME - - # Namespace the theme's static files to 'themes/' to - # avoid collisions with default edX static files - settings.STATICFILES_DIRS.append( - (u'themes/{}'.format(settings.THEME_NAME), theme_root / 'static') - ) diff --git a/cms/tests/test_startup.py b/cms/tests/test_startup.py deleted file mode 100644 index 9ffe33c702..0000000000 --- a/cms/tests/test_startup.py +++ /dev/null @@ -1,47 +0,0 @@ -""" -Test cms startup -""" - -from django.conf import settings - -from django.test import TestCase -from django.test.utils import override_settings - -from mock import patch -from cms.startup import run, enable_theme - - -class StartupTestCase(TestCase): - """ - Test cms startup - """ - - def setUp(self): - super(StartupTestCase, self).setUp() - - @patch.dict("django.conf.settings.FEATURES", {"USE_CUSTOM_THEME": True}) - @override_settings(THEME_NAME="bar") - def test_run_with_theme(self): - self.assertEqual(settings.FEATURES["USE_CUSTOM_THEME"], True) - with patch('cms.startup.enable_theme') as mock_enable_theme: - run() - self.assertTrue(mock_enable_theme.called) - - @patch.dict("django.conf.settings.FEATURES", {"USE_CUSTOM_THEME": False}) - def test_run_without_theme(self): - self.assertEqual(settings.FEATURES["USE_CUSTOM_THEME"], False) - with patch('cms.startup.enable_theme') as mock_enable_theme: - run() - self.assertFalse(mock_enable_theme.called) - - @patch.dict("django.conf.settings.FEATURES", {"USE_CUSTOM_THEME": True}) - @override_settings(THEME_NAME="bar") - @override_settings(FAVICON_PATH="images/favicon.ico") - def test_enable_theme(self): - enable_theme() - self.assertEqual( - settings.FAVICON_PATH, - 'themes/bar/images/favicon.ico' - ) - exp_path = (u'themes/bar', settings.ENV_ROOT / "themes/bar/static") - self.assertIn(exp_path, settings.STATICFILES_DIRS) diff --git a/common/djangoapps/edxmako/management/commands/preprocess_assets.py b/common/djangoapps/edxmako/management/commands/preprocess_assets.py deleted file mode 100644 index 8d3cf5608a..0000000000 --- a/common/djangoapps/edxmako/management/commands/preprocess_assets.py +++ /dev/null @@ -1,64 +0,0 @@ -""" -Preprocess templatized asset files, enabling asset authors to use -Python/Django inside of Sass and CoffeeScript. This preprocessing -will happen before the invocation of the asset compiler (currently -handled by the assets paver file). - -For this to work, assets need to be named with the appropriate -template extension (e.g., .mako for Mako templates). Currently Mako -is the only template engine supported. -""" - -import os -import textwrap - -from django.core.management.base import BaseCommand -from django.conf import settings - - -class Command(BaseCommand): - """ - Basic management command to preprocess asset template files. - """ - - help = "Preprocess asset template files to ready them for compilation." - - def add_arguments(self, parser): - parser.add_argument('files', type=unicode, nargs='+', help='files to pre-process') - parser.add_argument('dest_dir', type=unicode, help='destination directory') - - def handle(self, *args, **options): - theme_name = getattr(settings, "THEME_NAME", None) - use_custom_theme = settings.FEATURES.get("USE_CUSTOM_THEME", False) - if not use_custom_theme or not theme_name: - # No custom theme, nothing to do! - return - - dest_dir = options['dest_dir'] - for source_file in options['files']: - self.process_one_file(source_file, dest_dir, theme_name) - - def process_one_file(self, source_file, dest_dir, theme_name): - """Pre-process a .scss file to replace our markers with real code.""" - with open(source_file) as fsource: - original_content = fsource.read() - - content = original_content.replace( - "//", - "@import '{}';".format(theme_name), - ) - - if content != original_content: - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - dest_file = os.path.join(dest_dir, os.path.basename(source_file)) - with open(dest_file, "w") as fout: - fout.write(textwrap.dedent("""\ - /* - * This file is dynamically generated and ignored by Git. - * DO NOT MAKE CHANGES HERE. Instead, go edit its source: - * {} - */ - \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n - """.format(source_file))) - fout.write(content) diff --git a/common/djangoapps/embargo/messages.py b/common/djangoapps/embargo/messages.py index e8af1f4783..04c7cd871d 100644 --- a/common/djangoapps/embargo/messages.py +++ b/common/djangoapps/embargo/messages.py @@ -38,12 +38,3 @@ COURSEWARE_MESSAGES = { 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 6ef81f6618..b4b6bb0749 100644 --- a/common/djangoapps/embargo/tests/test_views.py +++ b/common/djangoapps/embargo/tests/test_views.py @@ -2,7 +2,6 @@ import unittest 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 @@ -11,6 +10,7 @@ import ddt from util.testing import UrlResetMixin from embargo import messages from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') @@ -53,23 +53,21 @@ class CourseAccessMessageViewTest(CacheIsolationTestCase, UrlResetMixin): 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}) + @with_comprehensive_theme("test-theme") @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') + url = reverse('embargo_blocked_message', kwargs={ + 'access_point': access_point, + 'message_key': "embargo" + }) + response = self.client.get(url) + self.assertContains( + response, + "This is a test template to test embargo message override for theming." + ) def _load_page(self, access_point, message_key, expected_status=200): """Load the message page and check the status code. """ diff --git a/common/djangoapps/embargo/views.py b/common/djangoapps/embargo/views.py index 5ac2fb9966..b97f21a860 100644 --- a/common/djangoapps/embargo/views.py +++ b/common/djangoapps/embargo/views.py @@ -56,16 +56,11 @@ 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. - elif access_point == self.ENROLLMENT_ACCESS_POINT: + if access_point == self.ENROLLMENT_ACCESS_POINT: message_dict = messages.ENROLL_MESSAGES elif access_point == self.COURSEWARE_ACCESS_POINT: message_dict = messages.COURSEWARE_MESSAGES diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 495d5ffa12..91dbc150d8 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -13,7 +13,6 @@ from openedx.core.djangoapps.site_configuration.helpers import ( from openedx.core.djangoapps.theming.helpers import ( get_template_path, - get_themed_template_path, is_request_in_themed_site, ) from certificates.api import get_asset_url_by_slug @@ -156,10 +155,6 @@ else: return get_template_path(relative_path, **kwargs) %> -<%def name="get_themed_template_path(relative_path, default_path, **kwargs)"><% - return get_themed_template_path(relative_path, default_path, **kwargs) -%> - <%def name="is_request_in_themed_site()"><% return is_request_in_themed_site() %> diff --git a/common/test/test-theme/lms/templates/static_templates/embargo.html b/common/test/test-theme/lms/templates/static_templates/embargo.html new file mode 100644 index 0000000000..648d2b0729 --- /dev/null +++ b/common/test/test-theme/lms/templates/static_templates/embargo.html @@ -0,0 +1,23 @@ +<%page expression_filter="h"/> +<%! +from django.utils.translation import ugettext as _ +from openedx.core.djangolib.markup import HTML, Text +%> +<%inherit file="../main.html" /> + +<%block name="pagetitle">${_("This Course Unavailable In Your Country")} + + +
+
+

+ ${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, at this time {platform_name} must comply with " + "export controls, and we cannot allow you to access this course." + )).format( + platform_name=Text(settings.PLATFORM_NAME), + )} +

+
+
diff --git a/lms/djangoapps/courseware/tests/test_favicon.py b/lms/djangoapps/courseware/tests/test_favicon.py index 6e57e73d2f..ecf3f0b70d 100644 --- a/lms/djangoapps/courseware/tests/test_favicon.py +++ b/lms/djangoapps/courseware/tests/test_favicon.py @@ -38,18 +38,3 @@ class FaviconTestCase(UrlResetMixin, TestCase): "/static/images/foo.ico", status_code=301, target_status_code=404 # @@@ how to avoid 404? ) - - @patch.dict("django.conf.settings.FEATURES", {"USE_CUSTOM_THEME": True}) - @override_settings(FAVICON_PATH="images/bar_fav.ico") - @override_settings(THEME_NAME="bar") - def test_favicon_redirect_with_theme(self): - self.assertEqual(settings.FEATURES["USE_CUSTOM_THEME"], True) - self.reset_urls() - - resp = self.client.get("/favicon.ico") - self.assertEqual(resp.status_code, 301) - self.assertRedirects( - resp, - "/static/images/bar_fav.ico", - status_code=301, target_status_code=404 # @@@ how to avoid 404? - ) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 986bbb0791..c1a9e8cc7e 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -267,9 +267,6 @@ BULK_EMAIL_ROUTING_KEY = HIGH_PRIORITY_QUEUE # we have to reset the value here. BULK_EMAIL_ROUTING_KEY_SMALL_JOBS = LOW_PRIORITY_QUEUE -# Theme overrides -THEME_NAME = ENV_TOKENS.get('THEME_NAME', None) - # following setting is for backward compatibility if ENV_TOKENS.get('COMPREHENSIVE_THEME_DIR', None): COMPREHENSIVE_THEME_DIR = ENV_TOKENS.get('COMPREHENSIVE_THEME_DIR') diff --git a/lms/envs/bok_choy.env.json b/lms/envs/bok_choy.env.json index 1454089e1b..fe65d3faa2 100644 --- a/lms/envs/bok_choy.env.json +++ b/lms/envs/bok_choy.env.json @@ -138,7 +138,6 @@ "SUPPORT_SITE_LINK": "https://support.example.com", "SYSLOG_SERVER": "", "TECH_SUPPORT_EMAIL": "technical@example.com", - "THEME_NAME": "", "THIRD_PARTY_AUTH_BACKENDS": [ "social.backends.google.GoogleOAuth2", "social.backends.linkedin.LinkedinOAuth2", diff --git a/lms/envs/common.py b/lms/envs/common.py index bdef305949..a09e1b89e1 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -153,9 +153,6 @@ FEATURES = { # Enable URL that shows information about the status of variuous services 'ENABLE_SERVICE_STATUS': False, - # Toggle to indicate use of the Stanford theming system - 'USE_CUSTOM_THEME': False, - # Don't autoplay videos for students 'AUTOPLAY_VIDEOS': False, diff --git a/lms/startup.py b/lms/startup.py index a88b786c9d..914e7d9000 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -58,9 +58,6 @@ def run(): # Mako requires the directories to be added after the django setup. microsite.enable_microsites(log) - if settings.FEATURES.get('USE_CUSTOM_THEME', False): - enable_stanford_theme() - # Initialize Segment analytics module by setting the write_key. if settings.LMS_SEGMENT_KEY: analytics.write_key = settings.LMS_SEGMENT_KEY @@ -100,40 +97,6 @@ def add_mimetypes(): mimetypes.add_type('application/font-woff', '.woff') -def enable_stanford_theme(): - """ - Enable the settings for a custom theme, whose files should be stored - in ENV_ROOT/themes/THEME_NAME (e.g., edx_all/themes/stanford). - """ - # Workaround for setting THEME_NAME to an empty - # string which is the default due to this ansible - # bug: https://github.com/ansible/ansible/issues/4812 - if getattr(settings, "THEME_NAME", "") == "": - settings.THEME_NAME = None - return - - assert settings.FEATURES['USE_CUSTOM_THEME'] - settings.FAVICON_PATH = 'themes/{name}/images/favicon.ico'.format( - name=settings.THEME_NAME - ) - - # Calculate the location of the theme's files - theme_root = settings.ENV_ROOT / "themes" / settings.THEME_NAME - - # Include the theme's templates in the template search paths - settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].insert(0, theme_root / 'templates') - edxmako.paths.add_lookup('main', theme_root / 'templates', prepend=True) - - # Namespace the theme's static files to 'themes/' to - # avoid collisions with default edX static files - settings.STATICFILES_DIRS.append( - (u'themes/{}'.format(settings.THEME_NAME), theme_root / 'static') - ) - - # Include theme locale path for django translations lookup - settings.LOCALE_PATHS = (theme_root / 'conf/locale',) + settings.LOCALE_PATHS - - def enable_microsites(): """ Calls the enable_microsites function in the microsite backend. diff --git a/lms/static/sass/lms-course-rtl.scss b/lms/static/sass/lms-course-rtl.scss index 47c0dcda71..654565bd98 100644 --- a/lms/static/sass/lms-course-rtl.scss +++ b/lms/static/sass/lms-course-rtl.scss @@ -6,8 +6,4 @@ @import 'base/font_face'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - @import 'build-course'; // shared app style assets/rendering diff --git a/lms/static/sass/lms-course.scss b/lms/static/sass/lms-course.scss index 53ecb202e2..8ebd978a8e 100644 --- a/lms/static/sass/lms-course.scss +++ b/lms/static/sass/lms-course.scss @@ -6,8 +6,4 @@ @import 'base/font_face'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - @import 'build-course'; // shared app style assets/rendering diff --git a/lms/static/sass/lms-footer-rtl.scss b/lms/static/sass/lms-footer-rtl.scss index 218aa1f964..ad15a1c9aa 100644 --- a/lms/static/sass/lms-footer-rtl.scss +++ b/lms/static/sass/lms-footer-rtl.scss @@ -9,10 +9,6 @@ @import 'base/variables'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - footer#footer-openedx { @import 'base/reset'; @import 'base/extends'; diff --git a/lms/static/sass/lms-footer.scss b/lms/static/sass/lms-footer.scss index ba292cc8e9..9173c23b7e 100644 --- a/lms/static/sass/lms-footer.scss +++ b/lms/static/sass/lms-footer.scss @@ -9,10 +9,6 @@ @import 'base/variables'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - footer#footer-openedx { @import 'base/reset'; @import 'base/extends'; diff --git a/lms/static/sass/lms-main-v1-rtl.scss b/lms/static/sass/lms-main-v1-rtl.scss index 0988836b42..aa560e25a4 100644 --- a/lms/static/sass/lms-main-v1-rtl.scss +++ b/lms/static/sass/lms-main-v1-rtl.scss @@ -15,8 +15,4 @@ @import 'base/variables'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - @import 'build-lms-v1'; // shared app style assets/rendering diff --git a/lms/static/sass/lms-main-v1.scss b/lms/static/sass/lms-main-v1.scss index ca36fb3acb..6f629fa414 100644 --- a/lms/static/sass/lms-main-v1.scss +++ b/lms/static/sass/lms-main-v1.scss @@ -14,8 +14,4 @@ @import 'base/variables'; @import 'base/mixins'; -// This comment is used by preprocess_assets.py to include resources from a -// theme, for old-style deprecated theming. -// - @import 'build-lms-v1'; // shared app style assets/rendering diff --git a/lms/static/themed_sass/README.rst b/lms/static/themed_sass/README.rst deleted file mode 100644 index 1f2696c41e..0000000000 --- a/lms/static/themed_sass/README.rst +++ /dev/null @@ -1,2 +0,0 @@ -When USE_CUSTOM_THEME is true, .scss files are pre-processed to add imports of -the theme settings. This directory will hold the output of the pre-processing. diff --git a/lms/templates/header.html b/lms/templates/header.html index 5b07e9f1c7..9647c3def8 100644 --- a/lms/templates/header.html +++ b/lms/templates/header.html @@ -1,4 +1,4 @@ ## mako <%page expression_filter="h" args="online_help_token"/> <%namespace name='static' file='static_content.html'/> -<%include file="${static.get_themed_template_path(relative_path='theme-header.html', default_path='navigation.html')}" args="online_help_token=online_help_token" /> +<%include file="${static.get_template_path(relative_path='navigation.html')}" args="online_help_token=online_help_token" /> diff --git a/lms/templates/main.html b/lms/templates/main.html index 61848b87f2..41369b42d1 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -141,7 +141,7 @@ from pipeline_mako import render_require_js_path_overrides % if not disable_footer: - <%include file="themable-footer.html" /> + <%include file="${static.get_template_path('footer.html')}" /> % endif % if not disable_window_wrap: diff --git a/lms/templates/themable-footer.html b/lms/templates/themable-footer.html deleted file mode 100644 index 2db3d82f26..0000000000 --- a/lms/templates/themable-footer.html +++ /dev/null @@ -1,11 +0,0 @@ -## mako -<%page expression_filter="h"/> -<%namespace name='static' file='static_content.html'/> - -## This file only exists as an additional layer of indirection to preserve -## backwards compatibility with Stanford theming -## (as much as possible). If you are writing your own theme using the -## "comprehensive theming" system, do NOT override this file. You should -## override "footer.html" instead. - -<%include file="${static.get_themed_template_path(relative_path='theme-footer.html', default_path='footer.html')}" /> diff --git a/lms/urls.py b/lms/urls.py index c4558f69c6..6077e169d8 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -176,33 +176,31 @@ urlpatterns += (url( RedirectView.as_view(url=settings.STATIC_URL + favicon_path, permanent=True) ),) -# Semi-static views only used by edX, not by themes -if not settings.FEATURES["USE_CUSTOM_THEME"]: - urlpatterns += ( - url(r'^blog$', 'static_template_view.views.render', - {'template': 'blog.html'}, name="blog"), - url(r'^contact$', 'static_template_view.views.render', - {'template': 'contact.html'}, name="contact"), - url(r'^donate$', 'static_template_view.views.render', - {'template': 'donate.html'}, name="donate"), - url(r'^faq$', 'static_template_view.views.render', - {'template': 'faq.html'}, name="faq"), - url(r'^help$', 'static_template_view.views.render', - {'template': 'help.html'}, name="help_edx"), - url(r'^jobs$', 'static_template_view.views.render', - {'template': 'jobs.html'}, name="jobs"), - url(r'^news$', 'static_template_view.views.render', - {'template': 'news.html'}, name="news"), - url(r'^press$', 'static_template_view.views.render', - {'template': 'press.html'}, name="press"), - url(r'^media-kit$', 'static_template_view.views.render', - {'template': 'media-kit.html'}, name="media-kit"), - url(r'^copyright$', 'static_template_view.views.render', - {'template': 'copyright.html'}, name="copyright"), +urlpatterns += ( + url(r'^blog$', 'static_template_view.views.render', + {'template': 'blog.html'}, name="blog"), + url(r'^contact$', 'static_template_view.views.render', + {'template': 'contact.html'}, name="contact"), + url(r'^donate$', 'static_template_view.views.render', + {'template': 'donate.html'}, name="donate"), + url(r'^faq$', 'static_template_view.views.render', + {'template': 'faq.html'}, name="faq"), + url(r'^help$', 'static_template_view.views.render', + {'template': 'help.html'}, name="help_edx"), + url(r'^jobs$', 'static_template_view.views.render', + {'template': 'jobs.html'}, name="jobs"), + url(r'^news$', 'static_template_view.views.render', + {'template': 'news.html'}, name="news"), + url(r'^press$', 'static_template_view.views.render', + {'template': 'press.html'}, name="press"), + url(r'^media-kit$', 'static_template_view.views.render', + {'template': 'media-kit.html'}, name="media-kit"), + url(r'^copyright$', 'static_template_view.views.render', + {'template': 'copyright.html'}, name="copyright"), - # Press releases - url(r'^press/([_a-zA-Z0-9-]+)$', 'static_template_view.views.render_press_release', name='press_release'), - ) + # Press releases + url(r'^press/([_a-zA-Z0-9-]+)$', 'static_template_view.views.render_press_release', name='press_release'), +) # Only enable URLs for those marketing links actually enabled in the # settings. Disable URLs by marking them as None. @@ -222,11 +220,6 @@ for key, value in settings.MKTG_URL_LINK_MAP.items(): # no file extension was specified in the key template = "%s.%s" % (template, settings.STATIC_TEMPLATE_VIEW_DEFAULT_FILE_EXTENSION) - # To allow theme templates to inherit from default templates, - # prepend a standard prefix - if settings.FEATURES["USE_CUSTOM_THEME"]: - template = "theme-" + template - # Make the assumption that the URL we want is the lowercased # version of the map key urlpatterns += (url(r'^%s$' % key.lower(), diff --git a/openedx/core/djangoapps/theming/helpers.py b/openedx/core/djangoapps/theming/helpers.py index de3d90fa5c..cb119f1266 100644 --- a/openedx/core/djangoapps/theming/helpers.py +++ b/openedx/core/djangoapps/theming/helpers.py @@ -41,26 +41,6 @@ def get_template(uri): return microsite.get_template(uri) -def get_themed_template_path(relative_path, default_path, **kwargs): - """ - This is a proxy function to hide microsite_configuration behind comprehensive theming. - - The workflow considers the "Stanford theming" feature alongside of microsites. It returns - the path of the themed template (i.e. relative_path) if Stanford theming is enabled AND - microsite theming is disabled, otherwise it will return the path of either the microsite - override template or the base lms template. - - :param relative_path: relative path of themed template - :param default_path: relative path of the microsite's or lms template to use if - theming is disabled or microsite is enabled - """ - is_stanford_theming_enabled = settings.FEATURES.get("USE_CUSTOM_THEME", False) - is_microsite = microsite.is_request_in_microsite() - if is_stanford_theming_enabled and not is_microsite: - return relative_path - return microsite.get_template_path(default_path, **kwargs) - - def get_template_path_with_theme(relative_path): """ Returns template path in current site's theme if it finds one there otherwise returns same path. diff --git a/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py b/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py index cab289ba80..8f4e912303 100644 --- a/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py +++ b/openedx/core/djangoapps/theming/tests/test_theme_style_overrides.py @@ -137,3 +137,57 @@ class TestComprehensiveThemeDisabledCMS(TestCase): resp = self.client.get('/signin') self.assertEqual(resp.status_code, 200) self.assertNotContains(resp, "Login Page override for test-theme.") + + +@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') +class TestStanfordTheme(TestCase): + """ + Test html, sass and static file overrides for stanford theme. + These tests are added to ensure expected behavior after USE_CUSTOM_THEME is removed and + a new theme 'stanford-style' is added instead. + """ + + def setUp(self): + """ + Clear static file finders cache and register cleanup methods. + """ + super(TestStanfordTheme, self).setUp() + + # Clear the internal staticfiles caches, to get test isolation. + staticfiles.finders.get_finder.cache_clear() + + @with_comprehensive_theme("stanford-style") + def test_footer(self): + """ + Test stanford theme footer. + """ + resp = self.client.get('/') + self.assertEqual(resp.status_code, 200) + # This string comes from header.html of test-theme + self.assertContains(resp, "footer overrides for stanford theme go here") + + @with_comprehensive_theme("stanford-style") + def test_logo_image(self): + """ + Test custom logo. + """ + result = staticfiles.finders.find('stanford-style/images/logo.png') + self.assertEqual(result, settings.REPO_ROOT / 'themes/stanford-style/lms/static/images/logo.png') + + @with_comprehensive_theme("stanford-style") + def test_favicon_image(self): + """ + Test correct favicon for custom theme. + """ + result = staticfiles.finders.find('stanford-style/images/favicon.ico') + self.assertEqual(result, settings.REPO_ROOT / 'themes/stanford-style/lms/static/images/favicon.ico') + + @with_comprehensive_theme("stanford-style") + def test_index_page(self): + """ + Test custom theme overrides for index page. + """ + resp = self.client.get('/') + self.assertEqual(resp.status_code, 200) + # This string comes from header.html of test-theme + self.assertContains(resp, "Free courses from Stanford") diff --git a/pavelib/assets.py b/pavelib/assets.py index c1320eb698..3bb5d81454 100644 --- a/pavelib/assets.py +++ b/pavelib/assets.py @@ -585,23 +585,6 @@ def _compile_sass(system, theme, debug, force, timing_info): return True -def compile_templated_sass(systems, settings): - """ - Render Mako templates for Sass files. - `systems` is a list of systems (e.g. 'lms' or 'studio' or both) - `settings` is the Django settings module to use. - """ - for system in systems: - if system == "studio": - system = "cms" - sh(django_cmd( - system, settings, 'preprocess_assets', - '{system}/static/sass/*.scss'.format(system=system), - '{system}/static/themed_sass'.format(system=system) - )) - print("\t\tFinished preprocessing {} assets.".format(system)) - - def process_npm_assets(): """ Process vendor libraries installed via NPM. @@ -766,7 +749,6 @@ def update_assets(args): ) args = parser.parse_args(args) - compile_templated_sass(args.system, args.settings) process_xmodule_assets() process_npm_assets() compile_coffeescript() diff --git a/pavelib/paver_tests/test_servers.py b/pavelib/paver_tests/test_servers.py index 364c01c119..e2c7f9cbd5 100644 --- a/pavelib/paver_tests/test_servers.py +++ b/pavelib/paver_tests/test_servers.py @@ -28,10 +28,6 @@ EXPECTED_LMS_SASS_COMMAND = [ EXPECTED_CMS_SASS_COMMAND = [ u"python manage.py cms --settings={asset_settings} compile_sass cms ", ] -EXPECTED_PREPROCESS_ASSETS_COMMAND = ( - u"python manage.py {system} --settings={asset_settings} preprocess_assets" - u" {system}/static/sass/*.scss {system}/static/themed_sass" -) EXPECTED_COLLECT_STATIC_COMMAND = ( u"python manage.py {system} --settings={asset_settings} collectstatic --noinput > /dev/null" ) @@ -233,9 +229,6 @@ class TestPaverServerTasks(PaverTestCase): expected_asset_settings = "test_static_optimized" expected_collect_static = not is_fast and expected_settings != "devstack" if not is_fast: - expected_messages.append(EXPECTED_PREPROCESS_ASSETS_COMMAND.format( - system=system, asset_settings=expected_asset_settings - )) expected_messages.append(u"xmodule_assets common/static/xmodule") expected_messages.append(u"install npm_assets") expected_messages.append(EXPECTED_COFFEE_COMMAND.format(platform_root=self.platform_root)) @@ -272,12 +265,6 @@ class TestPaverServerTasks(PaverTestCase): expected_collect_static = not is_fast and expected_settings != "devstack" expected_messages = [] if not is_fast: - expected_messages.append(EXPECTED_PREPROCESS_ASSETS_COMMAND.format( - system="lms", asset_settings=expected_asset_settings - )) - expected_messages.append(EXPECTED_PREPROCESS_ASSETS_COMMAND.format( - system="cms", asset_settings=expected_asset_settings - )) expected_messages.append(u"xmodule_assets common/static/xmodule") expected_messages.append(u"install npm_assets") expected_messages.append(EXPECTED_COFFEE_COMMAND.format(platform_root=self.platform_root)) diff --git a/themes/README.rst b/themes/README.rst index c87d8fc0c5..a2b98a6bb9 100644 --- a/themes/README.rst +++ b/themes/README.rst @@ -99,20 +99,6 @@ theme (so far): * ``header.html`` * ``footer.html`` -You should **not** use the following names in your comprehensive theme: - -* ``themable-footer.html`` - -If you look at the ``main.html`` template file, you will notice that it includes -``header.html`` and ``themable-footer.html``, rather than ``footer.html``. -You might be inclined to override ``themable-footer.html`` as a result. DO NOT -DO THIS. ``themable-footer.html`` is an additional layer of indirection that -is necessary to avoid breaking microsites, which also refers to a file named -``footer.html``. The goal is to eventually make comprehensive theming do -everything that microsites does now, and then deprecate and remove microsites -from the codebase. At that point, the ``themable-footer.html`` file will go -away, since the additional layer of indirection will no longer be necessary. - Installing your theme --------------------- diff --git a/themes/stanford-style/lms/templates/embargo/default_courseware.html b/themes/stanford-style/lms/templates/embargo/default_courseware.html new file mode 100644 index 0000000000..cdd199f234 --- /dev/null +++ b/themes/stanford-style/lms/templates/embargo/default_courseware.html @@ -0,0 +1,11 @@ +<%! from django.utils.translation import ugettext as _ %> +<%inherit file="../main.html" /> + +<%block name="pagetitle">${_("This Course Unavailable In Your Country")} + +
+

+ +

+
diff --git a/themes/stanford-style/lms/templates/embargo/default_enrollment.html b/themes/stanford-style/lms/templates/embargo/default_enrollment.html new file mode 100644 index 0000000000..cdd199f234 --- /dev/null +++ b/themes/stanford-style/lms/templates/embargo/default_enrollment.html @@ -0,0 +1,11 @@ +<%! from django.utils.translation import ugettext as _ %> +<%inherit file="../main.html" /> + +<%block name="pagetitle">${_("This Course Unavailable In Your Country")} + +
+

+ +

+
diff --git a/themes/stanford-style/lms/templates/footer.html b/themes/stanford-style/lms/templates/footer.html index 645fc80e11..b4afdcd4c6 100644 --- a/themes/stanford-style/lms/templates/footer.html +++ b/themes/stanford-style/lms/templates/footer.html @@ -6,7 +6,7 @@ <%! from datetime import date %> - +