Skip to content

Commit

Permalink
Merge pull request #3 from epfl-si/enh-add-django32-42-py39-py310-py3…
Browse files Browse the repository at this point in the history
…11-py312-support

Add Django 3.2 and 4.2 + Python 3.9, 3.10, 3.11 and 3.12 support
  • Loading branch information
obieler authored Sep 18, 2024
2 parents f58bbef + a0faf08 commit 8b896ac
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 23 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
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

# 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 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 }}
uses: actions/setup-python@v2
if: matrix.python-version != '2.7'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -27,15 +38,16 @@ 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: |
${{ 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
python -m pip install --upgrade pip setuptools
python -m pip install --upgrade tox tox-gh-actions
- name: Tox tests
Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):
------------------

Expand Down
21 changes: 15 additions & 6 deletions authority/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from django import VERSION as django_version
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext, ungettext, ugettext_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
Expand All @@ -10,10 +11,18 @@
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 >= (4, 0):
from django.utils.encoding import force_str as force_text # Django 4.x
elif django_version >= (2, 0):
from django.utils.encoding import force_text # Django 2.x and 3.x
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.7
else:
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
Expand Down Expand Up @@ -100,7 +109,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,
Expand Down
7 changes: 6 additions & 1 deletion authority/decorators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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
from django.shortcuts import get_object_or_404
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

Expand Down
2 changes: 1 addition & 1 deletion authority/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion authority/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion authority/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion authority/urls.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion authority/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion authority/widgets.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion example/exampleapp/forms.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion example/exampleapp/permissions.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion example/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -16,10 +17,13 @@ commands =
coverage xml
deps =
coverage
setuptools
dj111: Django>=1.11,<2.0
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]
Expand All @@ -37,3 +41,7 @@ python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

0 comments on commit 8b896ac

Please sign in to comment.