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
88282b5b
Commit
88282b5b
authored
Aug 14, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some comments for the mitxmako additions.
parent
33b381d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
10 deletions
+39
-10
common/lib/mitxmako/mitxmako/templatetag_helpers.py
+27
-9
lms/templates/main_django.html
+12
-1
No files found.
common/lib/mitxmako/mitxmako/templatetag_helpers.py
View file @
88282b5b
...
...
@@ -2,8 +2,34 @@ from django.template import loader
from
django.template.base
import
Template
,
Context
from
django.template.loader
import
get_template
,
select_template
def
django_template_include
(
file_name
,
mako_context
):
"""
This can be used within a mako template to include a django template
in the way that a django-style {
%
include
%
} does. Pass it context
which can be the mako context ('context') or a dictionary.
"""
dictionary
=
dict
(
mako_context
)
return
loader
.
render_to_string
(
file_name
,
dictionary
=
dictionary
)
def
render_inclusion
(
func
,
file_name
,
takes_context
,
django_context
,
*
args
,
**
kwargs
):
"""
This allows a mako template to call a template tag function (written
for django templates) that is an "inclusion tag". These functions are
decorated with @register.inclusion_tag.
-func: This is the function that is registered as an inclusion tag.
You must import it directly using a python import statement.
-file_name: This is the filename of the template, passed into the
@register.inclusion_tag statement.
-takes_context: This is a parameter of the @register.inclusion_tag.
-django_context: This is an instance of the django context. If this
is a mako template rendered through the regular django rendering calls,
a copy of the django context is available as 'django_context'.
-*args and **kwargs are the arguments to func.
"""
if
takes_context
:
args
=
[
django_context
]
+
list
(
args
)
...
...
@@ -22,14 +48,6 @@ def render_inclusion(func, file_name, takes_context, django_context, *args, **kw
if
csrf_token
is
not
None
:
new_context
[
'csrf_token'
]
=
csrf_token
# **{
# 'autoescape': context.autoescape,
# 'current_app': context.current_app,
# 'use_l10n': context.use_l10n,
# 'use_tz': context.use_tz,
# })
return
nodelist
.
render
(
new_context
)
def
django_template_include
(
file_name
,
mako_context
):
dictionary
=
dict
(
mako_context
)
return
loader
.
render_to_string
(
file_name
,
dictionary
=
dictionary
)
lms/templates/main_django.html
View file @
88282b5b
...
...
@@ -12,7 +12,6 @@
{% render_block "css" %}
{% render_block "js" %}
<meta
name=
"path_prefix"
content=
"{{MITX_ROOT_URL}}"
>
</head>
...
...
@@ -31,3 +30,14 @@
{% compressed_js 'module-js' %}
</body>
</html>
{% comment %}
This is a django template version of our main page from which all
other pages inherit. This file should be rewritten to reflect any
changes in main.html! Files used by {% include %} can be written
as mako templates.
Inheriting from this file allows us to include apps that use the
django templating system without rewriting all of their views in
mako.
{% endcomment %}
\ No newline at end of file
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