Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3259df54
Commit
3259df54
authored
Jan 29, 2016
by
Matjaz Gregoric
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11315 from open-craft/comprehensive-theme-on-django-templates
Make comprehensive theme work with django templates.
parents
4f342dac
9b89bd32
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
26 deletions
+72
-26
cms/startup.py
+7
-0
lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py
+45
-0
lms/startup.py
+6
-0
openedx/core/djangoapps/theming/core.py
+7
-9
openedx/core/djangoapps/theming/startup.py
+0
-14
openedx/core/djangoapps/theming/test_util.py
+7
-3
No files found.
cms/startup.py
View file @
3259df54
...
@@ -14,6 +14,8 @@ from monkey_patch import third_party_auth
...
@@ -14,6 +14,8 @@ from monkey_patch import third_party_auth
import
xmodule.x_module
import
xmodule.x_module
import
cms.lib.xblock.runtime
import
cms.lib.xblock.runtime
from
openedx.core.djangoapps.theming.core
import
enable_comprehensive_theme
def
run
():
def
run
():
"""
"""
...
@@ -21,6 +23,11 @@ def run():
...
@@ -21,6 +23,11 @@ def run():
"""
"""
third_party_auth
.
patch
()
third_party_auth
.
patch
()
# 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
)
django
.
setup
()
django
.
setup
()
autostartup
()
autostartup
()
...
...
lms/djangoapps/course_wiki/tests/test_comprehensive_theming.py
0 → 100644
View file @
3259df54
"""
Tests for wiki middleware.
"""
from
django.conf
import
settings
from
django.test.client
import
Client
from
nose.plugins.attrib
import
attr
from
wiki.models
import
URLPath
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
openedx.core.djangoapps.theming.test_util
import
with_comprehensive_theme
from
courseware.tests.factories
import
InstructorFactory
from
course_wiki.views
import
get_or_create_root
@attr
(
'shard_1'
)
class
TestComprehensiveTheming
(
ModuleStoreTestCase
):
"""Tests for comprehensive theming of wiki pages."""
def
setUp
(
self
):
"""Test setup."""
super
(
TestComprehensiveTheming
,
self
)
.
setUp
()
self
.
wiki
=
get_or_create_root
()
self
.
course_math101
=
CourseFactory
.
create
(
org
=
'edx'
,
number
=
'math101'
,
display_name
=
'2014'
,
metadata
=
{
'use_unique_wiki_id'
:
'false'
})
self
.
course_math101_instructor
=
InstructorFactory
(
course_key
=
self
.
course_math101
.
id
,
username
=
'instructor'
,
password
=
'secret'
)
self
.
wiki_math101
=
URLPath
.
create_article
(
self
.
wiki
,
'math101'
,
title
=
'math101'
)
self
.
client
=
Client
()
self
.
client
.
login
(
username
=
'instructor'
,
password
=
'secret'
)
@with_comprehensive_theme
(
settings
.
REPO_ROOT
/
'themes/red-theme'
)
def
test_themed_footer
(
self
):
"""
Tests that theme footer is used rather than standard
footer when comprehensive theme is enabled.
"""
response
=
self
.
client
.
get
(
'/courses/edx/math101/2014/wiki/math101/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# This string comes from themes/red-theme/lms/templates/footer.html
self
.
assertContains
(
response
,
"super-ugly"
)
lms/startup.py
View file @
3259df54
...
@@ -18,6 +18,7 @@ from monkey_patch import third_party_auth
...
@@ -18,6 +18,7 @@ from monkey_patch import third_party_auth
import
xmodule.x_module
import
xmodule.x_module
import
lms_xblock.runtime
import
lms_xblock.runtime
from
openedx.core.djangoapps.theming.core
import
enable_comprehensive_theme
from
microsite_configuration
import
microsite
from
microsite_configuration
import
microsite
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -33,6 +34,11 @@ def run():
...
@@ -33,6 +34,11 @@ def run():
if
settings
.
FEATURES
.
get
(
'ENABLE_THIRD_PARTY_AUTH'
,
False
):
if
settings
.
FEATURES
.
get
(
'ENABLE_THIRD_PARTY_AUTH'
,
False
):
enable_third_party_auth
()
enable_third_party_auth
()
# 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
)
# We currently use 2 template rendering engines, mako and django_templates,
# We currently use 2 template rendering engines, mako and django_templates,
# and one of them (django templates), requires the directories be added
# and one of them (django templates), requires the directories be added
# before the django.setup().
# before the django.setup().
...
...
openedx/core/djangoapps/theming/core.py
View file @
3259df54
...
@@ -5,8 +5,6 @@ from path import Path
...
@@ -5,8 +5,6 @@ from path import Path
from
django.conf
import
settings
from
django.conf
import
settings
import
edxmako
def
comprehensive_theme_changes
(
theme_dir
):
def
comprehensive_theme_changes
(
theme_dir
):
"""
"""
...
@@ -20,14 +18,14 @@ def comprehensive_theme_changes(theme_dir):
...
@@ -20,14 +18,14 @@ def comprehensive_theme_changes(theme_dir):
* 'settings': a dictionary of settings names and their new values.
* 'settings': a dictionary of settings names and their new values.
* '
mako_paths': a list of directories to prepend to the edxmako
* '
template_paths': a list of directories to prepend to template
template
lookup path.
lookup path.
"""
"""
changes
=
{
changes
=
{
'settings'
:
{},
'settings'
:
{},
'
mako
_paths'
:
[],
'
template
_paths'
:
[],
}
}
root
=
Path
(
settings
.
PROJECT_ROOT
)
root
=
Path
(
settings
.
PROJECT_ROOT
)
if
root
.
name
==
""
:
if
root
.
name
==
""
:
...
@@ -37,8 +35,7 @@ def comprehensive_theme_changes(theme_dir):
...
@@ -37,8 +35,7 @@ def comprehensive_theme_changes(theme_dir):
templates_dir
=
component_dir
/
"templates"
templates_dir
=
component_dir
/
"templates"
if
templates_dir
.
isdir
():
if
templates_dir
.
isdir
():
changes
[
'settings'
][
'TEMPLATE_DIRS'
]
=
[
templates_dir
]
+
settings
.
DEFAULT_TEMPLATE_ENGINE
[
'DIRS'
]
changes
[
'template_paths'
]
.
append
(
templates_dir
)
changes
[
'mako_paths'
]
.
append
(
templates_dir
)
staticfiles_dir
=
component_dir
/
"static"
staticfiles_dir
=
component_dir
/
"static"
if
staticfiles_dir
.
isdir
():
if
staticfiles_dir
.
isdir
():
...
@@ -64,5 +61,6 @@ def enable_comprehensive_theme(theme_dir):
...
@@ -64,5 +61,6 @@ def enable_comprehensive_theme(theme_dir):
# Use the changes
# Use the changes
for
name
,
value
in
changes
[
'settings'
]
.
iteritems
():
for
name
,
value
in
changes
[
'settings'
]
.
iteritems
():
setattr
(
settings
,
name
,
value
)
setattr
(
settings
,
name
,
value
)
for
template_dir
in
changes
[
'mako_paths'
]:
for
template_dir
in
changes
[
'template_paths'
]:
edxmako
.
paths
.
add_lookup
(
'main'
,
template_dir
,
prepend
=
True
)
settings
.
DEFAULT_TEMPLATE_ENGINE
[
'DIRS'
]
.
insert
(
0
,
template_dir
)
settings
.
MAKO_TEMPLATES
[
'main'
]
.
insert
(
0
,
template_dir
)
openedx/core/djangoapps/theming/startup.py
deleted
100644 → 0
View file @
4f342dac
"""
Startup code for Comprehensive Theming
"""
from
path
import
Path
as
path
from
django.conf
import
settings
from
.core
import
enable_comprehensive_theme
def
run
():
"""Enable comprehensive theming, if we should."""
if
settings
.
COMPREHENSIVE_THEME_DIR
:
enable_comprehensive_theme
(
theme_dir
=
path
(
settings
.
COMPREHENSIVE_THEME_DIR
))
openedx/core/djangoapps/theming/test_util.py
View file @
3259df54
...
@@ -10,6 +10,7 @@ import contextlib
...
@@ -10,6 +10,7 @@ import contextlib
from
mock
import
patch
from
mock
import
patch
from
django.conf
import
settings
from
django.conf
import
settings
from
django.template
import
Engine
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
import
edxmako
import
edxmako
...
@@ -38,11 +39,14 @@ def with_comprehensive_theme(theme_dir):
...
@@ -38,11 +39,14 @@ def with_comprehensive_theme(theme_dir):
@wraps
(
func
)
@wraps
(
func
)
def
_decorated
(
*
args
,
**
kwargs
):
# pylint: disable=missing-docstring
def
_decorated
(
*
args
,
**
kwargs
):
# pylint: disable=missing-docstring
with
override_settings
(
COMPREHENSIVE_THEME_DIR
=
theme_dir
,
**
changes
[
'settings'
]):
with
override_settings
(
COMPREHENSIVE_THEME_DIR
=
theme_dir
,
**
changes
[
'settings'
]):
default_engine
=
Engine
.
get_default
()
dirs
=
default_engine
.
dirs
[:]
with
edxmako
.
save_lookups
():
with
edxmako
.
save_lookups
():
for
template_dir
in
changes
[
'
mako
_paths'
]:
for
template_dir
in
changes
[
'
template
_paths'
]:
edxmako
.
paths
.
add_lookup
(
'main'
,
template_dir
,
prepend
=
True
)
edxmako
.
paths
.
add_lookup
(
'main'
,
template_dir
,
prepend
=
True
)
dirs
.
insert
(
0
,
template_dir
)
return
func
(
*
args
,
**
kwargs
)
with
patch
.
object
(
default_engine
,
'dirs'
,
dirs
):
return
func
(
*
args
,
**
kwargs
)
return
_decorated
return
_decorated
return
_decorator
return
_decorator
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment