Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cms/envs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
"MICROSITE_DATABASE_TEMPLATE_CACHE_TTL", MICROSITE_DATABASE_TEMPLATE_CACHE_TTL
)

FOOTER_CACHE_TIMEOUT = ENV_TOKENS.get('FOOTER_CACHE_TIMEOUT', FOOTER_CACHE_TIMEOUT)
############################ OAUTH2 Provider ###################################

# OpenID Connect issuer ID. Normally the URL of the authentication endpoint.
Expand Down
4 changes: 2 additions & 2 deletions cms/envs/bok_choy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
)
STATICFILES_DIRS = (
STATICFILES_DIRS = [
(TEST_ROOT / "staticfiles" / "cms").abspath(),
)
]

# Silence noisy logs
import logging
Expand Down
6 changes: 5 additions & 1 deletion cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@


# Site info
SITE_ID = 1
SITE_NAME = "localhost:8001"
HTTPS = 'on'
ROOT_URLCONF = 'cms.urls'
Expand Down Expand Up @@ -513,6 +512,7 @@
# List of finder classes that know how to find static files in various locations.
# Note: the pipeline finder is included to be able to discover optimized files
STATICFILES_FINDERS = [
'openedx.core.djangoapps.theming.finders.ComprehensiveThemeFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
Expand Down Expand Up @@ -1128,6 +1128,10 @@
# TTL for microsite database template cache
MICROSITE_DATABASE_TEMPLATE_CACHE_TTL = 5 * 60

# Cache expiration for the version of the footer served
# by the branding API.
FOOTER_CACHE_TIMEOUT = 30 * 60

############################### PROCTORING CONFIGURATION DEFAULTS ##############
PROCTORING_BACKEND_PROVIDER = {
'class': 'edx_proctoring.backends.null.NullBackendProvider',
Expand Down
1 change: 1 addition & 0 deletions cms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

# Revert to the default set of finders as we don't want the production pipeline
STATICFILES_FINDERS = [
'openedx.core.djangoapps.theming.finders.ComprehensiveThemeFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
Expand Down
4 changes: 2 additions & 2 deletions cms/envs/devstack_optimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
)
STATICFILES_DIRS = (
STATICFILES_DIRS = [
(TEST_ROOT / "staticfiles" / "cms").abspath(),
)
]
3 changes: 3 additions & 0 deletions cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from lms.envs.test import (
WIKI_ENABLED,
PLATFORM_NAME,
SITE_ID,
SITE_NAME,
DEFAULT_FILE_STORAGE,
MEDIA_ROOT,
Expand Down Expand Up @@ -281,6 +282,8 @@
MICROSITE_TEST_HOSTNAME = 'testmicrosite.testserver'
MICROSITE_LOGISTRATION_HOSTNAME = 'logistration.testserver'

TEST_THEME = COMMON_ROOT / "test" / "test-theme"

# For consistency in user-experience, keep the value of this setting in sync with
# the one in lms/envs/test.py
FEATURES['ENABLE_DISCUSSION_SERVICE'] = False
Expand Down
4 changes: 2 additions & 2 deletions cms/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import xmodule.x_module
import cms.lib.xblock.runtime

from openedx.core.djangoapps.theming.core import enable_comprehensive_theme
from openedx.core.djangoapps.theming.core import enable_comprehensive_theming


def run():
Expand All @@ -30,7 +30,7 @@ def run():
# Comprehensive theming needs to be set up before django startup,
# because modifying django template paths after startup has no effect.
if settings.COMPREHENSIVE_THEME_DIR:
enable_comprehensive_theme(settings.COMPREHENSIVE_THEME_DIR)
enable_comprehensive_theming(settings.COMPREHENSIVE_THEME_DIR)

django.setup()

Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/course_modes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from student.models import CourseEnrollment
import lms.djangoapps.commerce.tests.test_utils as ecomm_test_utils
from course_modes.models import CourseMode, Mode
from openedx.core.djangoapps.theming.test_util import with_is_edx_domain
from openedx.core.djangoapps.theming.test_util import with_comprehensive_theme


@ddt.ddt
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_multiple_mode_creation(self):
self.assertEquals(course_modes, expected_modes)

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@with_is_edx_domain(True)
@with_comprehensive_theme("edx.org")
def test_hide_nav(self):
# Create the course modes
for mode in ["honor", "verified"]:
Expand Down
31 changes: 23 additions & 8 deletions common/djangoapps/edxmako/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@

from django.conf import settings
from mako.lookup import TemplateLookup
from mako.exceptions import TopLevelLookupException

from microsite_configuration import microsite
from . import LOOKUP
from openedx.core.djangoapps.theming.helpers import (
get_template as themed_template,
get_template_path_with_theme,
strip_site_theme_templates_path,
)


class DynamicTemplateLookup(TemplateLookup):
Expand Down Expand Up @@ -49,15 +54,25 @@ def add_directory(self, directory, prepend=False):

def get_template(self, uri):
"""
Overridden method which will hand-off the template lookup to the microsite subsystem
Overridden method for locating a template in either the database or the site theme.

If not found, template lookup will be done in comprehensive theme for current site
by prefixing path to theme.
e.g if uri is `main.html` then new uri would be something like this `/red-theme/lms/static/main.html`

If still unable to find a template, it will fallback to the default template directories after stripping off
the prefix path to theme.
"""
microsite_template = microsite.get_template(uri)
template = themed_template(uri)

return (
microsite_template
if microsite_template
else super(DynamicTemplateLookup, self).get_template(uri)
)
if not template:
try:
template = super(DynamicTemplateLookup, self).get_template(get_template_path_with_theme(uri))
except TopLevelLookupException:
# strip off the prefix path to theme and look in default template dirs
template = super(DynamicTemplateLookup, self).get_template(strip_site_theme_templates_path(uri))

return template


def clear_lookups(namespace):
Expand Down
13 changes: 7 additions & 6 deletions common/djangoapps/edxmako/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from django.template import Context
from django.http import HttpResponse
import logging

from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.template import Context

from microsite_configuration import microsite

from edxmako import lookup_template
from edxmako.middleware import get_template_request_context
from django.conf import settings
from django.core.urlresolvers import reverse
from openedx.core.djangoapps.theming.helpers import get_template_path
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -113,8 +115,7 @@ def microsite_footer_context_processor(request):

def render_to_string(template_name, dictionary, context=None, namespace='main'):

# see if there is an override template defined in the microsite
template_name = microsite.get_template_path(template_name)
template_name = get_template_path(template_name)

context_instance = Context(dictionary)
# add dictionary to context_instance
Expand Down
4 changes: 1 addition & 3 deletions common/djangoapps/microsite_configuration/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from __future__ import absolute_import

import abc
import edxmako
import os.path
import threading

Expand Down Expand Up @@ -272,9 +271,7 @@ def enable_microsites(self, log):
Configure the paths for the microsites feature
"""
microsites_root = settings.MICROSITE_ROOT_DIR

if os.path.isdir(microsites_root):
edxmako.paths.add_lookup('main', microsites_root)
settings.STATICFILES_DIRS.insert(0, microsites_root)

log.info('Loading microsite path at %s', microsites_root)
Expand All @@ -292,6 +289,7 @@ def enable_microsites_pre_startup(self, log):
microsites_root = settings.MICROSITE_ROOT_DIR

if self.has_configuration_set():
settings.MAKO_TEMPLATES['main'].insert(0, microsites_root)
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].append(microsites_root)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ def test_clear(self):
microsite.clear()
self.assertIsNone(microsite.get_value('platform_name'))

def test_enable_microsites_pre_startup(self):
"""
Tests microsite.test_enable_microsites_pre_startup works as expected.
"""
# remove microsite root directory paths first
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] = [
path for path in settings.DEFAULT_TEMPLATE_ENGINE['DIRS']
if path != settings.MICROSITE_ROOT_DIR
]
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': False}):
microsite.enable_microsites_pre_startup(log)
self.assertNotIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': True}):
microsite.enable_microsites_pre_startup(log)
self.assertIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
self.assertIn(settings.MICROSITE_ROOT_DIR, settings.MAKO_TEMPLATES['main'])

@patch('edxmako.paths.add_lookup')
def test_enable_microsites(self, add_lookup):
"""
Expand All @@ -122,7 +139,6 @@ def test_enable_microsites(self, add_lookup):
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': True}):
microsite.enable_microsites(log)
self.assertIn(settings.MICROSITE_ROOT_DIR, settings.STATICFILES_DIRS)
add_lookup.assert_called_once_with('main', settings.MICROSITE_ROOT_DIR)

def test_get_all_configs(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from django.utils.translation import get_language_bidi
from mako.exceptions import TemplateLookupException

from openedx.core.djangoapps.theming.helpers import get_page_title_breadcrumbs, get_value, get_template_path, get_themed_template_path, is_request_in_themed_site
from openedx.core.djangoapps.theming.helpers import (
get_page_title_breadcrumbs,
get_value,
get_template_path,
get_themed_template_path,
is_request_in_themed_site,
)
from certificates.api import get_asset_url_by_slug
from lang_pref.api import released_languages
%>
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/student/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from edxmako.tests import mako_middleware_process_request
from util.request import safe_get_host
from util.testing import EventTestMixin
from openedx.core.djangoapps.theming.test_util import with_is_edx_domain
from openedx.core.djangoapps.theming.test_util import with_comprehensive_theme


class TestException(Exception):
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_activation_email(self):
self._create_account()
self._assert_activation_email(self.ACTIVATION_SUBJECT, self.OPENEDX_FRAGMENTS)

@with_is_edx_domain(True)
@with_comprehensive_theme("edx.org")
def test_activation_email_edx_domain(self):
self._create_account()
self._assert_activation_email(self.ACTIVATION_SUBJECT, self.EDX_DOMAIN_FRAGMENTS)
Expand Down
2 changes: 0 additions & 2 deletions common/djangoapps/student/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification
import shoppingcart # pylint: disable=import-error
from openedx.core.djangoapps.programs.tests.mixins import ProgramsApiConfigMixin
from openedx.core.djangoapps.theming.test_util import with_is_edx_domain

# Explicitly import the cache from ConfigurationModel so we can reset it after each test
from config_models.models import cache
Expand Down Expand Up @@ -492,7 +491,6 @@ def test_dashboard_metadata_caching(self, modulestore_type):
self.assertEquals(response_2.status_code, 200)

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@with_is_edx_domain(True)
def test_dashboard_header_nav_has_find_courses(self):
self.client.login(username="jack", password="test")
response = self.client.get(reverse("dashboard"))
Expand Down
20 changes: 20 additions & 0 deletions common/test/db_fixtures/sites.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"pk": 2,
"model": "sites.Site",

"fields": {
"domain": "localhost:8003",
"name": "lms"
}
},
{
"pk": 3,
"model": "sites.Site",

"fields": {
"domain": "localhost:8031",
"name": "cms"
}
}
]
1 change: 1 addition & 0 deletions common/test/test-theme/cms/static/css/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.css
Loading