From c8562f0e3efc0c6e0f7600c8f4e3ebd808e4e4bb Mon Sep 17 00:00:00 2001 From: Aiky30 Date: Tue, 10 May 2022 14:12:44 +0100 Subject: [PATCH] port-feat: pre-commit config added from the v3 workstream (#117) Changes partially taken from this change: https://github.com/django-cms/djangocms-snippet/commit/a56091c7358cb712e6bd0c4186588f7ce0811530 Requires additional work when the django-cms 4.0 workstream is official, the version bump code has been ignored because it would generate official releases only: https://github.com/django-cms/djangocms-snippet/issues/116 --- .pre-commit-config.yaml | 35 +++++++++++++++++++++++++++++++++++ CHANGELOG.rst | 1 + djangocms_snippet/admin.py | 6 +++--- tests/test_plugins.py | 3 ++- tests/utils/factories.py | 5 +---- 5 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..37516d4a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: +# Need to drop python 3.5 and 3.6 before we include python upgrade +# - repo: https://github.com/asottile/pyupgrade +# rev: v2.31.0 +# hooks: +# - id: pyupgrade +# args: ["--py37-plus"] +# +# FIXME: Should be enabled for codebases that are minimum django 2.2+ +# - repo: https://github.com/adamchainz/django-upgrade +# rev: '1.4.0' +# hooks: +# - id: django-upgrade +# args: [--target-version, "2.2"] + + - repo: https://github.com/PyCQA/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + + - repo: https://github.com/asottile/yesqa + rev: v1.3.0 + hooks: + - id: yesqa + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-merge-conflict + - id: mixed-line-ending + + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7172ddb3..dd7ab2f3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ Changelog Unreleased ========== +* port-feat: pre-commit config added from the v3 workstream * fix: Added test coverage to admin preview view 4.0.0.dev4 (2022-02-03) diff --git a/djangocms_snippet/admin.py b/djangocms_snippet/admin.py index 6769d9ce..0b5f40de 100644 --- a/djangocms_snippet/admin.py +++ b/djangocms_snippet/admin.py @@ -142,12 +142,12 @@ 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( + url( r"^(?P\d+)/preview/$", self.admin_site.admin_view(self.preview_view), name="{}_{}_preview".format(*info), - ), - ] + super().get_urls() + ), + ] + super().get_urls() def has_delete_permission(self, request, obj=None): """ diff --git a/tests/test_plugins.py b/tests/test_plugins.py index d6ab5182..210af121 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -5,9 +5,10 @@ from cms.test_utils.testcases import CMSTestCase from cms.toolbar.utils import get_object_edit_url, get_object_structure_url -from djangocms_snippet.models import Snippet, SnippetGrouper from djangocms_versioning.models import Version +from djangocms_snippet.models import Snippet, SnippetGrouper + from .utils.factories import SnippetWithVersionFactory diff --git a/tests/utils/factories.py b/tests/utils/factories.py index af8d18ce..9d6210c6 100644 --- a/tests/utils/factories.py +++ b/tests/utils/factories.py @@ -6,11 +6,8 @@ from cms.models import Placeholder import factory -from factory.fuzzy import ( - FuzzyInteger, - FuzzyText, -) from djangocms_versioning.models import Version +from factory.fuzzy import FuzzyInteger, FuzzyText from djangocms_snippet.models import Snippet, SnippetGrouper, SnippetPtr