In Django template rendering, context processors only run once.
But when we do template rendering through edxmako (which we do for
each and every web fragment/XBlock), we can end up having hundreds
of invocations of templates and run context processors for each
separately. This removes that work.
This was originally added in ad5cc3d5 and reverted when we saw
errors in one of our environments that seemed to be related to
context processor code. Those errors persisted after the revert,
and so I'm adding this back in (with some modifications based on
review comments).
In Django template rendering, context processors only run once.
But when we do template rendering through edxmako (which we do for
each and every web fragment/XBlock), we can end up having hundreds
of invocations of templates and run context processors for each
separately. This removes that work.
The old code set the output-encoding to None, which means, I want
Unicode strings as output. This made Mako pass markupsafe objects to
"unicode()", which applied all the escaping. Then the result would be
given to Django, would would html-escape it again, resulting in
over-escaping.
By setting the output-encoding to utf8, we use filters.encode.utf8
instead, which is aware of Markupsafe, which avoids the over-escaping.
Fixed the edX middleware to lazily create request
context for Mako templates, so that it is based on
any changes made to the request object.
Verified that with this fix the "Instructor" tab is
correctly hidden when a staff member is viewing
the course as a student.
This code adds the ability to add Mako template lookup directories on
the fly, allowing third party add-ons to contribute their own Mako templates.
A new API function for registering Mako templates is introduced::
from edxmako import add_lookup
add_lookup('main', '/path/to/templates')
# Or, specify a package to lookup using pkg_resources. This will
# add the 'templates' directory inside the current package:
add_lookup('main', 'templates', package=__name__)