diff --git a/common/lib/mitxmako/mitxmako/templatetag_helpers.py b/common/lib/mitxmako/mitxmako/templatetag_helpers.py index 6742f3ee1c..e254625d3d 100644 --- a/common/lib/mitxmako/mitxmako/templatetag_helpers.py +++ b/common/lib/mitxmako/mitxmako/templatetag_helpers.py @@ -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) + diff --git a/lms/templates/main_django.html b/lms/templates/main_django.html index 22620710c3..74838d7b85 100644 --- a/lms/templates/main_django.html +++ b/lms/templates/main_django.html @@ -12,7 +12,6 @@ {% render_block "css" %} {% render_block "js" %} - @@ -31,3 +30,14 @@ {% compressed_js 'module-js' %} + +{% 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