Skip to content

Commit

Permalink
Add django 4.2 compatibility (#46)
Browse files Browse the repository at this point in the history
* Add compatibility witgh django 4.2, drop python<3.9, djangocms<3.9, django<3.2

* Update github actions

* Fix docs

---------

Co-authored-by: Iacopo Spalletti <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent 6ff9322 commit 2241a3e
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 187 deletions.
22 changes: 22 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[bumpversion]
current_version = 0.6.1.dev0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.?)(?P<release>[a-z]*)(?P<relver>\d*)
serialize =
{major}.{minor}.{patch}.{release}{relver}
{major}.{minor}.{patch}
commit = True
tag = True
sign_tags = True
tag_name = {new_version}
message = Release {new_version}

[bumpversion:part:release]
optional_value = gamma
values =
dev
a
b
rc
gamma

[bumpversion:file:djangocms_redirect/__init__.py]
15 changes: 8 additions & 7 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
python-version: [3.8]
toxenv: [pep8, isort, black, pypi-description, docs, towncrier]
python-version: ["3.11.x"]
toxenv: [ruff, isort, black, pypi-description, docs, towncrier]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Cache tox
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .tox
key: ${{ runner.os }}-lint-${{ matrix.toxenv }}-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-lint-${{ matrix.toxenv }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox>=1.8
python -m pip install --upgrade pip setuptools tox>4
- name: Test with tox
if: ${{ matrix.toxenv != 'towncrier' || (!contains(github.event.head_commit.message, '[pre-commit.ci]') && !contains(github.event.pull_request.body, 'pre-commit.ci start')) }}
run: |
tox -e${{ matrix.toxenv }}
36 changes: 24 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,46 @@ jobs:
test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.continue-on-error }}
strategy:
matrix:
python-version: [3.8, 3.7, 3.6]
django: [31, 30, 22]
cms: [38, 37]
python-version: ["3.11", "3.10", "3.9"]
django: [42, 41, 32]
cms: [311, 39]
continue-on-error: [false]
exclude:
- django: 31
cms: 37
- django: 41
cms: 39
- django: 42
cms: 39
- django: 32
cms: 311
- django: 42
cms: 311
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.toxenv }}
- name: Cache tox
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: .tox
key: ${{ runner.os }}-tox-${{ format('{{py{0}-django{1}-cms{2}}}', matrix.python-version, matrix.django, matrix.cms) }}-${{ hashFiles('setup.cfg') }}
restore-keys: |
${{ runner.os }}-tox-${{ format('{{py{0}-django{1}-cms{2}}}', matrix.python-version, matrix.django, matrix.cms) }}-
- name: Install dependencies
run: |
sudo apt-get install gettext
python -m pip install --upgrade pip tox>=3.5
sudo apt-get install gettext memcached
python -m pip install --upgrade pip tox>4
- name: Test with tox
env:
TOX_ENV: ${{ format('py-django{1}-cms{2}', matrix.python-version, matrix.django, matrix.cms) }}
Expand All @@ -48,7 +56,7 @@ jobs:
tox -e$TOX_ENV
.tox/$TOX_ENV/bin/coverage xml
.tox/$TOX_ENV/bin/coveralls
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
Expand All @@ -59,3 +67,7 @@ jobs:
image: redis
ports:
- 6379:6379
memcached:
image: memcached:latest
ports:
- 11211:11211
43 changes: 17 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
exclude: "(.idea|node_modules|.tox)"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: ".+cfg"
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
Expand All @@ -16,42 +17,29 @@ repos:
- id: fix-encoding-pragma
args:
- --remove
- repo: https://github.com/timothycrosley/isort
rev: "5.6.4"
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 23.3.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.265'
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line
- flake8-bugbear
- flake8-builtins
- flake8-coding
- flake8-commas
- flake8-comprehensions
- flake8-eradicate
- flake8-quotes
- flake8-tidy-imports
- pep8-naming
- repo: https://github.com/econchick/interrogate
rev: 1.3.2
hooks:
- id: interrogate
args:
- "-cpyproject.toml"
- "--quiet"
- id: ruff
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.4
rev: v3.4.0
hooks:
- id: pyupgrade
args:
- --py3-plus
- repo: https://github.com/adamchainz/django-upgrade
rev: "1.13.0"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
- repo: local
hooks:
- id: towncrier
Expand All @@ -60,3 +48,6 @@ repos:
language: system
pass_filenames: false
always_run: true
ci:
skip:
- towncrier
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.10"

sphinx:
configuration: docs/conf.py
fail_on_warning: false
Expand All @@ -9,7 +14,6 @@ formats:
- pdf

python:
version: 3.7
install:
- requirements: requirements-test.txt
- method: pip
Expand Down
1 change: 1 addition & 0 deletions changes/42.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add django 4.2 compatibility, drop python<3.9, djangocms<3.9 and django<3.2
3 changes: 2 additions & 1 deletion djangocms_redirect/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class RedirectMiddleware(MiddlewareMixin):

# Defined as class-level attributes to be subclassing-friendly.
response_gone_class = http.HttpResponseGone
response_redirect_class = http.HttpResponseRedirect
Expand Down Expand Up @@ -57,6 +56,7 @@ def do_redirect(self, request, response=None):
cached_redirect = cache.get(key)

if not cached_redirect:
print("possible_paths", possible_paths)
for path in possible_paths:
filters = dict(site=current_site, old_path=path)
try:
Expand All @@ -73,6 +73,7 @@ def do_redirect(self, request, response=None):
"status_code": r.response_code if r else None,
}
cache.set(key, cached_redirect, timeout=getattr(settings, "DJANGOCMS_REDIRECT_CACHE_TIMEOUT", 3600))
print("cached_redirect", cached_redirect)
if cached_redirect["redirect"] == "":
return self.response_gone_class()
if cached_redirect["status_code"] == "302":
Expand Down
10 changes: 6 additions & 4 deletions djangocms_redirect/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand All @@ -21,7 +20,8 @@ class Migration(migrations.Migration):
"old_path",
models.CharField(
db_index=True,
help_text="This should be an absolute path, excluding the domain name. Example: '/events/search/'.",
help_text="This should be an absolute path, excluding the domain name. "
"Example: '/events/search/'.",
max_length=200,
verbose_name="redirect from",
),
Expand All @@ -30,7 +30,8 @@ class Migration(migrations.Migration):
"new_path",
models.CharField(
blank=True,
help_text="This can be either an absolute path (as above) or a full URL starting with 'http://'.",
help_text="This can be either an absolute path (as above) or a full URL "
"starting with 'http://'.",
max_length=200,
verbose_name="redirect to",
),
Expand All @@ -40,7 +41,8 @@ class Migration(migrations.Migration):
models.CharField(
choices=[("301", "301"), ("302", "302")],
default="301",
help_text="This is the http response code returned if a destination is specified. If no destination is specified the response code will be 410.",
help_text="This is the http response code returned if a destination is specified. "
"If no destination is specified the response code will be 410.",
max_length=3,
verbose_name="response code",
),
Expand Down
4 changes: 2 additions & 2 deletions djangocms_redirect/migrations/0002_auto_20170321_1807.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("djangocms_redirect", "0001_initial"),
]
Expand Down Expand Up @@ -34,7 +33,8 @@ class Migration(migrations.Migration):
("410", "410 - Permanently unavailable"),
],
default="301",
help_text="This is the http response code returned if a destination is specified. If no destination is specified the response code will be 410.",
help_text="This is the http response code returned if a destination is specified. If no "
"destination is specified the response code will be 410.",
max_length=3,
verbose_name="response code",
),
Expand Down
7 changes: 4 additions & 3 deletions djangocms_redirect/migrations/0003_auto_20190810_1009.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("djangocms_redirect", "0002_auto_20170321_1807"),
]
Expand All @@ -15,7 +14,8 @@ class Migration(migrations.Migration):
name="catchall_redirect",
field=models.BooleanField(
default=False,
help_text="If selected all the pages starting with the given string will be redirected to the given redirect path",
help_text="If selected all the pages starting with the given string will be redirected "
"to the given redirect path",
verbose_name="Catchall redirect",
),
),
Expand All @@ -24,7 +24,8 @@ class Migration(migrations.Migration):
name="subpath_match",
field=models.BooleanField(
default=False,
help_text="If selected all the pages starting with the given string will be redirected by replacing the matching subpath with the provided redirect path.",
help_text="If selected all the pages starting with the given string will be redirected"
" by replacing the matching subpath with the provided redirect path.",
verbose_name="Subpath match",
),
),
Expand Down
2 changes: 1 addition & 1 deletion djangocms_redirect/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .utils import normalize_url

Expand Down
Loading

0 comments on commit 2241a3e

Please sign in to comment.