general: remove compatibility with django < 1.11 (#38616)
This commit is contained in:
parent
320ee3c457
commit
74230b51ec
|
@ -13,7 +13,7 @@ Package: python-django-mellon
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, ${python:Depends},
|
Depends: ${misc:Depends}, ${python:Depends},
|
||||||
python (>= 2.7),
|
python (>= 2.7),
|
||||||
python-django (>= 1.5),
|
python-django (>= 1:1.11),
|
||||||
python-isodate,
|
python-isodate,
|
||||||
python-lasso,
|
python-lasso,
|
||||||
python-atomicwrites
|
python-atomicwrites
|
||||||
|
@ -23,7 +23,7 @@ Description: SAML authentication for Django
|
||||||
Package: python3-django-mellon
|
Package: python3-django-mellon
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: ${misc:Depends}, ${python:Depends},
|
Depends: ${misc:Depends}, ${python:Depends},
|
||||||
python3-django (>= 1.5),
|
python3-django (>= 1:1.11),
|
||||||
python3-isodate,
|
python3-isodate,
|
||||||
python3-lasso,
|
python3-lasso,
|
||||||
python3-atomicwrites
|
python3-atomicwrites
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
# django-mellon - SAML2 authentication for Django
|
|
||||||
# Copyright (C) 2014-2019 Entr'ouvert
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import django
|
|
||||||
if django.VERSION < (1, 11, 0):
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
MiddlewareClass = object
|
|
||||||
|
|
||||||
is_authenticated = lambda user: user.is_authenticated()
|
|
||||||
else:
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.utils.deprecation import MiddlewareMixin
|
|
||||||
MiddlewareClass = MiddlewareMixin
|
|
||||||
|
|
||||||
is_authenticated = lambda user: user.is_authenticated
|
|
|
@ -17,14 +17,15 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from . import app_settings, utils
|
from . import app_settings, utils
|
||||||
from .compat import reverse, MiddlewareClass, is_authenticated
|
|
||||||
|
|
||||||
PASSIVE_TRIED_COOKIE = 'MELLON_PASSIVE_TRIED'
|
PASSIVE_TRIED_COOKIE = 'MELLON_PASSIVE_TRIED'
|
||||||
|
|
||||||
|
|
||||||
class PassiveAuthenticationMiddleware(MiddlewareClass):
|
class PassiveAuthenticationMiddleware(MiddlewareMixin):
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
# When unlogged remove the PASSIVE_TRIED cookie
|
# When unlogged remove the PASSIVE_TRIED cookie
|
||||||
if app_settings.OPENED_SESSION_COOKIE_NAME \
|
if app_settings.OPENED_SESSION_COOKIE_NAME \
|
||||||
|
@ -50,7 +51,7 @@ class PassiveAuthenticationMiddleware(MiddlewareClass):
|
||||||
return
|
return
|
||||||
if not app_settings.OPENED_SESSION_COOKIE_NAME:
|
if not app_settings.OPENED_SESSION_COOKIE_NAME:
|
||||||
return
|
return
|
||||||
if hasattr(request, 'user') and is_authenticated(request.user):
|
if hasattr(request, 'user') and request.user.is_authenticated:
|
||||||
return
|
return
|
||||||
if PASSIVE_TRIED_COOKIE in request.COOKIES:
|
if PASSIVE_TRIED_COOKIE in request.COOKIES:
|
||||||
return
|
return
|
||||||
|
|
|
@ -14,6 +14,3 @@ urlpatterns = [
|
||||||
url('metadata/$', views.metadata,
|
url('metadata/$', views.metadata,
|
||||||
name='mellon_metadata')
|
name='mellon_metadata')
|
||||||
]
|
]
|
||||||
if django.VERSION < (1, 8):
|
|
||||||
from django.conf.urls import patterns
|
|
||||||
urlpatterns = patterns('', *urlpatterns)
|
|
||||||
|
|
|
@ -25,13 +25,13 @@ from xml.parsers import expat
|
||||||
import django
|
import django
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.timezone import make_aware, now, make_naive, is_aware, get_default_timezone
|
from django.utils.timezone import make_aware, now, make_naive, is_aware, get_default_timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.six.moves.urllib.parse import urlparse
|
from django.utils.six.moves.urllib.parse import urlparse
|
||||||
import lasso
|
import lasso
|
||||||
|
|
||||||
from . import app_settings
|
from . import app_settings
|
||||||
from .compat import reverse
|
|
||||||
|
|
||||||
|
|
||||||
def create_metadata(request):
|
def create_metadata(request):
|
||||||
|
|
|
@ -30,6 +30,7 @@ from django.contrib import auth
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.shortcuts import render, resolve_url
|
from django.shortcuts import render, resolve_url
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
|
@ -38,7 +39,6 @@ from django.db import transaction
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from . import app_settings, utils
|
from . import app_settings, utils
|
||||||
from .compat import reverse, is_authenticated
|
|
||||||
|
|
||||||
RETRY_LOGIN_COOKIE = 'MELLON_RETRY_LOGIN'
|
RETRY_LOGIN_COOKIE = 'MELLON_RETRY_LOGIN'
|
||||||
|
|
||||||
|
@ -529,7 +529,7 @@ class LogoutView(ProfileMixin, LogMixin, View):
|
||||||
next_url = request.GET.get(REDIRECT_FIELD_NAME)
|
next_url = request.GET.get(REDIRECT_FIELD_NAME)
|
||||||
referer = request.META.get('HTTP_REFERER')
|
referer = request.META.get('HTTP_REFERER')
|
||||||
if not referer or utils.same_origin(referer, request.build_absolute_uri()):
|
if not referer or utils.same_origin(referer, request.build_absolute_uri()):
|
||||||
if hasattr(request, 'user') and is_authenticated(request.user):
|
if hasattr(request, 'user') and request.user.is_authenticated:
|
||||||
logout = None
|
logout = None
|
||||||
try:
|
try:
|
||||||
issuer = request.session.get('mellon_session', {}).get('issuer')
|
issuer = request.session.get('mellon_session', {}).get('issuer')
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -91,13 +91,13 @@ setup(name="django-mellon",
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'django>=1.7,<2.3',
|
'django>=1.11,<2.3',
|
||||||
'requests',
|
'requests',
|
||||||
'isodate',
|
'isodate',
|
||||||
'atomicwrites',
|
'atomicwrites',
|
||||||
],
|
],
|
||||||
setup_requires=[
|
setup_requires=[
|
||||||
'django>=1.7,<2',
|
'django>=1.10,<2.3',
|
||||||
],
|
],
|
||||||
tests_require=[
|
tests_require=[
|
||||||
'nose>=0.11.4',
|
'nose>=0.11.4',
|
||||||
|
|
|
@ -26,6 +26,7 @@ import lasso
|
||||||
import pytest
|
import pytest
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.six.moves.urllib import parse as urlparse
|
from django.utils.six.moves.urllib import parse as urlparse
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
|
@ -34,8 +35,6 @@ from mellon.utils import create_metadata
|
||||||
|
|
||||||
from httmock import all_requests, HTTMock, response as mock_response
|
from httmock import all_requests, HTTMock, response as mock_response
|
||||||
|
|
||||||
from mellon.compat import reverse
|
|
||||||
|
|
||||||
from utils import reset_caplog
|
from utils import reset_caplog
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,12 @@ import hashlib
|
||||||
from httmock import HTTMock
|
from httmock import HTTMock
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
|
|
||||||
from xml_utils import assert_xml_constraints
|
from xml_utils import assert_xml_constraints
|
||||||
|
|
||||||
from mellon.compat import reverse
|
|
||||||
|
|
||||||
from utils import error_500, html_response
|
from utils import error_500, html_response
|
||||||
|
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
|
@ -38,11 +38,10 @@ ROOT_URLCONF = 'urls_tests'
|
||||||
TEMPLATE_DIRS = [
|
TEMPLATE_DIRS = [
|
||||||
'tests/templates/',
|
'tests/templates/',
|
||||||
]
|
]
|
||||||
if django.VERSION >= (1, 8):
|
TEMPLATES = [
|
||||||
TEMPLATES = [
|
{
|
||||||
{
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'APP_DIRS': True,
|
||||||
'APP_DIRS': True,
|
'DIRS': TEMPLATE_DIRS,
|
||||||
'DIRS': TEMPLATE_DIRS,
|
},
|
||||||
},
|
]
|
||||||
]
|
|
||||||
|
|
4
tox.ini
4
tox.ini
|
@ -1,5 +1,5 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = coverage-py2-{dj18,dj111}-{pg,sqlite},coverage-py3-dj{111,22}-{pg,sqlite}
|
envlist = coverage-py2-dj111-{pg,sqlite},coverage-py3-dj{111,22}-{pg,sqlite}
|
||||||
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/django-mellon/
|
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/django-mellon/
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
|
@ -14,7 +14,6 @@ setenv =
|
||||||
usedevelop =
|
usedevelop =
|
||||||
coverage: true
|
coverage: true
|
||||||
deps =
|
deps =
|
||||||
dj18: django>=1.8,<1.9
|
|
||||||
dj111: django>=1.11,<1.12
|
dj111: django>=1.11,<1.12
|
||||||
dj22: django>=2.2,<2.3
|
dj22: django>=2.2,<2.3
|
||||||
pg: psycopg2
|
pg: psycopg2
|
||||||
|
@ -30,7 +29,6 @@ deps =
|
||||||
pytz
|
pytz
|
||||||
lxml
|
lxml
|
||||||
cssselect
|
cssselect
|
||||||
dj18: django-webtest<1.9.3
|
|
||||||
dj111: django-webtest<1.9.3
|
dj111: django-webtest<1.9.3
|
||||||
dj22: django-webtest>1.9.3
|
dj22: django-webtest>1.9.3
|
||||||
WebTest
|
WebTest
|
||||||
|
|
Loading…
Reference in New Issue