Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add input encoding choice #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions djangomako/middleware.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# 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.

# -*- coding: utf-8 -*-
from mako.lookup import TemplateLookup
import tempfile

class MakoMiddleware(object):
def __init__(self):

def __init__(self, get_response):
"""Setup mako variables and lookup object"""
self.get_response = get_response
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)
TEMPLATE_DIRS = settings.TEMPLATES[0]['DIRS']
directories = getattr(settings, 'MAKO_TEMPLATE_DIRS', TEMPLATE_DIRS)
module_directory = getattr(settings, 'MAKO_MODULE_DIR', 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,
lookup = TemplateLookup(directories=directories,
module_directory=module_directory,
output_encoding=output_encoding,
output_encoding=output_encoding,
encoding_errors=encoding_errors,
)
import djangomako
djangomako.lookup = lookup


def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.

response = self.get_response(request)

# Code to be executed for each request/response after
# the view is called.

return response
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os, sys

PACKAGE_NAME = "django-mako"
PACKAGE_VERSION = "0.1.4pre"
PACKAGE_VERSION = "0.1.5"

SUMMARY = 'Django Mako'

Expand Down