From c7a4ea76599406ec5511bbd968d5888c396ef01b Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Fri, 13 Sep 2024 17:57:19 +0200 Subject: [PATCH 1/9] =?UTF-8?q?ugettext=5Flazy=20=E2=86=92=20gettext=5Flaz?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authority/admin.py | 2 +- authority/forms.py | 2 +- authority/models.py | 2 +- authority/sites.py | 2 +- authority/widgets.py | 2 +- example/exampleapp/forms.py | 2 +- example/exampleapp/permissions.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/authority/admin.py b/authority/admin.py index 10cca73..9b746b1 100644 --- a/authority/admin.py +++ b/authority/admin.py @@ -1,6 +1,6 @@ from django import forms from django.http import HttpResponseRedirect -from django.utils.translation import ugettext, ungettext, ugettext_lazy as _ +from django.utils.translation import ugettext, ungettext, gettext_lazy as _ from django.shortcuts import render from django.utils.safestring import mark_safe from django.forms.formsets import all_valid diff --git a/authority/forms.py b/authority/forms.py index 78d90a9..a4417a3 100644 --- a/authority/forms.py +++ b/authority/forms.py @@ -1,5 +1,5 @@ from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.contrib.contenttypes.models import ContentType diff --git a/authority/models.py b/authority/models.py index 61674a5..2d6415a 100644 --- a/authority/models.py +++ b/authority/models.py @@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.auth.models import Group -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from authority.managers import PermissionManager diff --git a/authority/sites.py b/authority/sites.py index f124c2a..43a7088 100644 --- a/authority/sites.py +++ b/authority/sites.py @@ -2,7 +2,7 @@ from django.apps import apps from django.db import models from django.db.models.base import ModelBase -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.core.exceptions import ImproperlyConfigured from authority.permissions import BasePermission diff --git a/authority/widgets.py b/authority/widgets.py index fb5821b..cf5b359 100644 --- a/authority/widgets.py +++ b/authority/widgets.py @@ -1,7 +1,7 @@ from django import forms from django.conf import settings from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.contrib.admin.widgets import ForeignKeyRawIdWidget diff --git a/example/exampleapp/forms.py b/example/exampleapp/forms.py index 3c9c05e..4187206 100644 --- a/example/exampleapp/forms.py +++ b/example/exampleapp/forms.py @@ -1,5 +1,5 @@ from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from authority.forms import UserPermissionForm diff --git a/example/exampleapp/permissions.py b/example/exampleapp/permissions.py index b0f74cd..346a272 100644 --- a/example/exampleapp/permissions.py +++ b/example/exampleapp/permissions.py @@ -1,5 +1,5 @@ from django.contrib.flatpages.models import FlatPage -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ import authority from authority.permissions import BasePermission From 46617f462c3fae2ee1e56007490d3d38a7b3cbb1 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Fri, 13 Sep 2024 18:06:39 +0200 Subject: [PATCH 2/9] Add missing changes --- authority/admin.py | 4 ++-- authority/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/authority/admin.py b/authority/admin.py index 9b746b1..9afeb3d 100644 --- a/authority/admin.py +++ b/authority/admin.py @@ -1,6 +1,6 @@ from django import forms from django.http import HttpResponseRedirect -from django.utils.translation import ugettext, ungettext, gettext_lazy as _ +from django.utils.translation import gettext, ngettext, gettext_lazy as _ from django.shortcuts import render from django.utils.safestring import mark_safe from django.forms.formsets import all_valid @@ -100,7 +100,7 @@ def edit_permissions(modeladmin, request, queryset): context = { "errors": ActionErrorList(formsets), - "title": ugettext("Permissions for %s") % force_text(opts.verbose_name_plural), + "title": gettext("Permissions for %s") % force_text(opts.verbose_name_plural), "inline_admin_formsets": inline_admin_formsets, "app_label": app_label, "change": True, diff --git a/authority/views.py b/authority/views.py index f2b82be..fed2682 100644 --- a/authority/views.py +++ b/authority/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect, HttpResponseForbidden from django.apps import apps -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.template import loader from django.contrib.auth.decorators import login_required From 579afd329ddcbe8bee1842e8b46bc576a0be8d58 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 11:19:54 +0200 Subject: [PATCH 3/9] Fix + extend compatibility Python (<=3.12) and Django (3.2, 4.2) --- .github/workflows/test.yml | 2 +- authority/admin.py | 15 +++++++++++---- authority/decorators.py | 7 ++++++- authority/urls.py | 7 ++++++- example/urls.py | 8 +++++++- tox.ini | 9 ++++++++- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cacbb23..017bc73 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false max-parallel: 5 matrix: - python-version: ['2.7', '3.6', '3.7', '3.8'] + python-version: ['2.7', '3.6', '3.7', '3.8','3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 diff --git a/authority/admin.py b/authority/admin.py index 9afeb3d..da06ec1 100644 --- a/authority/admin.py +++ b/authority/admin.py @@ -1,4 +1,5 @@ from django import forms +from django import VERSION as django_version from django.http import HttpResponseRedirect from django.utils.translation import gettext, ngettext, gettext_lazy as _ from django.shortcuts import render @@ -10,10 +11,16 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text +from sys import version_info as python_version +if django_version[0] >= 4: + from django.utils.encoding import force_str as force_text # Django 4.x +elif django_version[0] >= 2: + from django.utils.encoding import force_text # Django 2.x and 3.x +else: + if python_version[0] < 3: + from django.utils.encoding import force_unicode as force_text # Django 1.x with Python 2.x + else: + raise ImportError("Unsupported Django version or Python version") from authority.models import Permission from authority.widgets import GenericForeignKeyRawIdWidget diff --git a/authority/decorators.py b/authority/decorators.py index a7ec19e..1bb1656 100644 --- a/authority/decorators.py +++ b/authority/decorators.py @@ -1,6 +1,5 @@ import inspect from django.http import HttpResponseRedirect -from django.utils.http import urlquote from django.utils.functional import wraps from django.db.models import Model from django.apps import apps @@ -8,6 +7,12 @@ from django.conf import settings from django.contrib.auth import REDIRECT_FIELD_NAME +from sys import version_info +if version_info[0] < 3: + from urllib import quote as urlquote # Python 2.7 +else: + from urllib.parse import quote as urlquote # Python 3.x + from authority.utils import get_check from authority.views import permission_denied diff --git a/authority/urls.py b/authority/urls.py index a11568c..3330903 100644 --- a/authority/urls.py +++ b/authority/urls.py @@ -1,4 +1,9 @@ -from django.conf.urls import url +from django import VERSION +if VERSION < (2, 0): + from django.conf.urls import url +else: + from django.urls import re_path as url + from authority.views import ( add_permission, delete_permission, diff --git a/example/urls.py b/example/urls.py index 978ceb5..ad15860 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,7 +1,13 @@ import django.contrib.auth.views -from django.conf.urls import include, handler500, url +from django.conf.urls import include, handler500 from django.conf import settings +from django import VERSION +if VERSION < (2, 0): + from django.conf.urls import url +else: + from django.urls import re_path as url + import authority.views import authority.urls import example.exampleapp.views diff --git a/tox.ini b/tox.ini index 444a737..b317667 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,8 @@ minversion = 1.8 envlist = py27-dj111 py37-dj{111,22} - {py36,py37,py38}-dj{30,31} + {py36,py37,py38}-dj{30,31,32} + {py38,py39,py310,py311,py312}-dj42 py37-check [testenv] @@ -20,6 +21,8 @@ deps = dj22: Django>=2.2,<2.3 dj30: Django>=3.0,<3.1 dj31: Django>=3.1,<3.2 + dj32: Django>=3.2,<4.0 + dj42: Django>=4.2,<4.3 [testenv:py37-check] @@ -37,3 +40,7 @@ python = 3.6: py36 3.7: py37 3.8: py38 + 3.9: py39 + 3.10: py310 + 3.11: py311 + 3.12: py312 From 378fcf559c11117864e849ed0259c835f0eee73e Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 13:41:48 +0200 Subject: [PATCH 4/9] Fix install py27 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 017bc73..5c86364 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: fail-fast: false max-parallel: 5 @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From 049d239d20f4b683dff82f2f6e2491d88877f7b4 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 13:44:02 +0200 Subject: [PATCH 5/9] Add setuptools --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5c86364..1f932a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools python -m pip install --upgrade tox tox-gh-actions - name: Tox tests From 9a336f50c765acb6583f66c14a96e7c90c514c28 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 15:29:06 +0200 Subject: [PATCH 6/9] Try fix tox test py27, 37 --- .github/workflows/test.yml | 15 +++++++++++++-- authority/admin.py | 12 +++++++----- tox.ini | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f932a5..fe8efbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false max-parallel: 5 @@ -14,7 +14,17 @@ jobs: steps: - uses: actions/checkout@v2 + # Special handling for Python 2.7 + - name: Set up Python 2.7 and pip (+ install dependencies) + if: matrix.python-version == '2.7' + run: | + sudo apt-get update + sudo apt-get install -y python2.7 python-pip + python2.7 -m pip install --upgrade "pip<21.0" "setuptools<45" + python2.7 -m pip install tox==3.24.4 tox-gh-actions + - name: Set up Python ${{ matrix.python-version }} + if: matrix.python-version != '2.7' uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -33,7 +43,8 @@ jobs: restore-keys: | ${{ matrix.python-version }}-v1- - - name: Install dependencies + - name: Install dependencies for Python 3.x + if: matrix.python-version != '2.7' run: | python -m pip install --upgrade pip setuptools python -m pip install --upgrade tox tox-gh-actions diff --git a/authority/admin.py b/authority/admin.py index da06ec1..0e046bf 100644 --- a/authority/admin.py +++ b/authority/admin.py @@ -12,15 +12,17 @@ from django.core.exceptions import PermissionDenied from sys import version_info as python_version -if django_version[0] >= 4: +if django_version >= (4, 0): from django.utils.encoding import force_str as force_text # Django 4.x -elif django_version[0] >= 2: +elif django_version >= (2, 0): from django.utils.encoding import force_text # Django 2.x and 3.x -else: +elif django_version >= (1, 11): if python_version[0] < 3: - from django.utils.encoding import force_unicode as force_text # Django 1.x with Python 2.x + from django.utils.encoding import force_unicode as force_text # Django 1.x with Python 2.7 else: - raise ImportError("Unsupported Django version or Python version") + from django.utils.encoding import force_text +else: + raise ImportError("Unsupported Django version or Python version") from authority.models import Permission from authority.widgets import GenericForeignKeyRawIdWidget diff --git a/tox.ini b/tox.ini index b317667..4246b1f 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ commands = coverage xml deps = coverage + setuptools dj111: Django>=1.11,<2.0 dj22: Django>=2.2,<2.3 dj30: Django>=3.0,<3.1 From db69f755e513fd4fc86d4808cf31e8ca3e3b3ff6 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 15:43:20 +0200 Subject: [PATCH 7/9] Try fix GH action/cache with py27 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe8efbc..33426ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: fail-fast: false max-parallel: 5 @@ -37,7 +37,7 @@ jobs: - name: Cache uses: actions/cache@v2 with: - path: ${{ steps.pip-cache.outputs.dir }} + path: ~/.cache/pip key: ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }} restore-keys: | From 335edddfb8c7f2e72fdd6e373a7fd6390745a6fe Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 16:12:37 +0200 Subject: [PATCH 8/9] Fix install pip for py27 test --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 33426ff..777c803 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,8 +19,9 @@ jobs: if: matrix.python-version == '2.7' run: | sudo apt-get update - sudo apt-get install -y python2.7 python-pip - python2.7 -m pip install --upgrade "pip<21.0" "setuptools<45" + sudo apt-get install -y python2.7 curl + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py + python2.7 get-pip.py --upgrade "pip<21.0" "setuptools<45" python2.7 -m pip install tox==3.24.4 tox-gh-actions - name: Set up Python ${{ matrix.python-version }} From a0faf08f81f4a491f763966622473587fa069af2 Mon Sep 17 00:00:00 2001 From: Olivier Bieler Date: Tue, 17 Sep 2024 16:31:12 +0200 Subject: [PATCH 9/9] Add line in CHANGELOG --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 7683b80..f6ebd10 100644 --- a/README.rst +++ b/README.rst @@ -58,6 +58,12 @@ html version using the setup.py:: Changelog: ========== +0.16 (changed in fork → epfl-si) +-------------------------------- + +* Add Django 3.2 and 4.2 support. +* Add Python 3.9, 3.10, 3.11 and 3.12 support. + 0.15 (unreleased): ------------------