Skip to content

Commit

Permalink
init support for django4.2 (#150)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent 1cd77a8 commit 1fb6fca
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: '3.10'
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: '3.10'
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9 ]
python-version: [ 3.8, 3.9, '3.10' ]
requirements-file: [
dj22_cms40.txt,
dj32_cms40.txt,
dj42_cms40.txt,
]
os: [
ubuntu-20.04,
Expand Down
22 changes: 12 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ repos:
# rev: v2.31.0
# hooks:
# - id: pyupgrade
# args: ["--py37-plus"]
# args: ["--py38-plus"]
#
- repo: https://github.com/adamchainz/django-upgrade
rev: '1.4.0'
hooks:
- id: django-upgrade
args: [--target-version, "2.2"]
# manually run the upgrade command to fix the issue, no need for ci to run.
# - repo: https://github.com/adamchainz/django-upgrade
# rev: '1.16.0'
# hooks:
# - id: django-upgrade
# args: [--target-version, "4.2"]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.3.0
rev: v1.5.0
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: mixed-line-ending

# 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
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog

Unreleased
==========
* add support for python 3.10
* add support for django 4.2
* drop support for django < 3.2
* drop support python < 3.8

4.0.1.dev2 (2022-11-15)
=======================
Expand Down
14 changes: 6 additions & 8 deletions djangocms_snippet/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin import helpers
from django.contrib.admin.exceptions import DisallowedModelAdminToField
from django.contrib.admin.options import IS_POPUP_VAR, TO_FIELD_VAR
from django.contrib.admin.utils import flatten_fieldsets, unquote
from django.db import models
from django.forms import Textarea
from django.urls import path
from django.utils.translation import gettext as _

from cms.utils.permissions import get_model_permission_codename
Expand All @@ -29,6 +29,7 @@
djangocms_versioning_enabled = False


@admin.register(Snippet)
class SnippetAdmin(*snippet_admin_classes):
list_display = ('name',)
search_fields = ['name']
Expand Down Expand Up @@ -92,10 +93,10 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None
model = self.model
opts = model._meta

obj = self.get_object(request, unquote(snippet_id), to_field)
obj = self.get_object(request, unquote(str(snippet_id)), to_field)

if obj is None:
return self._get_obj_does_not_exist_redirect(request, opts, snippet_id)
return self._get_obj_does_not_exist_redirect(request, opts, str(snippet_id))

fieldsets = self.get_fieldsets(request, obj)
ModelForm = self.get_form(
Expand Down Expand Up @@ -142,8 +143,8 @@ def preview_view(self, request, snippet_id=None, form_url='', extra_context=None
def get_urls(self):
info = self.model._meta.app_label, self.model._meta.model_name
return [
url(
r"^(?P<snippet_id>\d+)/preview/$",
path(
"<int:snippet_id>/preview/",
self.admin_site.admin_view(self.preview_view),
name="{}_{}_preview".format(*info),
),
Expand All @@ -160,6 +161,3 @@ def has_delete_permission(self, request, obj=None):
get_model_permission_codename(self.model, 'add'),
)
return False


admin.site.register(Snippet, SnippetAdmin)
2 changes: 1 addition & 1 deletion djangocms_snippet/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.contrib import admin
from django.db import transaction
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.utils.urlutils import admin_reverse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='snippetptr',
name='cmsplugin_ptr',
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'),
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'),
),
]
32 changes: 32 additions & 0 deletions djangocms_snippet/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
HELPER_SETTINGS = {
'SECRET_KEY': "djangocmssnippetstestsuitekey",
'INSTALLED_APPS': [
'tests.utils',
'djangocms_versioning',
'djangocms_snippet',
],
'CMS_LANGUAGES': {
1: [{
'code': 'en',
'name': 'English',
}]
},
'LANGUAGE_CODE': 'en',
'ALLOWED_HOSTS': ['localhost'],
'DJANGOCMS_SNIPPET_VERSIONING_ENABLED': True,
'DJANGOCMS_SNIPPET_MODERATION_ENABLED': True,
'CMS_TEMPLATES': (
("page.html", "Normal page"),
),
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField",
}


def run():
from app_helper import runner
runner.cms('djangocms_snippet')


if __name__ == '__main__':
run()
141 changes: 141 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "djangocms-snippet"
version = "4.0.1.dev2"
authors = [
{name = "Divio AG", email = "[email protected]"},
]
maintainers = [
{name = "Django CMS Association and contributors", email = "[email protected]"}
]
license = {file = "LICENSE"}
description = "Adds snippet plugin to django CMS."
readme = "README.rst"
requires-python = ">=3.8"
dependencies = [
'django-cms>=4.0',
]
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django CMS",
"Framework :: Django CMS :: 4.0",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
]

[project.optional-dependencies]
static-ace = ["djangocms-static-ace"]

[tool.setuptools.packages.find]
where = ["djangocms_snippet"]
exclude = ["tests"]

[project.urls]
"Bug Tracker" = "https://github.com/django-cms/djangocms-snippet/issues"
Changelog = "https://github.com/django-cms/djangocms-snippet/blob/master/CHANGELOG.rst"
Repository = "https://github.com/django-cms/djangocms-snippet"
Support = "https://www.django-cms.org/slack/"

[tool.coverage.run]
branch = true
parallel = true
source = [
"djangocms_snippet",
"tests",
]

[tool.coverage.paths]
source = [
"djangocms_snippet",
".tox/**/site-packages",
]

[tool.coverage.report]
show_missing = true

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
mypy_path = "djangocms_snippet/"
no_implicit_optional = true
show_error_codes = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
allow_untyped_defs = true


[tool.ruff]
# https://beta.ruff.rs/docs/configuration/
line-length = 79
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"FBT", # flake8-boolean-trap
"B", # flake8-bugbear
"C", # flake8-comprehensions
"DJ", # flake8-django
"INT", # flake8-gettext
"PIE", # flake8-pie
"SIM", # flake8-simplify
"PGH", # pygrep-hooks
"PLE", # pylint error
"PLR", # pylint refactor
"PLW", # pylint warning
"UP", # pyupgrade
"C901", # mccabe
"N", # pep8-naming
"YTT", # flake8-2020,
"RUF"
]

exclude = [
".eggs",
".git",
".mypy_cache",
".ruff_cache",
".env",
".venv",
"**migrations/**",
"venv",
]

ignore = [
"E501", # line-too-long
"W191", # tab-indentation
]

[tool.ruff.per-file-ignores]
"__init__.py" = [
"F401" # unused-import
]

[tool.ruff.isort]
combine-as-imports = true
known-first-party = [
"djangocms_snippet",
]
extra-standard-library = ["dataclasses"]
6 changes: 6 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bump2version
https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
django-treebeard
pip-tools
pre-commit
wheel
Loading

0 comments on commit 1fb6fca

Please sign in to comment.