Commit e845221f by Calen Pennington Committed by Matthew Mongeau

Make mitxmako available to both the lms and the cms

parent 3606ddbf
...@@ -20,10 +20,10 @@ from django.conf import settings ...@@ -20,10 +20,10 @@ from django.conf import settings
requestcontext = None requestcontext = None
lookup = {} lookup = {}
class MakoMiddleware(object): class MakoMiddleware(object):
def __init__(self): def __init__(self):
"""Setup mako variables and lookup object""" """Setup mako variables and lookup object"""
from django.conf import settings
# Set all mako variables based on django settings # Set all mako variables based on django settings
template_locations = settings.MAKO_TEMPLATES template_locations = settings.MAKO_TEMPLATES
module_directory = getattr(settings, 'MAKO_MODULE_DIR', None) module_directory = getattr(settings, 'MAKO_MODULE_DIR', None)
...@@ -42,7 +42,7 @@ class MakoMiddleware(object): ...@@ -42,7 +42,7 @@ class MakoMiddleware(object):
import mitxmako import mitxmako
mitxmako.lookup = lookup mitxmako.lookup = lookup
def process_request (self, request): def process_request(self, request):
global requestcontext global requestcontext
requestcontext = RequestContext(request) requestcontext = RequestContext(request)
requestcontext['is_secure'] = request.is_secure() requestcontext['is_secure'] = request.is_secure()
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
from django.template import Context from django.template import Context
from django.http import HttpResponse from django.http import HttpResponse
import mitxmako.middleware as middleware from . import middleware
from django.conf import settings from django.conf import settings
import mitxmako.middleware
def render_to_string(template_name, dictionary, context=None, namespace='main'): def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_instance = Context(dictionary) context_instance = Context(dictionary)
...@@ -28,15 +27,12 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'): ...@@ -28,15 +27,12 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_dictionary = {} context_dictionary = {}
context_instance['settings'] = settings context_instance['settings'] = settings
context_instance['MITX_ROOT_URL'] = settings.MITX_ROOT_URL context_instance['MITX_ROOT_URL'] = settings.MITX_ROOT_URL
for d in mitxmako.middleware.requestcontext: for d in middleware.requestcontext:
context_dictionary.update(d) context_dictionary.update(d)
for d in context_instance: for d in context_instance:
context_dictionary.update(d) context_dictionary.update(d)
if context: if context:
context_dictionary.update(context) context_dictionary.update(context)
## HACK
## We should remove this, and possible set COURSE_TITLE in the middleware from the session.
if 'COURSE_TITLE' not in context_dictionary: context_dictionary['COURSE_TITLE'] = ''
# fetch and render template # fetch and render template
template = middleware.lookup[namespace].get_template(template_name) template = middleware.lookup[namespace].get_template(template_name)
return template.render(**context_dictionary) return template.render(**context_dictionary)
......
...@@ -14,10 +14,11 @@ ...@@ -14,10 +14,11 @@
from mako.template import Template as MakoTemplate from mako.template import Template as MakoTemplate
import middleware from . import middleware
django_variables = ['lookup', 'template_dirs', 'output_encoding', django_variables = ['lookup', 'template_dirs', 'output_encoding',
'module_directory', 'encoding_errors',] 'module_directory', 'encoding_errors']
class Template(MakoTemplate): class Template(MakoTemplate):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment