Support Django 2.0

This is the final change required for Django 2.0 support. Instead of using
MIDDLEWARE_CLASSES use MIDDLEWARE setting. Support for new style middleware was
provided in version 0.3.0, so depend on that version. Django built-in middleware
already supports new style and plinth middleware will now support new style.

The actual semantics of the middleware don't need changes. See:
https://docs.djangoproject.com/en/2.0/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2018-03-12 18:33:43 +05:30 committed by James Valleroy
parent 474b363f0b
commit 1da594c32d
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
5 changed files with 12 additions and 9 deletions

2
debian/control vendored
View File

@ -28,7 +28,7 @@ Build-Depends: debhelper (>= 10~)
, python3-django (>= 1.11)
, python3-django-axes (>= 3.0.3)
, python3-django-captcha
, python3-django-stronghold
, python3-django-stronghold (>= 0.3.0)
, python3-gi
, python3-psutil
, python3-requests

View File

@ -277,7 +277,7 @@ def configure_django():
LOGIN_URL='users:login',
LOGIN_REDIRECT_URL='index',
MESSAGE_TAGS={message_constants.ERROR: 'danger'},
MIDDLEWARE_CLASSES=(
MIDDLEWARE=(
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',

View File

@ -24,6 +24,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.shortcuts import render
from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import ugettext_lazy as _
import logging
@ -38,7 +39,7 @@ from . import views
logger = logging.getLogger(__name__)
class SetupMiddleware(object):
class SetupMiddleware(MiddlewareMixin):
"""Django middleware to show pre-setup message and setup progress."""
@staticmethod
@ -92,7 +93,7 @@ class SetupMiddleware(object):
return view(request, setup_helper=module.setup_helper)
class AdminRequiredMiddleware(object):
class AdminRequiredMiddleware(MiddlewareMixin):
"""Django middleware for authenticating requests for admin areas."""
@staticmethod
@ -106,7 +107,7 @@ class AdminRequiredMiddleware(object):
raise PermissionDenied
class FirstSetupMiddleware(object):
class FirstSetupMiddleware(MiddlewareMixin):
"""Django middleware to block all interactions before first setup."""
@staticmethod

View File

@ -20,17 +20,19 @@ Django middleware to redirect to firstboot wizard if it has not be run
yet.
"""
import logging
from django.conf import settings
from django.http.response import HttpResponseRedirect
from django.urls import reverse
from django.conf import settings
import logging
from django.utils.deprecation import MiddlewareMixin
from plinth.modules import first_boot
LOGGER = logging.getLogger(__name__)
class FirstBootMiddleware(object):
class FirstBootMiddleware(MiddlewareMixin):
"""Forward to firstboot page if firstboot isn't finished yet."""
@staticmethod

View File

@ -212,7 +212,7 @@ setuptools.setup(
'django >= 1.11.0',
'django-bootstrap-form',
'django-simple-captcha',
'django-stronghold',
'django-stronghold >= 0.3.0',
'psutil',
'python-apt',
'python-augeas',