Added some comments for the mitxmako additions.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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 %}
|
||||
Reference in New Issue
Block a user