Commit e975d3f2 by fischerl

merge

parents 859afccd c99bc566
......@@ -12,7 +12,7 @@ from django.core.validators import validate_email, validate_slug
from django.db import connection
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from models import Registration, UserProfile
log = logging.getLogger("mitx.auth")
......
......@@ -7,7 +7,7 @@ from django.conf import settings
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from models import ServerCircuit
......
from lxml.etree import Element
from lxml import etree
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
class textline(object):
@staticmethod
......
......@@ -17,7 +17,7 @@ from django.http import HttpResponse
from django.shortcuts import redirect
from django.template import Context
from django.template import Context, loader
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from auth.models import UserProfile
from models import StudentModule
......
......@@ -16,7 +16,7 @@ from lxml import etree
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from django.http import Http404
from x_module import XModule
......
......@@ -2,7 +2,7 @@ import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
......
......@@ -2,7 +2,7 @@ import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
......
......@@ -5,7 +5,7 @@ from lxml import etree
## TODO: Abstract out from Django
from django.http import Http404
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
......
......@@ -2,7 +2,7 @@ import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
......
......@@ -5,7 +5,7 @@ from lxml import etree
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
......
......@@ -12,7 +12,7 @@ from django.contrib.auth.models import User
from django.http import HttpResponse, Http404
from django.shortcuts import redirect
from django.template import Context, loader
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from django.db import connection
from lxml import etree
......
================================================================================
django-mako
================================================================================
This module provides a drop in replacement of Django templates for Mako
Templates.
Django: http://www.djangoproject.com/
Mako: http://www.makotemplates.org/
================================================================================
How to install?
================================================================================
$ sudo python setup.py install
# Copyright (c) 2008 Mikeal Rogers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
lookup = None
# Copyright (c) 2008 Mikeal Rogers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mako.lookup import TemplateLookup
import tempfile
class MakoMiddleware(object):
def __init__(self):
"""Setup mako variables and lookup object"""
from django.conf import settings
# Set all mako variables based on django settings
global template_dirs, output_encoding, module_directory, encoding_errors
directories = getattr(settings, 'MAKO_TEMPLATE_DIRS', settings.TEMPLATE_DIRS)
module_directory = getattr(settings, 'MAKO_MODULE_DIR', None)
if module_directory is None:
module_directory = tempfile.mkdtemp()
output_encoding = getattr(settings, 'MAKO_OUTPUT_ENCODING', 'utf-8')
encoding_errors = getattr(settings, 'MAKO_ENCODING_ERRORS', 'replace')
global lookup
lookup = TemplateLookup(directories=directories,
module_directory=module_directory,
output_encoding=output_encoding,
encoding_errors=encoding_errors,
)
import mitxmako
mitxmako.lookup = lookup
# Copyright (c) 2008 Mikeal Rogers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.template import Context
from django.http import HttpResponse
import middleware
def render_to_string(template_name, dictionary, context_instance=None):
context_instance = context_instance or Context(dictionary)
# add dictionary to context_instance
context_instance.update(dictionary or {})
# collapse context_instance to a single dictionary for mako
context_dictionary = {}
for d in context_instance:
context_dictionary.update(d)
# fetch and render template
template = middleware.lookup.get_template(template_name)
return template.render(**context_dictionary)
def render_to_response(template_name, dictionary, context_instance=None, **kwargs):
"""
Returns a HttpResponse whose content is filled with the result of calling
lookup.get_template(args[0]).render with the passed arguments.
"""
return HttpResponse(render_to_string(template_name, dictionary, context_instance), **kwargs)
# Copyright (c) 2008 Mikeal Rogers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mako.template import Template as MakoTemplate
import middleware
django_variables = ['lookup', 'template_dirs', 'output_encoding',
'module_directory', 'encoding_errors',]
class Template(MakoTemplate):
def __init__(self, *args, **kwargs):
"""Overrides base __init__ to provide django variable overrides"""
if not kwargs.get('no_django', False):
overrides = dict([(k, getattr(middleware, k, None),) for k in django_variables])
kwargs.update(overrides)
super(Template, self).__init__(*args, **kwargs)
......@@ -3,6 +3,9 @@ import sys
import djcelery
LIB_URL = '/static/lib/'
BOOK_URL = '/static/book/'
# Our parent dir (mitx_all) is the BASE_DIR
BASE_DIR = os.path.abspath(os.path.join(__file__, "..", ".."))
......@@ -87,8 +90,12 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware',
<<<<<<< local
'djangomako.middleware.MakoMiddleware',
'askbot.middleware.pagesize.QuestionsPageSizeMiddleware',
=======
'mitxmako.middleware.MakoMiddleware',
>>>>>>> other
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)
......@@ -110,6 +117,7 @@ INSTALLED_APPS = (
'track',
'circuit',
'perfstats',
'util',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
......
......@@ -81,7 +81,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware',
'djangomako.middleware.MakoMiddleware',
'mitxmako.middleware.MakoMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)
......
......@@ -8,7 +8,7 @@ circuit:name becomes the circuit.
import simplewiki.settings as settings
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
import markdown
try:
......
......@@ -15,10 +15,10 @@ from django.template import Context
from django.template import RequestContext, Context, loader
from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from mako.lookup import TemplateLookup
from mako.template import Template
import djangomako.middleware
import mitxmako.middleware
from models import * # TODO: Clean up
from settings import *
......
......@@ -3,7 +3,7 @@
# List of valid templates is explicitly managed for (short-term)
# security reasons.
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
from django.shortcuts import redirect
from django.core.context_processors import csrf
......
......@@ -4,7 +4,7 @@ import os
from django.conf import settings
from django.http import Http404
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
def index(request, page=0):
if not request.user.is_authenticated():
......
......@@ -10,7 +10,7 @@ from django.core.mail import send_mail
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
from mitxmako.shortcuts import render_to_response, render_to_string
import courseware.capa.calc
import track.views
......
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