Remove all usages of USE_CUSTOM_THEME and THEME_NAME from python files

This commit is contained in:
Saleem Latif
2016-06-14 13:31:45 +05:00
parent 80644e0d18
commit 6277bd27e6
35 changed files with 155 additions and 377 deletions

View File

@@ -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(
"//<THEME-OVERRIDE>",
"@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)

View File

@@ -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'
)
}

View File

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

View File

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

View File

@@ -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>
<%def name="get_themed_template_path(relative_path, default_path, **kwargs)"><%
return get_themed_template_path(relative_path, default_path, **kwargs)
%></%def>
<%def name="is_request_in_themed_site()"><%
return is_request_in_themed_site()
%></%def>