From 4129687e4184dba876b90277880ed54d905ac492 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 25 Apr 2020 02:59:37 +0200 Subject: [PATCH] Support Django 2.2 and 3.0 --- .travis.yml | 8 +++- README.rst | 2 +- cas_server/apps.py | 7 ++- cas_server/default_settings.py | 7 ++- cas_server/forms.py | 7 ++- .../management/commands/cas_clean_federate.py | 7 ++- .../management/commands/cas_clean_sessions.py | 7 ++- .../management/commands/cas_clean_tickets.py | 7 ++- cas_server/models.py | 8 +++- cas_server/utils.py | 3 +- cas_server/views.py | 12 +++-- requirements-dev.txt | 1 - requirements.txt | 2 +- setup.py | 6 ++- tox.ini | 48 +++++++++++++++++++ 15 files changed, 113 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2b02b2..1499e34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: python matrix: include: - - python: "3.7" + - python: "3.8" env: TOX_ENV=flake8 - - python: "3.7" + - python: "3.8" env: TOX_ENV=check_rst - python: "2.7" env: TOX_ENV=py27-django111 @@ -20,6 +20,10 @@ matrix: - python: "3.6" env: TOX_ENV=py36-django21 - python: "3.7" + env: TOX_ENV=py37-django22 + - python: "3.8" + env: TOX_ENV=py38-django30 + - python: "3.8" env: TOX_ENV=coverage cache: directories: diff --git a/README.rst b/README.rst index 3bebaff..ce70792 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,7 @@ Dependencies ``django-cas-server`` depends on the following python packages: -* Django >= 1.11 < 2.1 +* Django >= 1.11 <= 3.0 * requests >= 2.4 * requests_futures >= 0.9.5 * lxml >= 3.4 diff --git a/cas_server/apps.py b/cas_server/apps.py index 03afab5..29b6616 100644 --- a/cas_server/apps.py +++ b/cas_server/apps.py @@ -9,9 +9,14 @@ # # (c) 2015-2016 Valentin Samir """django config module""" -from django.utils.translation import ugettext_lazy as _ from django.apps import AppConfig +import sys +if sys.version_info < (3, ): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + class CasAppConfig(AppConfig): """ diff --git a/cas_server/default_settings.py b/cas_server/default_settings.py index 8e72b54..744a6f7 100644 --- a/cas_server/default_settings.py +++ b/cas_server/default_settings.py @@ -12,10 +12,15 @@ """Default values for the app's settings""" from django.conf import settings from django.templatetags.static import static -from django.utils.translation import ugettext_lazy as _ from importlib import import_module +import sys +if sys.version_info < (3, ): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + try: #: URL to the logo showed in the up left corner on the default templates. diff --git a/cas_server/forms.py b/cas_server/forms.py index 107423c..5749285 100644 --- a/cas_server/forms.py +++ b/cas_server/forms.py @@ -13,11 +13,16 @@ from .default_settings import settings from django import forms from django.forms import widgets -from django.utils.translation import ugettext_lazy as _ import cas_server.utils as utils import cas_server.models as models +import sys +if sys.version_info < (3, ): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + class BootsrapForm(forms.Form): """ diff --git a/cas_server/management/commands/cas_clean_federate.py b/cas_server/management/commands/cas_clean_federate.py index 795230a..af46457 100644 --- a/cas_server/management/commands/cas_clean_federate.py +++ b/cas_server/management/commands/cas_clean_federate.py @@ -10,10 +10,15 @@ # # (c) 2016 Valentin Samir from django.core.management.base import BaseCommand -from django.utils.translation import ugettext_lazy as _ from ... import models +import sys +if sys.version_info < (3, ): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + class Command(BaseCommand): args = '' diff --git a/cas_server/management/commands/cas_clean_sessions.py b/cas_server/management/commands/cas_clean_sessions.py index d0c63fe..9e8db52 100644 --- a/cas_server/management/commands/cas_clean_sessions.py +++ b/cas_server/management/commands/cas_clean_sessions.py @@ -11,10 +11,15 @@ # (c) 2016 Valentin Samir """Clean deleted sessions management command""" from django.core.management.base import BaseCommand -from django.utils.translation import ugettext_lazy as _ from ... import models +import sys +if sys.version_info < (3,): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + class Command(BaseCommand): """Clean deleted sessions""" diff --git a/cas_server/management/commands/cas_clean_tickets.py b/cas_server/management/commands/cas_clean_tickets.py index 3111016..b2869bd 100644 --- a/cas_server/management/commands/cas_clean_tickets.py +++ b/cas_server/management/commands/cas_clean_tickets.py @@ -11,10 +11,15 @@ # (c) 2016 Valentin Samir """Clean old trickets management command""" from django.core.management.base import BaseCommand -from django.utils.translation import ugettext_lazy as _ from ... import models +import sys +if sys.version_info < (3, ): + from django.utils.translation import ugettext_lazy as _ +else: + from django.utils.translation import gettext_lazy as _ + class Command(BaseCommand): """Clean old trickets""" diff --git a/cas_server/models.py b/cas_server/models.py index 657a669..607c048 100644 --- a/cas_server/models.py +++ b/cas_server/models.py @@ -15,9 +15,13 @@ from .default_settings import settings, SessionStore from django.db import models from django.db.models import Q from django.contrib import messages -from django.utils.translation import ugettext_lazy as _ from django.utils import timezone -from django.utils.encoding import python_2_unicode_compatible +try: + from django.utils.encoding import python_2_unicode_compatible + from django.utils.translation import ugettext_lazy as _ +except ImportError: + def python_2_unicode_compatible(f): return f + from django.utils.translation import gettext_lazy as _ from django.core.mail import send_mail import re diff --git a/cas_server/utils.py b/cas_server/utils.py index 9f8a5af..7e9de27 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -18,11 +18,12 @@ from django.contrib.messages import constants as DEFAULT_MESSAGE_LEVELS from django.core.serializers.json import DjangoJSONEncoder from django.utils import timezone from django.core.exceptions import ValidationError -from django.utils.translation import ugettext_lazy as _ try: from django.urls import reverse + from django.utils.translation import gettext_lazy as _ except ImportError: from django.core.urlresolvers import reverse + from django.utils.translation import ugettext_lazy as _ import re import random diff --git a/cas_server/views.py b/cas_server/views.py index ff8d144..f1616d4 100644 --- a/cas_server/views.py +++ b/cas_server/views.py @@ -16,12 +16,16 @@ from django.shortcuts import render, redirect from django.http import HttpResponse, HttpResponseRedirect from django.contrib import messages from django.utils.decorators import method_decorator -from django.utils.translation import ugettext as _ from django.utils import timezone from django.views.decorators.csrf import csrf_exempt from django.middleware.csrf import CsrfViewMiddleware from django.views.generic import View -from django.utils.encoding import python_2_unicode_compatible +try: + from django.utils.encoding import python_2_unicode_compatible + from django.utils.translation import ugettext as _ +except ImportError: + def python_2_unicode_compatible(f): return f + from django.utils.translation import gettext as _ from django.utils.safestring import mark_safe try: from django.urls import reverse @@ -256,7 +260,7 @@ class FederateAuth(CsrfExemptView): self.service_url = service_url return CASFederateValidateUser(provider, service_url, renew=renew) - def post(self, request, provider=None): + def post(self, request, provider=None, *args, **kwargs): """ method called on POST request @@ -1395,7 +1399,7 @@ class SamlValidate(CsrfExemptView): ticket = None root = None - def post(self, request): + def post(self, request, *args, **kwargs): """ method called on POST request on this view diff --git a/requirements-dev.txt b/requirements-dev.txt index f92821a..b793b42 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,6 +7,5 @@ tox>=1.8.1 pytest>=2.6.4 pytest-django>=2.8.0 pytest-pythonpath>=0.3 -pytest-warnings pytest-cov>=2.2.1 mock>=1 diff --git a/requirements.txt b/requirements.txt index 95b36d9..d69cdb7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django >= 1.11,<2.2 +Django >= 1.11,<=3.0 setuptools>=5.5 requests>=2.4 requests_futures>=0.9.5 diff --git a/setup.py b/setup.py index 4c4af3b..905b68e 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,8 @@ if __name__ == '__main__': 'Framework :: Django :: 1.11', 'Framework :: Django :: 2.0', 'Framework :: Django :: 2.1', + 'Framework :: Django :: 2.2', + 'Framework :: Django :: 3.0', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', @@ -44,6 +46,8 @@ if __name__ == '__main__': 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', @@ -58,7 +62,7 @@ if __name__ == '__main__': }, keywords=['django', 'cas', 'cas3', 'server', 'sso', 'single sign-on', 'authentication', 'auth'], install_requires=[ - 'Django >= 1.11,<2.2', 'requests >= 2.4', 'requests_futures >= 0.9.5', + 'Django >= 1.11,<=3.0', 'requests >= 2.4', 'requests_futures >= 0.9.5', 'lxml >= 3.4', 'six >= 1' ], url="https://github.com/nitmir/django-cas-server", diff --git a/tox.ini b/tox.ini index ff5e1db..5bc8105 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,13 @@ envlist= py36-django20, py35-django21, py36-django21, + py37-django21, + py36-django22, + py37-django22, + py38-django22, + py36-django30, + py37-django30, + py38-django30, [flake8] max-line-length=100 @@ -118,6 +125,47 @@ deps = Django>=2.1,<2.2 {[base]deps} +[testenv:py37-django21] +basepython=python3.7 +deps = + Django>=2.1,<2.2 + {[base]deps} + +[testenv:py36-django22] +basepython=python3.6 +deps = + Django>=2.2,<3.0 + {[base]deps} + +[testenv:py37-django22] +basepython=python3.7 +deps = + Django>=2.2,<3.0 + {[base]deps} + +[testenv:py38-django22] +basepython=python3.8 +deps = + Django>=2.2,<3.0 + {[base]deps} + +[testenv:py36-django30] +basepython=python3.6 +deps = + Django>=3.0,<3.1 + {[base]deps} + +[testenv:py37-django30] +basepython=python3.7 +deps = + Django>=3.0,<3.1 + {[base]deps} + +[testenv:py38-django30] +basepython=python3.8 +deps = + Django>=3.0,<3.1 + {[base]deps} [testenv:flake8]