From 33f7e57da6823daafb0a5bf5b15cf2ec34f03eb3 Mon Sep 17 00:00:00 2001 From: duoduo369 Date: Sun, 14 Dec 2014 15:43:50 +0800 Subject: [PATCH 1/2] add input encoding choice --- djangomako/middleware.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/djangomako/middleware.py b/djangomako/middleware.py index 3d82c30..64e6e16 100644 --- a/djangomako/middleware.py +++ b/djangomako/middleware.py @@ -24,14 +24,15 @@ def __init__(self): directories = getattr(settings, 'MAKO_TEMPLATE_DIRS', settings.TEMPLATE_DIRS) module_directory = getattr(settings, 'MAKO_MODULE_DIR', tempfile.mkdtemp()) output_encoding = getattr(settings, 'MAKO_OUTPUT_ENCODING', 'utf-8') + input_encoding = getattr(settings, 'MAKO_INPUT_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, + input_encoding=input_encoding, + output_encoding=output_encoding, encoding_errors=encoding_errors, ) import djangomako djangomako.lookup = lookup - \ No newline at end of file From 1177157317522edcc56d55a530dd3d7547dbb823 Mon Sep 17 00:00:00 2001 From: duoduo369 Date: Tue, 3 Dec 2019 04:34:08 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=85=BC=E5=AE=B9django=201.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- djangomako/middleware.py | 35 +++++++++++++++++------------------ setup.py | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/djangomako/middleware.py b/djangomako/middleware.py index 64e6e16..02d6e50 100644 --- a/djangomako/middleware.py +++ b/djangomako/middleware.py @@ -1,38 +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') - input_encoding = getattr(settings, 'MAKO_INPUT_ENCODING', 'utf-8') encoding_errors = getattr(settings, 'MAKO_ENCODING_ERRORS', 'replace') global lookup lookup = TemplateLookup(directories=directories, module_directory=module_directory, - input_encoding=input_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 diff --git a/setup.py b/setup.py index 6dc5ad4..3e9c26e 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ import os, sys PACKAGE_NAME = "django-mako" -PACKAGE_VERSION = "0.1.4pre" +PACKAGE_VERSION = "0.1.5" SUMMARY = 'Django Mako'