Skip to content

Commit

Permalink
Prep for Wagtail 6.0 (#232)
Browse files Browse the repository at this point in the history
* Fix summary item context and template class
* Update tox matrix and tidy up config
  - drop Wagtail 5.1
  - add Wagtail 6.0rc1
  - adds base_python
  - constrains package deps to ensure it runs with the correct Django/Wagtail version
* Add the Wagtail 6 PyPI classifier
* Fix test for Wagtail 4.1
  • Loading branch information
zerolab authored Feb 5, 2024
1 parent f3fd3f0 commit 5bdedce
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
]

dynamic = ["version"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{% icon name="media" %}
<a href="{% url 'wagtailmedia:index' %}">
{% blocktrans trimmed count counter=total_media with total_media|intcomma as total %}
<span>{{ total }}</span> Media file <span class="visuallyhidden">created in {{ site_name }}</span>
<span>{{ total }}</span> Media file <span class="visuallyhidden w-sr-only">created in {{ site_name }}</span>
{% plural %}
<span>{{ total }}</span> Media files <span class="visuallyhidden">created in {{ site_name }}</span>
<span>{{ total }}</span> Media files <span class="visuallyhidden w-sr-only">created in {{ site_name }}</span>
{% endblocktrans %}
</a>
</li>
11 changes: 8 additions & 3 deletions src/wagtailmedia/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
register_admin_url_finder,
)
from wagtail.admin.menu import MenuItem
from wagtail.admin.navigation import get_site_for_user
from wagtail.admin.search import SearchArea
from wagtail.admin.site_summary import SummaryItem
from wagtail.admin.staticfiles import versioned_static
Expand Down Expand Up @@ -48,9 +49,13 @@ class MediaSummaryItem(SummaryItem):
template_name = "wagtailmedia/homepage/site_summary_media.html"

def get_context_data(self, parent_context):
context = super().get_context_data(parent_context)
context["total_media"] = get_media_model().objects.count()
return context
site_name = get_site_for_user(self.request.user)["site_name"]
return {
"total_media": permission_policy.instances_user_has_any_permission_for(
self.request.user, {"add", "change", "delete", "choose"}
).count(),
"site_name": site_name,
}

def is_shown(self):
return permission_policy.user_has_any_permission(
Expand Down
17 changes: 13 additions & 4 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ def test_media_field_in_admin(self):
args=("wagtailmedia_tests", "eventpage", self.root_page.id),
)
)
self.assertContains(
response,
'<script>createMediaChooser("id_related_media-__prefix__-link_media");</script>',
)

from wagtail import VERSION as WAGTAIL_VERSION

if WAGTAIL_VERSION >= (4, 2):
self.assertContains(
response,
'<script>createMediaChooser("id_related_media-__prefix__-link_media");</script>',
)
else:
self.assertContains(
response,
'<script>createMediaChooser("id_related_media-__prefix__-link_media");<-/script>',
)
self.assertContains(response, "media-chooser.js")

def test_media_block_in_admin(self):
Expand Down
30 changes: 19 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
[tox]
min_version = 4.11

envlist =
py{38,39,310}-dj{32,41}-wagtail{41,51,52}
py{311}-dj{41,42}-wagtail{51,52}
py{312}-dj{42}-wagtail{52}
env_list =
py{38,39,310}-dj{32}-wagtail{41,52}
py{311}-dj{41,42}-wagtail{52,60}
py{312}-dj{42,50}-wagtail{52,60}

base_python =
py38: python3.8
py39: python3.8

This comment has been minimized.

Copy link
@jsma

jsma Feb 5, 2024

Contributor

py39: python3.8 => python3.9

This comment has been minimized.

Copy link
@zerolab

zerolab Feb 5, 2024

Author Member

gah, thanks!
4683a6d

py310: python3.10
py311: python3.11
py312: python3.12

[gh-actions]
python =
Expand All @@ -17,6 +24,8 @@ python =
[testenv]
package = wheel
wheel_build_env = .pkg
use_frozen_constraints = true
constrain_package_deps = true

pass_env =
FORCE_COLOR
Expand All @@ -30,23 +39,22 @@ setenv =
deps =
coverage[toml]>=7.0,<8.0
dj32: Django>=3.2,<3.3
dj41: Django>=4.1,<4.2
dj42: Django>=4.2,<5.0
dj50: Django>=5.0,<5.1
wagtail41: wagtail>=4.1,<4.2
wagtail51: wagtail>=5.1,<5.2
wagtail52: wagtail>=5.2,<5.3
wagtail52: wagtail>=5.2,<6.0
wagtail60: wagtail>=6.0rc1,<6.1

install_command = python -Im pip install -U {opts} {packages}
install_command = python -Im pip install --upgrade {opts} {packages}

commands =
python -Im coverage run runtests.py {posargs: -v 2}

[testenv:coverage-report]
base_python = python3.11
; a bit of a hack - we want to keep deps to a minimum here
package = skip
deps =
extras =
install_command = python -Im pip install -U "coverage[toml]>=7.0,<8.0"
coverage[toml]>=7.0,<8.0
commands =
python -Im coverage combine
python -Im coverage report -m
Expand Down

0 comments on commit 5bdedce

Please sign in to comment.