From 69f748acbd1e7b1f2947494f3d86bc1b7f7ba8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Thu, 23 Feb 2017 00:43:23 +0100 Subject: [PATCH] Django1.11-style MiddleWares The design of middlewares has changed in Django 1.11 --- gestioCOF/settings_dev.py | 6 +++--- kfet/middleware.py | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/gestioCOF/settings_dev.py b/gestioCOF/settings_dev.py index feacba52..3f5ac2d2 100644 --- a/gestioCOF/settings_dev.py +++ b/gestioCOF/settings_dev.py @@ -50,18 +50,18 @@ INSTALLED_APPS = ( 'kfet.apps.KFetConfig', ) -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = [ 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - 'kfet.middleware.KFetAuthenticationMiddleware', + 'kfet.middleware.kfet_auth_middleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', -) +] ROOT_URLCONF = 'gestioCOF.urls' diff --git a/kfet/middleware.py b/kfet/middleware.py index dbb192c6..02d3d2f4 100644 --- a/kfet/middleware.py +++ b/kfet/middleware.py @@ -1,17 +1,16 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, - print_function, unicode_literals) -from builtins import * - -from django.http import HttpResponseForbidden from kfet.backends import KFetBackend -from kfet.models import Account -class KFetAuthenticationMiddleware(object): - def process_request(self, request): - kfet_backend = KFetBackend() + +def kfet_auth_middleware(get_response): + kfet_backend = KFetBackend() + + def middleware(request): temp_request_user = kfet_backend.authenticate(request) if temp_request_user: request.real_user = request.user request.user = temp_request_user + return get_response(request) + + return middleware