Skip to content

Commit 1fb6fca

Browse files
FreemanPancakepre-commit-ci[bot]joshyu
authored
init support for django4.2 (#150)
* init support for django4.2 * add change log for add compatiable for django 4.2 and python 3.10 * Update CHANGELOG.rst * Update .pre-commit-config.yaml * fix lint config issue * remove test code * add blackline for flake8 * add pyproject.toml file * add requirement files * fix ci failed issue * format setup.py import section * upgrade isort version to fix pre commit ci issue * upgrade the django-upgrade package to pass through the pre commit ci test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upgrade packages in pre commit * resort init file changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * comment the django-upgrade from ci * fix: add missing migration file * fix: update previous file instead of creating new file --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Josh Peng Yu <joshyupeng@gmail.com>
1 parent 1cd77a8 commit 1fb6fca

File tree

17 files changed

+314
-45
lines changed

17 files changed

+314
-45
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Set up Python
1313
uses: actions/setup-python@v2
1414
with:
15-
python-version: 3.9
15+
python-version: '3.10'
1616
- name: Install flake8
1717
run: pip install --upgrade flake8
1818
- name: Run flake8
@@ -29,7 +29,7 @@ jobs:
2929
- name: Set up Python
3030
uses: actions/setup-python@v2
3131
with:
32-
python-version: 3.9
32+
python-version: '3.10'
3333
- run: python -m pip install isort
3434
- name: isort
3535
uses: liskin/gh-problem-matcher-wrap@v1

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
python-version: [ 3.7, 3.8, 3.9 ]
11+
python-version: [ 3.8, 3.9, '3.10' ]
1212
requirements-file: [
13-
dj22_cms40.txt,
1413
dj32_cms40.txt,
14+
dj42_cms40.txt,
1515
]
1616
os: [
1717
ubuntu-20.04,

.pre-commit-config.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@ repos:
44
# rev: v2.31.0
55
# hooks:
66
# - id: pyupgrade
7-
# args: ["--py37-plus"]
7+
# args: ["--py38-plus"]
88
#
9-
- repo: https://github.com/adamchainz/django-upgrade
10-
rev: '1.4.0'
11-
hooks:
12-
- id: django-upgrade
13-
args: [--target-version, "2.2"]
9+
# manually run the upgrade command to fix the issue, no need for ci to run.
10+
# - repo: https://github.com/adamchainz/django-upgrade
11+
# rev: '1.16.0'
12+
# hooks:
13+
# - id: django-upgrade
14+
# args: [--target-version, "4.2"]
1415

1516
- repo: https://github.com/PyCQA/flake8
16-
rev: 4.0.1
17+
rev: 7.0.0
1718
hooks:
1819
- id: flake8
1920

2021
- repo: https://github.com/asottile/yesqa
21-
rev: v1.3.0
22+
rev: v1.5.0
2223
hooks:
2324
- id: yesqa
2425

2526
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.1.0
27+
rev: v4.5.0
2728
hooks:
2829
- id: check-merge-conflict
2930
- id: mixed-line-ending
3031

32+
# upgrade the isort version to fix compatiable issue withe peotry: https://stackoverflow.com/questions/75269700/pre-commit-fails-to-install-isort-5-11-4-with-error-runtimeerror-the-poetry-co
3133
- repo: https://github.com/pycqa/isort
32-
rev: 5.10.1
34+
rev: 5.13.2
3335
hooks:
3436
- id: isort

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44

55
Unreleased
66
==========
7+
* add support for python 3.10
8+
* add support for django 4.2
9+
* drop support for django < 3.2
10+
* drop support python < 3.8
711

812
4.0.1.dev2 (2022-11-15)
913
=======================

djangocms_snippet/admin.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from django.conf import settings
2-
from django.conf.urls import url
32
from django.contrib import admin
43
from django.contrib.admin import helpers
54
from django.contrib.admin.exceptions import DisallowedModelAdminToField
65
from django.contrib.admin.options import IS_POPUP_VAR, TO_FIELD_VAR
76
from django.contrib.admin.utils import flatten_fieldsets, unquote
87
from django.db import models
98
from django.forms import Textarea
9+
from django.urls import path
1010
from django.utils.translation import gettext as _
1111

1212
from cms.utils.permissions import get_model_permission_codename
@@ -29,6 +29,7 @@
2929
djangocms_versioning_enabled = False
3030

3131

32+
@admin.register(Snippet)
3233
class SnippetAdmin(*snippet_admin_classes):
3334
list_display = ('name',)
3435
search_fields = ['name']
@@ -92,10 +93,10 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None
9293
model = self.model
9394
opts = model._meta
9495

95-
obj = self.get_object(request, unquote(snippet_id), to_field)
96+
obj = self.get_object(request, unquote(str(snippet_id)), to_field)
9697

9798
if obj is None:
98-
return self._get_obj_does_not_exist_redirect(request, opts, snippet_id)
99+
return self._get_obj_does_not_exist_redirect(request, opts, str(snippet_id))
99100

100101
fieldsets = self.get_fieldsets(request, obj)
101102
ModelForm = self.get_form(
@@ -142,8 +143,8 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None
142143
def get_urls(self):
143144
info = self.model._meta.app_label, self.model._meta.model_name
144145
return [
145-
url(
146-
r"^(?P<snippet_id>\d+)/preview/$",
146+
path(
147+
"<int:snippet_id>/preview/",
147148
self.admin_site.admin_view(self.preview_view),
148149
name="{}_{}_preview".format(*info),
149150
),
@@ -160,6 +161,3 @@ def has_delete_permission(self, request, obj=None):
160161
get_model_permission_codename(self.model, 'add'),
161162
)
162163
return False
163-
164-
165-
admin.site.register(Snippet, SnippetAdmin)

djangocms_snippet/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import forms
22
from django.contrib import admin
33
from django.db import transaction
4-
from django.utils.translation import ugettext_lazy as _
4+
from django.utils.translation import gettext_lazy as _
55

66
from cms.utils.urlutils import admin_reverse
77

djangocms_snippet/migrations/0005_set_related_name_for_cmsplugin_ptr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class Migration(migrations.Migration):
1212
migrations.AlterField(
1313
model_name='snippetptr',
1414
name='cmsplugin_ptr',
15-
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='djangocms_snippet_snippetptr', serialize=False, to='cms.CMSPlugin'),
15+
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='%(app_label)s_%(class)s', serialize=False, to='cms.cmsplugin'),
1616
),
1717
]

djangocms_snippet/settings.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
HELPER_SETTINGS = {
3+
'SECRET_KEY': "djangocmssnippetstestsuitekey",
4+
'INSTALLED_APPS': [
5+
'tests.utils',
6+
'djangocms_versioning',
7+
'djangocms_snippet',
8+
],
9+
'CMS_LANGUAGES': {
10+
1: [{
11+
'code': 'en',
12+
'name': 'English',
13+
}]
14+
},
15+
'LANGUAGE_CODE': 'en',
16+
'ALLOWED_HOSTS': ['localhost'],
17+
'DJANGOCMS_SNIPPET_VERSIONING_ENABLED': True,
18+
'DJANGOCMS_SNIPPET_MODERATION_ENABLED': True,
19+
'CMS_TEMPLATES': (
20+
("page.html", "Normal page"),
21+
),
22+
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField",
23+
}
24+
25+
26+
def run():
27+
from app_helper import runner
28+
runner.cms('djangocms_snippet')
29+
30+
31+
if __name__ == '__main__':
32+
run()

pyproject.toml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
[build-system]
2+
requires = ["setuptools >= 40.6.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "djangocms-snippet"
7+
version = "4.0.1.dev2"
8+
authors = [
9+
{name = "Divio AG", email = "info@divio.ch"},
10+
]
11+
maintainers = [
12+
{name = "Django CMS Association and contributors", email = "info@django-cms.org"}
13+
]
14+
license = {file = "LICENSE"}
15+
description = "Adds snippet plugin to django CMS."
16+
readme = "README.rst"
17+
requires-python = ">=3.8"
18+
dependencies = [
19+
'django-cms>=4.0',
20+
]
21+
classifiers=[
22+
"Development Status :: 5 - Production/Stable",
23+
"Environment :: Web Environment",
24+
"Intended Audience :: Developers",
25+
"License :: OSI Approved :: BSD License",
26+
"Operating System :: OS Independent",
27+
"Programming Language :: Python",
28+
"Programming Language :: Python :: 3",
29+
"Programming Language :: Python :: 3.8",
30+
"Programming Language :: Python :: 3.9",
31+
"Programming Language :: Python :: 3.10",
32+
"Framework :: Django",
33+
"Framework :: Django :: 3.2",
34+
"Framework :: Django :: 4.2",
35+
"Framework :: Django CMS",
36+
"Framework :: Django CMS :: 4.0",
37+
"Topic :: Internet :: WWW/HTTP",
38+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
39+
"Topic :: Software Development",
40+
"Topic :: Software Development :: Libraries",
41+
]
42+
43+
[project.optional-dependencies]
44+
static-ace = ["djangocms-static-ace"]
45+
46+
[tool.setuptools.packages.find]
47+
where = ["djangocms_snippet"]
48+
exclude = ["tests"]
49+
50+
[project.urls]
51+
"Bug Tracker" = "https://github.com/django-cms/djangocms-snippet/issues"
52+
Changelog = "https://github.com/django-cms/djangocms-snippet/blob/master/CHANGELOG.rst"
53+
Repository = "https://github.com/django-cms/djangocms-snippet"
54+
Support = "https://www.django-cms.org/slack/"
55+
56+
[tool.coverage.run]
57+
branch = true
58+
parallel = true
59+
source = [
60+
"djangocms_snippet",
61+
"tests",
62+
]
63+
64+
[tool.coverage.paths]
65+
source = [
66+
"djangocms_snippet",
67+
".tox/**/site-packages",
68+
]
69+
70+
[tool.coverage.report]
71+
show_missing = true
72+
73+
[tool.mypy]
74+
check_untyped_defs = true
75+
disallow_any_generics = true
76+
disallow_incomplete_defs = true
77+
disallow_untyped_defs = true
78+
mypy_path = "djangocms_snippet/"
79+
no_implicit_optional = true
80+
show_error_codes = true
81+
warn_unreachable = true
82+
warn_unused_ignores = true
83+
84+
[[tool.mypy.overrides]]
85+
module = "tests.*"
86+
allow_untyped_defs = true
87+
88+
89+
[tool.ruff]
90+
# https://beta.ruff.rs/docs/configuration/
91+
line-length = 79
92+
select = [
93+
"E", # pycodestyle errors
94+
"W", # pycodestyle warnings
95+
"F", # pyflakes
96+
"I", # isort
97+
"FBT", # flake8-boolean-trap
98+
"B", # flake8-bugbear
99+
"C", # flake8-comprehensions
100+
"DJ", # flake8-django
101+
"INT", # flake8-gettext
102+
"PIE", # flake8-pie
103+
"SIM", # flake8-simplify
104+
"PGH", # pygrep-hooks
105+
"PLE", # pylint error
106+
"PLR", # pylint refactor
107+
"PLW", # pylint warning
108+
"UP", # pyupgrade
109+
"C901", # mccabe
110+
"N", # pep8-naming
111+
"YTT", # flake8-2020,
112+
"RUF"
113+
]
114+
115+
exclude = [
116+
".eggs",
117+
".git",
118+
".mypy_cache",
119+
".ruff_cache",
120+
".env",
121+
".venv",
122+
"**migrations/**",
123+
"venv",
124+
]
125+
126+
ignore = [
127+
"E501", # line-too-long
128+
"W191", # tab-indentation
129+
]
130+
131+
[tool.ruff.per-file-ignores]
132+
"__init__.py" = [
133+
"F401" # unused-import
134+
]
135+
136+
[tool.ruff.isort]
137+
combine-as-imports = true
138+
known-first-party = [
139+
"djangocms_snippet",
140+
]
141+
extra-standard-library = ["dataclasses"]

requirements.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bump2version
2+
https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
3+
django-treebeard
4+
pip-tools
5+
pre-commit
6+
wheel

0 commit comments

Comments
 (0)