diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4242ab..0f07b27 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,8 @@ ci: autofix_prs: false default_language_version: - python: python3.8 + python: python3.11 + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 @@ -17,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/pycqa/isort @@ -39,8 +40,8 @@ repos: hooks: - id: check-manifest args: [--no-build-isolation] - - repo: https://github.com/asottile/blacken-docs - rev: v1.12.1 + - repo: https://github.com/adamchainz/blacken-docs + rev: 1.13.0 hooks: - id: blacken-docs - additional_dependencies: [black==22.3.0] + additional_dependencies: [black==23.1.0] diff --git a/CHANGELOG.md b/CHANGELOG.md index b96c0d2..511ebb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Unreleased +## [0.13] - 2023-02-15 + ### Changed - Testing against Wagtail 4.2 ([#193](https://github.com/torchbox/wagtailmedia/pull/193)) by @katdom13 @@ -216,6 +218,7 @@ Initial release --- +[0.13.0]: https://github.com/torchbox/wagtailmedia/releases/tag/v0.13.0 [0.12.0]: https://github.com/torchbox/wagtailmedia/releases/tag/v0.12.0 [0.11.1]: https://github.com/torchbox/wagtailmedia/releases/tag/v0.11.1 [0.11.0]: https://github.com/torchbox/wagtailmedia/releases/tag/v0.11.0 diff --git a/manage.py b/manage.py index 5db5547..d3a9f05 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os import sys diff --git a/pyproject.toml b/pyproject.toml index fd4ee88..b619661 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] line_length = 88 -target-version = ['py38'] +target-version = ['py311'] exclude = ''' ( /( diff --git a/setup.py b/setup.py index 61a525b..e7dfd76 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -import io - from setuptools import find_packages, setup from src.wagtailmedia import __version__ @@ -10,12 +8,11 @@ # Testing dependencies testing_extras = [ # Required for running the tests - "mock>=1.0.0", "coverage>=7.0,<8.0", "tox>=4.0,<5.0", ] -with io.open("README.md", encoding="utf-8") as readme_file: +with open("README.md", encoding="utf-8") as readme_file: long_description = readme_file.read() setup( diff --git a/src/wagtailmedia/__init__.py b/src/wagtailmedia/__init__.py index ea370a8..f23a6b3 100644 --- a/src/wagtailmedia/__init__.py +++ b/src/wagtailmedia/__init__.py @@ -1 +1 @@ -__version__ = "0.12.0" +__version__ = "0.13.0" diff --git a/src/wagtailmedia/blocks.py b/src/wagtailmedia/blocks.py index 183ffd5..79f86df 100644 --- a/src/wagtailmedia/blocks.py +++ b/src/wagtailmedia/blocks.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from typing import TYPE_CHECKING, Type from django.forms import ModelChoiceField diff --git a/src/wagtailmedia/edit_handlers.py b/src/wagtailmedia/edit_handlers.py index 19735c2..fd834b0 100644 --- a/src/wagtailmedia/edit_handlers.py +++ b/src/wagtailmedia/edit_handlers.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, annotations, unicode_literals +from __future__ import annotations from typing import TYPE_CHECKING diff --git a/src/wagtailmedia/forms.py b/src/wagtailmedia/forms.py index 34c2c6d..b656cc5 100644 --- a/src/wagtailmedia/forms.py +++ b/src/wagtailmedia/forms.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django import forms from django.forms.models import modelform_factory from django.utils.module_loading import import_string @@ -43,7 +41,7 @@ class Meta: permission_policy = media_permission_policy def __init__(self, *args, **kwargs): - super(BaseMediaForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) if self.instance.type == "audio": for name in ("width", "height"): diff --git a/src/wagtailmedia/migrations/0001_initial.py b/src/wagtailmedia/migrations/0001_initial.py index c1364e0..2c4e4d1 100644 --- a/src/wagtailmedia/migrations/0001_initial.py +++ b/src/wagtailmedia/migrations/0001_initial.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- # Generated by Django 1.9.5 on 2016-04-20 12:32 -from __future__ import unicode_literals from django.conf import settings from django.db import migrations, models @@ -13,7 +11,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ diff --git a/src/wagtailmedia/migrations/0002_initial_data.py b/src/wagtailmedia/migrations/0002_initial_data.py index d5ee78c..62b9276 100644 --- a/src/wagtailmedia/migrations/0002_initial_data.py +++ b/src/wagtailmedia/migrations/0002_initial_data.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django import VERSION as DJANGO_VERSION from django.db import migrations @@ -56,7 +53,6 @@ def remove_media_permissions(apps, schema_editor): class Migration(migrations.Migration): - dependencies = [ ("wagtailmedia", "0001_initial"), # Need to run wagtailcores initial data migration to make sure the groups are created diff --git a/src/wagtailmedia/migrations/0003_copy_media_permissions_to_collections.py b/src/wagtailmedia/migrations/0003_copy_media_permissions_to_collections.py index ad90f58..b56f892 100644 --- a/src/wagtailmedia/migrations/0003_copy_media_permissions_to_collections.py +++ b/src/wagtailmedia/migrations/0003_copy_media_permissions_to_collections.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - from django.db import migrations @@ -40,7 +37,6 @@ def remove_media_permissions_from_collections(apps, schema_editor): class Migration(migrations.Migration): - dependencies = [ ("wagtailmedia", "0002_initial_data"), ("wagtailcore", "0026_group_collection_permission"), diff --git a/src/wagtailmedia/migrations/0004_duration_optional_floatfield.py b/src/wagtailmedia/migrations/0004_duration_optional_floatfield.py index 3de628d..70cf55a 100644 --- a/src/wagtailmedia/migrations/0004_duration_optional_floatfield.py +++ b/src/wagtailmedia/migrations/0004_duration_optional_floatfield.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [ ("wagtailmedia", "0003_copy_media_permissions_to_collections"), ] diff --git a/src/wagtailmedia/models.py b/src/wagtailmedia/models.py index d257979..abfe5f6 100644 --- a/src/wagtailmedia/models.py +++ b/src/wagtailmedia/models.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import mimetypes import os.path diff --git a/src/wagtailmedia/settings.py b/src/wagtailmedia/settings.py index 840603c..59c2415 100644 --- a/src/wagtailmedia/settings.py +++ b/src/wagtailmedia/settings.py @@ -90,6 +90,7 @@ def __check_user_settings(self, user_settings): f"The '{setting}' setting is deprecated and will be removed in the next release, " f'use WAGTAILMEDIA["{new_setting}"] instead.', category=category, + stacklevel=2, ) user_settings[new_setting] = user_settings[setting] for setting in REMOVED_SETTINGS: diff --git a/src/wagtailmedia/views/media.py b/src/wagtailmedia/views/media.py index fd5c1dd..b8e1311 100644 --- a/src/wagtailmedia/views/media.py +++ b/src/wagtailmedia/views/media.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.core.paginator import Paginator from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse diff --git a/src/wagtailmedia/wagtail_hooks.py b/src/wagtailmedia/wagtail_hooks.py index a4e9bac..0869f15 100644 --- a/src/wagtailmedia/wagtail_hooks.py +++ b/src/wagtailmedia/wagtail_hooks.py @@ -1,5 +1,4 @@ -from django.conf.urls import include -from django.urls import path, reverse +from django.urls import include, path, reverse from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ from django.utils.translation import ngettext diff --git a/src/wagtailmedia/widgets.py b/src/wagtailmedia/widgets.py index 7e17b7f..85f3228 100644 --- a/src/wagtailmedia/widgets.py +++ b/src/wagtailmedia/widgets.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, unicode_literals - import json from django import forms @@ -62,7 +60,7 @@ def render_html(self, name, value, attrs): ) def render_js_init(self, id_, name, value): - return "createMediaChooser({0});".format(json.dumps(id_)) + return f"createMediaChooser({json.dumps(id_)});" @property def media(self): diff --git a/tests/test_models.py b/tests/test_models.py index d531a02..11d7786 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.core.exceptions import ValidationError from django.core.files import File from django.core.files.base import ContentFile @@ -259,7 +257,7 @@ class TestMediaModel(TestCase): def test_media_model(self): cls = get_media_model() self.assertEqual( - "%s.%s" % (cls._meta.app_label, cls.__name__), + "{}.{}".format(cls._meta.app_label, cls.__name__), "wagtailmedia_tests.CustomMedia", ) diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 4874239..55d3dc3 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.core.files.base import ContentFile diff --git a/tests/test_settings.py b/tests/test_settings.py index 4ae9d0f..4b424a8 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,6 @@ -from django.test import TestCase, override_settings +from unittest import mock -import mock +from django.test import TestCase, override_settings from wagtailmedia.settings import WagtailMediaSettings, wagtailmedia_settings diff --git a/tests/test_views.py b/tests/test_views.py index 93ffb0b..4e376ea 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import json import os @@ -148,7 +146,7 @@ def test_get_audio(self): self.assertNotContains(response, "Add audio or video") self.assertContains( response, - '
'.format( + ''.format( reverse("wagtailmedia:add", args=("audio",)) ), count=1, @@ -162,7 +160,7 @@ def test_get_video(self): self.assertNotContains(response, "Add audio or video") self.assertContains( response, - ''.format( + ''.format( reverse("wagtailmedia:add", args=("video",)) ), count=1, @@ -196,7 +194,7 @@ def test_get_audio_with_collections(self): self.assertContains(response, "Add audio") self.assertContains( response, - ''.format( + ''.format( reverse("wagtailmedia:add", args=("audio",)) ), count=1, @@ -215,7 +213,7 @@ def test_get_video_with_collections(self): self.assertContains(response, "Add video") self.assertContains( response, - ''.format( + ''.format( reverse("wagtailmedia:add", args=("video",)) ), count=1, @@ -375,7 +373,7 @@ def test_get_audio(self): self.assertContains(response, "Add audio") self.assertContains( response, - ''.format( + ''.format( reverse("wagtailmedia:add", args=("audio",)) ), count=1, @@ -392,7 +390,7 @@ def test_get_video(self): self.assertContains(response, "Add video") self.assertContains( response, - ''.format( + ''.format( reverse("wagtailmedia:add", args=("video",)) ), count=1, @@ -746,8 +744,6 @@ def setUpTestData(cls): ) video.save() - cls.tab_prefix = "tab-" - def setUp(self): self.user = self.login() diff --git a/tests/testapp/migrations/0001_initial.py b/tests/testapp/migrations/0001_initial.py index 272baa8..e9d7710 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/tests/testapp/migrations/0001_initial.py @@ -1,25 +1,28 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.5 on 2016-04-22 14:21 -from __future__ import unicode_literals - -import django.core.validators +# Generated by Django 4.1.4 on 2023-02-15 17:47 from django.conf import settings +import django.core.validators from django.db import migrations, models import django.db.models.deletion import modelcluster.fields import taggit.managers - -from wagtail import fields, models as wagtail_models - +import tests.testapp.models +import wagtail.blocks +import wagtail.fields +import wagtail.models.collections import wagtail.search.index +import wagtailmedia.blocks class Migration(migrations.Migration): - initial = True - dependencies = [("wagtailmedia", "0001_initial"), ("wagtailcore", "0028_merge")] + dependencies = [ + ("wagtailcore", "0078_referenceindex"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("wagtailmedia", "0004_duration_optional_floatfield"), + ("taggit", "0005_auto_20220424_2025"), + ] operations = [ migrations.CreateModel( @@ -33,7 +36,7 @@ class Migration(migrations.Migration): parent_link=True, primary_key=True, serialize=False, - to="wagtailcore.Page", + to="wagtailcore.page", ), ), ("date_from", models.DateField(null=True, verbose_name="Start date")), @@ -55,11 +58,13 @@ class Migration(migrations.Migration): models.TimeField(blank=True, null=True, verbose_name="End time"), ), ("location", models.CharField(max_length=255)), - ("body", fields.RichTextField(blank=True)), + ("body", wagtail.fields.RichTextField(blank=True)), ("cost", models.CharField(max_length=255)), ("signup_link", models.URLField(blank=True)), ], - options={"abstract": False}, + options={ + "abstract": False, + }, bases=("wagtailcore.page",), ), migrations.CreateModel( @@ -86,7 +91,7 @@ class Migration(migrations.Migration): null=True, on_delete=django.db.models.deletion.CASCADE, related_name="+", - to="wagtailmedia.Media", + to="wagtailmedia.media", ), ), ( @@ -94,11 +99,14 @@ class Migration(migrations.Migration): modelcluster.fields.ParentalKey( on_delete=django.db.models.deletion.CASCADE, related_name="related_media", - to="wagtailmedia_tests.EventPage", + to="wagtailmedia_tests.eventpage", ), ), ], - options={"ordering": ["sort_order"], "abstract": False}, + options={ + "ordering": ["sort_order"], + "abstract": False, + }, ), migrations.CreateModel( name="CustomMedia", @@ -155,13 +163,14 @@ class Migration(migrations.Migration): "created_at", models.DateTimeField(auto_now_add=True, verbose_name="created at"), ), + ("fancy_caption", wagtail.fields.RichTextField(blank=True)), ( "collection", models.ForeignKey( - default=wagtail_models.get_root_collection_id, + default=wagtail.models.collections.get_root_collection_id, on_delete=django.db.models.deletion.CASCADE, related_name="+", - to="wagtailcore.Collection", + to="wagtailcore.collection", verbose_name="collection", ), ), @@ -186,9 +195,68 @@ class Migration(migrations.Migration): verbose_name="uploaded by user", ), ), - ("fancy_caption", fields.RichTextField(blank=True)), ], - options={"verbose_name": "media", "abstract": False}, + options={ + "verbose_name": "media", + "abstract": False, + }, bases=(wagtail.search.index.Indexed, models.Model), ), + migrations.CreateModel( + name="BlogStreamPage", + fields=[ + ( + "page_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="wagtailcore.page", + ), + ), + ("author", models.CharField(max_length=255)), + ("date", models.DateField(verbose_name="Post date")), + ( + "body", + wagtail.fields.StreamField( + [ + ( + "heading", + wagtail.blocks.CharBlock( + form_classname="title", icon="title" + ), + ), + ("paragraph", wagtail.blocks.RichTextBlock(icon="pilcrow")), + ( + "media", + tests.testapp.models.TestMediaBlock(icon="media"), + ), + ( + "video", + wagtailmedia.blocks.VideoChooserBlock(icon="media"), + ), + ( + "audio", + wagtailmedia.blocks.AudioChooserBlock(icon="media"), + ), + ], + use_json_field=True, + ), + ), + ( + "featured_media", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailmedia.media", + ), + ), + ], + options={ + "abstract": False, + }, + bases=("wagtailcore.page",), + ), ] diff --git a/tests/testapp/migrations/0002_blogstreampage.py b/tests/testapp/migrations/0002_blogstreampage.py deleted file mode 100644 index 654ac08..0000000 --- a/tests/testapp/migrations/0002_blogstreampage.py +++ /dev/null @@ -1,79 +0,0 @@ -# Generated by Django 3.2.6 on 2021-09-01 22:45 - -from django.db import migrations, models -import django.db.models.deletion -import tests.testapp.models - -from wagtail import blocks, fields - -import wagtailmedia.blocks - - -class Migration(migrations.Migration): - - dependencies = [ - ("wagtailcore", "0059_apply_collection_ordering"), - ("wagtailmedia", "0004_duration_optional_floatfield"), - ("wagtailmedia_tests", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="BlogStreamPage", - fields=[ - ( - "page_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="wagtailcore.page", - ), - ), - ("author", models.CharField(max_length=255)), - ("date", models.DateField(verbose_name="Post date")), - ( - "body", - fields.StreamField( - [ - ( - "heading", - blocks.CharBlock(form_classname="title", icon="title"), - ), - ( - "paragraph", - blocks.RichTextBlock(icon="pilcrow"), - ), - ( - "media", - tests.testapp.models.TestMediaBlock(icon="media"), - ), - ( - "video", - wagtailmedia.blocks.VideoChooserBlock(icon="media"), - ), - ( - "audio", - wagtailmedia.blocks.AudioChooserBlock(icon="media"), - ), - ], - use_json_field=True, - ), - ), - ( - "featured_media", - models.ForeignKey( - on_delete=django.db.models.deletion.PROTECT, - related_name="+", - to="wagtailmedia.media", - ), - ), - ], - options={ - "abstract": False, - }, - bases=("wagtailcore.page",), - ), - ] diff --git a/tests/testapp/migrations/0003_alter_blogstreampage_body.py b/tests/testapp/migrations/0003_alter_blogstreampage_body.py deleted file mode 100644 index 5a2ddd3..0000000 --- a/tests/testapp/migrations/0003_alter_blogstreampage_body.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 4.1.4 on 2022-12-27 10:19 - -from django.db import migrations -import tests.testapp.models -import wagtail.blocks -import wagtail.fields -import wagtailmedia.blocks - - -class Migration(migrations.Migration): - - dependencies = [ - ("wagtailmedia_tests", "0002_blogstreampage"), - ] - - operations = [ - migrations.AlterField( - model_name="blogstreampage", - name="body", - field=wagtail.fields.StreamField( - [ - ( - "heading", - wagtail.blocks.CharBlock(form_classname="title", icon="title"), - ), - ("paragraph", wagtail.blocks.RichTextBlock(icon="pilcrow")), - ("media", tests.testapp.models.TestMediaBlock(icon="media")), - ("video", wagtailmedia.blocks.VideoChooserBlock(icon="media")), - ("audio", wagtailmedia.blocks.AudioChooserBlock(icon="media")), - ], - use_json_field=True, - ), - ), - ] diff --git a/tests/urls.py b/tests/urls.py index 489f771..aa643bf 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,6 +1,5 @@ from django.conf import settings -from django.conf.urls import include -from django.urls import path +from django.urls import include, path from django.views.static import serve from wagtail import urls as wagtail_urls