Skip to content

Commit a10e6a4

Browse files
authored
Prep for Wagtail 7.0 (#257)
* Update min versions and add Wagtail 7.0 to the test matrix * Use SPDX license expression https://peps.python.org/pep-0639/ https://hugovk.dev/blog/2025/improving-licence-metadata/ * Tidy up tests setup * Use the non-deprecated/removed pagination template `wagtailadmin/shared/ajax_pagination_nav.html` was soft deprecated since Wagtail 2.16 and was removed in 7.0
1 parent 00ef044 commit a10e6a4

File tree

23 files changed

+172
-116
lines changed

23 files changed

+172
-116
lines changed

.github/workflows/nightly-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
id: test
4141
continue-on-error: true
4242
run: |
43-
./runtests.py
43+
cd tests
44+
python manage.py test
4445
env:
4546
DATABASE_ENGINE: django.db.backends.postgresql
4647
DATABASE_HOST: localhost

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919
PIP_DISABLE_PIP_VERSION_CHECK: "1"
2020
PIP_NO_PYTHON_VERSION_WARNING: "1"
2121
# Keep in sync with .pre-commit-config.yaml/default_language_version/python.
22-
PYTHON_LATEST: "3.12" # because harden runner fails on the 3.13 download
22+
PYTHON_LATEST: "3.13" # because harden runner fails on the 3.13 download
2323

2424
jobs:
2525
tests:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ but for audio and video files.
1414
wagtailmedia requires the following:
1515

1616
- Python (3.9, 3.10, 3.11, 3.12, 3.13)
17-
- Django (4.2, 5.0, 5.1)
18-
- Wagtail (5.2, 6.2, 6.3)
17+
- Django (4.2, 5.1, 5.2)
18+
- Wagtail (6.3, 6.4, 7.0)
1919

2020
## Install
2121

@@ -361,7 +361,7 @@ Now you can run tests as shown below:
361361
tox
362362
```
363363

364-
or, you can run them for a specific environment `tox -e py310-dj41-wagtail41` or specific test
365-
`tox -e py310-dj41-wagtail41 -- tests.test_views.TestMediaChooserUploadView`
364+
or, you can run them for a specific environment `tox -e py313-dj51-wagtail70` or specific test
365+
`tox -e py313-dj51-wagtail70 -- tests.test_views.TestMediaChooserUploadView`
366366

367367
To run the test app interactively, use `tox -e interactive`, visit `http://127.0.0.1:8020/admin/` and log in with `admin`/`changeme`.

manage.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

pyproject.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ description = "A Wagtail module for audio and video files."
44
authors = [{name = "Mikalai Radchuk ", email = "[email protected]"}]
55
maintainers = [{name = "Dan Braghis", email="[email protected]"}]
66
readme = "README.md"
7-
license = {file = "LICENSE"}
7+
license = "BSD-3-Clause"
8+
license-files = [ "LICENSE" ]
89
keywords = ["Wagtail", "Django", "media"]
910
classifiers = [
1011
"Development Status :: 4 - Beta",
1112
"Environment :: Web Environment",
1213
"Intended Audience :: Developers",
1314
"Operating System :: OS Independent",
14-
"License :: OSI Approved :: BSD License",
1515
"Programming Language :: Python",
1616
"Programming Language :: Python :: 3",
1717
"Programming Language :: Python :: 3.9",
@@ -20,23 +20,23 @@ classifiers = [
2020
"Programming Language :: Python :: 3.12",
2121
"Programming Language :: Python :: 3.13",
2222
"Framework :: Wagtail",
23-
"Framework :: Wagtail :: 5",
2423
"Framework :: Wagtail :: 6",
24+
"Framework :: Wagtail :: 7",
2525
]
2626

2727
dynamic = ["version"]
2828
requires-python = ">=3.9"
2929
dependencies = [
30-
"Wagtail>=5.2",
30+
"Wagtail>=6.3",
3131
"Django>=4.2",
3232
]
3333

3434
[project.optional-dependencies]
3535
testing = [
36-
"coverage>=7.6.0",
36+
"coverage>=7.8.0",
3737
]
3838
linting = [
39-
"pre-commit>=5.0.0",
39+
"pre-commit>=4.2.0",
4040
]
4141

4242
[project.urls]
@@ -45,7 +45,7 @@ Changelog = "https://github.com/torchbox/wagtailmedia/blob/main/CHANGELOG.md"
4545
Issues = "https://github.com/torchbox/wagtailmedia/issues"
4646

4747
[build-system]
48-
requires = ["flit_core >=3.2,<4"]
48+
requires = ["flit_core >=3.11,<4"]
4949
build-backend = "flit_core.buildapi"
5050

5151
[tool.flit.module]
@@ -62,7 +62,5 @@ exclude = [
6262
"*.yml",
6363
"CHANGELOG.md",
6464
"SPECIFICATION.md",
65-
"manage.py",
66-
"runtests.py",
6765
"ruff.toml",
6866
]

runtests.py

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 5.2 on 2025-05-06 16:58
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("wagtailmedia", "0004_duration_optional_floatfield"),
9+
]
10+
11+
operations = [
12+
migrations.AlterModelOptions(
13+
name="media",
14+
options={"verbose_name": "media", "verbose_name_plural": "media items"},
15+
),
16+
]

src/wagtailmedia/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def clean(self, *args, **kwargs):
153153
class Meta:
154154
abstract = True
155155
verbose_name = _("media")
156+
verbose_name_plural = _("media items")
156157

157158

158159
class Media(AbstractMedia):

src/wagtailmedia/static/wagtailmedia/js/media-chooser-modal.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ MEDIA_CHOOSER_MODAL_ONLOAD_HANDLERS = {
2121

2222
$('.pagination a', context).on('click', function(e) {
2323
let params = {
24-
p: this.getAttribute("data-page"),
2524
collection_id: collectionChooser.val()
2625
};
26+
27+
if (this.hasAttribute("data-page")) {
28+
params['p'] = this.getAttribute("data-page");
29+
}
30+
else if (this.parentElement.classList.contains("prev") || this.parentElement.classList.contains("next")) {
31+
const href = new URL(this.href);
32+
params = Object.fromEntries(href.searchParams.entries());
33+
}
34+
2735
const query = searchInput.val();
2836
if (query.length) {
2937
params['q'] = query;

src/wagtailmedia/templates/wagtailmedia/chooser/results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h2>{% trans "Latest media" %}</h2>
1414

1515
{% include "wagtailmedia/media/list.html" with choosing=1 %}
1616

17-
{% include pagination_template with items=media_files is_ajax=1 %}
17+
{% include pagination_template with items=media_files link_url=link_url %}
1818
{% else %}
1919
{% if is_searching %}
2020
<p>{% blocktrans %}Sorry, no media files match "<em>{{ query_string }}</em>"{% endblocktrans %}</p>

src/wagtailmedia/utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
from typing import TYPE_CHECKING
44

5-
from django.core.paginator import Paginator
65
from django.forms.utils import flatatt
76
from django.utils.html import format_html, format_html_join
87
from django.utils.translation import gettext_lazy as _
98

109

10+
try:
11+
from wagtail.admin.paginator import WagtailPaginator as Paginator
12+
except ImportError:
13+
from django.core.paginator import Paginator
14+
15+
1116
if TYPE_CHECKING:
17+
from django.core.paginator import Page as PaginatorPage
18+
from django.http import HttpRequest
19+
1220
from .models import AbstractMedia
1321

14-
DEFAULT_PAGE_KEY = "p"
22+
DEFAULT_PAGE_KEY: str = "p"
1523

1624

17-
def paginate(request, items, page_key=DEFAULT_PAGE_KEY, per_page=20):
25+
def paginate(
26+
request: HttpRequest, items, page_key: str = DEFAULT_PAGE_KEY, per_page: int = 20
27+
) -> tuple[Paginator, PaginatorPage]:
1828
paginator = Paginator(items, per_page)
1929
page = paginator.get_page(request.GET.get(page_key))
2030
return paginator, page

src/wagtailmedia/views/chooser.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from wagtailmedia.utils import paginate
1616

1717

18-
pagination_template = "wagtailadmin/shared/ajax_pagination_nav.html"
18+
pagination_template = "wagtailadmin/shared/pagination_nav.html"
1919
permission_checker = PermissionPolicyChecker(permission_policy)
2020

2121

@@ -100,7 +100,7 @@ def chooser(request, media_type=None):
100100
media_files = media_files.filter(tags__name=tag_name)
101101

102102
# Pagination
103-
paginator, media_files = paginate(request, media_files, per_page=10)
103+
paginator, media_files = paginate(request, media_files)
104104

105105
return render(
106106
request,
@@ -112,6 +112,10 @@ def chooser(request, media_type=None):
112112
"pagination_template": pagination_template,
113113
"media_type": media_type,
114114
"ordering": ordering,
115+
"linkurl": reverse("wagtailmedia:chooser"),
116+
"elided_page_range": paginator.get_elided_page_range(
117+
request.GET.get("p", 1)
118+
),
115119
},
116120
)
117121
else:
@@ -122,7 +126,7 @@ def chooser(request, media_type=None):
122126
collections = None
123127

124128
media_files = media_files.order_by(ordering)
125-
paginator, media_files = paginate(request, media_files, per_page=10)
129+
paginator, media_files = paginate(request, media_files)
126130

127131
if media_type == "audio":
128132
title = _("Choose audio")
@@ -147,6 +151,10 @@ def chooser(request, media_type=None):
147151
"ordering": ordering,
148152
"title": title,
149153
"icon": f"wagtailmedia-{media_type}" if media_type is not None else "media",
154+
"linkurl": reverse("wagtailmedia:chooser"),
155+
"elided_page_range": paginator.get_elided_page_range(
156+
request.GET.get("p", 1)
157+
),
150158
},
151159
json_data={
152160
"step": "chooser",

tests/manage.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
import shutil
6+
import sys
7+
import warnings
8+
9+
from django.core.management import execute_from_command_line
10+
11+
12+
os.environ["DJANGO_SETTINGS_MODULE"] = "testapp.settings"
13+
sys.path.append("tests")
14+
15+
16+
def make_parser():
17+
parser = argparse.ArgumentParser()
18+
parser.add_argument(
19+
"--deprecation",
20+
choices=["all", "pending", "imminent", "none"],
21+
default="imminent",
22+
)
23+
return parser
24+
25+
26+
def parse_args(args=None):
27+
return make_parser().parse_known_args(args)
28+
29+
30+
def runtests():
31+
args, rest = parse_args()
32+
33+
only_wagtail = r"^wagtail(\.|$)"
34+
if args.deprecation == "all":
35+
# Show all deprecation warnings from all packages
36+
warnings.simplefilter("default", DeprecationWarning)
37+
warnings.simplefilter("default", PendingDeprecationWarning)
38+
elif args.deprecation == "pending":
39+
# Show all deprecation warnings from wagtail
40+
warnings.filterwarnings(
41+
"default", category=DeprecationWarning, module=only_wagtail
42+
)
43+
warnings.filterwarnings(
44+
"default", category=PendingDeprecationWarning, module=only_wagtail
45+
)
46+
elif args.deprecation == "imminent":
47+
# Show only imminent deprecation warnings from wagtail
48+
warnings.filterwarnings(
49+
"default", category=DeprecationWarning, module=only_wagtail
50+
)
51+
elif args.deprecation == "none":
52+
# Deprecation warnings are ignored by default
53+
pass
54+
55+
argv = [sys.argv[0]] + rest
56+
57+
try:
58+
execute_from_command_line(argv)
59+
finally:
60+
from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT
61+
62+
shutil.rmtree(STATIC_ROOT, ignore_errors=True)
63+
shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
64+
65+
66+
if __name__ == "__main__":
67+
runtests()

tests/test_compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.test import TestCase
22
from django.utils.safestring import SafeString
3+
from testapp.models import BlogStreamPage
34

4-
from tests.testapp.models import BlogStreamPage
55
from wagtailmedia.blocks import (
66
AudioChooserBlock,
77
MediaChooserBlockComparison,

tests/test_edit_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from django.contrib.auth.models import AnonymousUser
22
from django.test import RequestFactory, TestCase
33
from django.urls import reverse
4+
from testapp.models import BlogStreamPage
45
from wagtail import VERSION as WAGTAIL_VERSION
56
from wagtail.admin.panels import FieldPanel, ObjectList
67
from wagtail.models import Page
78

8-
from tests.testapp.models import BlogStreamPage
99
from wagtailmedia.edit_handlers import MediaChooserPanel, MediaFieldComparison
1010
from wagtailmedia.widgets import AdminAudioChooser, AdminMediaChooser, AdminVideoChooser
1111

0 commit comments

Comments
 (0)