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
93970f34
Commit
93970f34
authored
May 24, 2016
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow edxmako to be passed an explicit request to create the RequestContext from
parent
0e8af4cc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
14 deletions
+37
-14
cms/djangoapps/contentstore/views/error.py
+2
-2
common/djangoapps/edxmako/request_context.py
+8
-6
common/djangoapps/edxmako/shortcuts.py
+25
-4
lms/djangoapps/static_template_view/views.py
+2
-2
No files found.
cms/djangoapps/contentstore/views/error.py
View file @
93970f34
...
...
@@ -39,9 +39,9 @@ def server_error(request):
@jsonable_error
(
404
,
"Resource not found"
)
def
render_404
(
request
):
return
HttpResponseNotFound
(
render_to_string
(
'404.html'
,
{}))
return
HttpResponseNotFound
(
render_to_string
(
'404.html'
,
{}
,
request
=
request
))
@jsonable_error
(
500
,
"The Studio servers encountered an error"
)
def
render_500
(
request
):
return
HttpResponseServerError
(
render_to_string
(
'500.html'
,
{}))
return
HttpResponseServerError
(
render_to_string
(
'500.html'
,
{}
,
request
=
request
))
common/djangoapps/edxmako/request_context.py
View file @
93970f34
...
...
@@ -38,23 +38,25 @@ def get_template_context_processors():
return
tuple
(
import_string
(
path
)
for
path
in
context_processors
)
def
get_template_request_context
():
def
get_template_request_context
(
request
=
None
):
"""
Returns the template processing context to use for the current request,
or returns None if there is not a current request.
"""
if
request
is
None
:
request
=
get_current_request
()
if
request
is
None
:
return
None
request_cache_dict
=
request_cache
.
get_cache
(
'edxmako'
)
cache_key
=
"request_context"
if
cache_key
in
request_cache_dict
:
return
request_cache_dict
[
cache_key
]
request
=
get_current_request
()
if
request
is
None
:
return
None
context
=
RequestContext
(
request
)
context
[
'is_secure'
]
=
request
.
is_secure
()
context
[
'site'
]
=
safe_get_host
(
request
)
...
...
common/djangoapps/edxmako/shortcuts.py
View file @
93970f34
...
...
@@ -111,7 +111,28 @@ def microsite_footer_context_processor(request):
)
def
render_to_string
(
template_name
,
dictionary
,
context
=
None
,
namespace
=
'main'
):
def
render_to_string
(
template_name
,
dictionary
,
context
=
None
,
namespace
=
'main'
,
request
=
None
):
"""
Render a Mako template to as a string.
The following values are available to all templates:
settings: the django settings object
EDX_ROOT_URL: settings.EDX_ROOT_URL
marketing_link: The :func:`marketing_link` function
is_any_marketing_link_set: The :func:`is_any_marketing_link_set` function
is_marketing_link_set: The :func:`is_marketing_link_set` function
Arguments:
template_name: The name of the template to render. Will be loaded
from the template paths specified in configuration.
dictionary: A dictionary of variables to insert into the template during
rendering.
context: A :class:`~django.template.Context` with values to make
available to the template.
namespace: The Mako namespace to find the named template in.
request: The request to use to construct the RequestContext for rendering
this template. If not supplied, the current request will be used.
"""
# see if there is an override template defined in the microsite
template_name
=
microsite
.
get_template_path
(
template_name
)
...
...
@@ -128,7 +149,7 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_instance
[
'is_marketing_link_set'
]
=
is_marketing_link_set
# In various testing contexts, there might not be a current request context.
request_context
=
get_template_request_context
()
request_context
=
get_template_request_context
(
request
)
if
request_context
:
for
item
in
request_context
:
context_dictionary
.
update
(
item
)
...
...
@@ -148,11 +169,11 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
return
template
.
render_unicode
(
**
context_dictionary
)
def
render_to_response
(
template_name
,
dictionary
=
None
,
context_instance
=
None
,
namespace
=
'main'
,
**
kwargs
):
def
render_to_response
(
template_name
,
dictionary
=
None
,
context_instance
=
None
,
namespace
=
'main'
,
request
=
None
,
**
kwargs
):
"""
Returns a HttpResponse whose content is filled with the result of calling
lookup.get_template(args[0]).render with the passed arguments.
"""
dictionary
=
dictionary
or
{}
return
HttpResponse
(
render_to_string
(
template_name
,
dictionary
,
context_instance
,
namespace
),
**
kwargs
)
return
HttpResponse
(
render_to_string
(
template_name
,
dictionary
,
context_instance
,
namespace
,
request
),
**
kwargs
)
lms/djangoapps/static_template_view/views.py
View file @
93970f34
...
...
@@ -71,8 +71,8 @@ def render_press_release(request, slug):
def
render_404
(
request
):
return
HttpResponseNotFound
(
render_to_string
(
'static_templates/404.html'
,
{}))
return
HttpResponseNotFound
(
render_to_string
(
'static_templates/404.html'
,
{}
,
request
=
request
))
def
render_500
(
request
):
return
HttpResponseServerError
(
render_to_string
(
'static_templates/server-error.html'
,
{}))
return
HttpResponseServerError
(
render_to_string
(
'static_templates/server-error.html'
,
{}
,
request
=
request
))
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