Skip to content

Commit

Permalink
Add official Wagtail 6.2 support (wagtail#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix authored Aug 22, 2024
1 parent f5690d0 commit 9741735
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
python: ['3.9', '3.10', '3.11', '3.12']
database: ['postgres']

services:
Expand Down Expand Up @@ -110,6 +110,6 @@ jobs:
run: |
coverage run testmanage.py test
- name: 'Upload coverage to Codecov'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for Wagtail 6.1 ([#797](https://github.com/wagtail/wagtail-localize/pull/797)) & 6.2 ([#813](https://github.com/wagtail/wagtail-localize/pull/813))

### Removed

- Support for Django < 4.2 ([#797](https://github.com/wagtail/wagtail-localize/pull/797))
- Support for Python < 3.9 ([#813](https://github.com/wagtail/wagtail-localize/pull/813))

## [1.9] - 2024-04-03

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ We'll be at Wagtail Space US this year! The Call for Participation and Registrat

Wagtail Localize requires the following:

- Python (3.8, 3.9, 3.10, 3.11)
- Django (3.2, 4.2, 5.0)
- Wagtail (5.2, 6.0) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration)
- Python (3.9, 3.10, 3.11)
- Django (4.2, 5.0, 5.1)
- Wagtail (5.2, 6.1) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration)
- [wagtail-modeladmin](https://pypi.org/project/wagtail-modeladmin/) if `using wagtail_localize.modeladmin` and Wagtail >= 5.2

## Installation
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/modeladmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ INSTALLED_APPS = [
When registering your custom models you can use the supplied `TranslatableModelAdmin` in place of Wagtail's `ModelAdmin` class.

```python
from wagtail.contrib.modeladmin.options import modeladmin_register
from wagtail_localize.modeladmin.options import TranslatableModelAdmin
from wagtail_modeladmin.options import modeladmin_register

from .models import MyTranslatableModel

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ classifiers = [
"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",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5"
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6"
]
dynamic = ["version"]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"Django>=3.2,<5.1",
"Django>=4.2,<6.0",
"Wagtail>=5.2",
"polib>=1.1,<2.0",
"typing_extensions>=4.0"
Expand Down
23 changes: 12 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
min_version = 4.0

envlist =
python3.10-django3.2-wagtail5.2-postgres15
python{3.8,3.9,3.10,3.11,3.12}-django{4.2}-wagtail{5.2,6.0}-postgres15
python{3.10,3.11,3.12}-django{5.0}-wagtail{5.2,6.0}-postgres15
python{3.9,3.10,3.11,3.12}-django4.2-wagtail{5.2,6.1,6.2}-postgres15
python{3.10,3.11,3.12}-django5.0-wagtail{5.2,6.1,6.2}-postgres15
python{3.12}-django5.1-wagtail{6.2}-postgres15
# note: we're running a subset of the test with sqlite
python3.10-django3.2-wagtail5.2-sqlite
python3.11-django4.2-wagtail{5.2,6.0}-sqlite
python3.12-django5.0-wagtail{5.2,6.0}-sqlite
python3.11-django4.2-wagtail{5.2,6.1,6.2}-sqlite
python3.12-django5.0-wagtail{5.2,6.1,6.2}-sqlite
python3.12-django5.1-wagtail{6.2}-sqlite

[gh-actions]
python =
3.8: python3.8
3.9: python3.9
3.10: python3.10
3.11: python3.11
Expand All @@ -39,12 +38,13 @@ setenv =
extras = testing

deps =
django3.2: Django>=3.2,<3.3
django4.2: Django>=4.2,<5.0
django5.0: Django>=5.0,<5.1
django5.1: Django>=5.1,<5.2

wagtail5.2: wagtail>=5.2.2,<5.3
wagtail6.0: wagtail>=6.0,<6.1
wagtail6.1: wagtail>=6.1,<6.2
wagtail6.2: wagtail>=6.2,<6.3
wagtailmain: git+https://github.com/wagtail/wagtail.git

postgres: psycopg2>=2.9
Expand Down Expand Up @@ -75,7 +75,8 @@ commands =
description = An interactive environment for local testing purposes
basepython = python3.11
deps =
wagtail>=5.2,<6.0
wagtail>=5.2,<6.3
Django>=4.2,<5.2

commands_pre =
python {toxinidir}/testmanage.py makemigrations
Expand All @@ -94,7 +95,7 @@ basepython = python3.11

# always generate with the min supported versions
deps =
Django>=3.2,<3.3
Django>=4.2,<5.0
wagtail>=5.2,<6.0

commands =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{% extends "wagtailadmin/generic/confirm_delete.html" %}
{% load i18n %}

{% block content %}
{% include "wagtailadmin/shared/header.html" with title=view.page_title subtitle=view.get_page_subtitle icon=view.header_icon %}

<div class="nice-padding">
{% if can_delete %}
<p>{{ view.confirmation_message }}</p>

<form action="{{ view.get_delete_url }}" method="POST">
{% csrf_token %}
<input type="submit" value="{% trans 'Yes, delete' %}" class="button serious" />
<a href="{% url 'wagtaillocales:edit' locale.id %}" class="button button-secondary">{% trans "Back" %}</a>
</form>
{% else %}
<p>{{ view.cannot_delete_message }}</p>
{% block main_content %}
{% if can_delete %}
<p>{{ view.confirmation_message }}</p>

<form action="{{ view.get_delete_url }}" method="POST">
{% csrf_token %}
<input type="submit" value="{% trans 'Yes, delete' %}" class="button serious" />
<a href="{% url 'wagtaillocales:edit' locale.id %}" class="button button-secondary">{% trans "Back" %}</a>
{% endif %}
</div>
</form>
{% else %}
<p>{{ view.cannot_delete_message }}</p>

<a href="{% url 'wagtaillocales:edit' locale.id %}" class="button button-secondary">{% trans "Back" %}</a>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends 'wagtailadmin/reports/base_report_results.html' %}
{% load i18n wagtailadmin_tags %}

{% block results %}
<table class="listing">
<thead>
<tr>
<th>
{% trans 'Content type' %}
</th>
<th>
{% trans 'Source' %}
</th>
<th>
{% trans 'Target' %}
</th>
<th>
{% trans 'Status' %}
</th>
</tr>
</thead>
<tbody>
{% for translation in object_list %}
<tr>
<td>
{{ translation.source.specific_content_type.name|capfirst }}
</td>
<td>
<a href="{{ translation.source.get_source_instance_edit_url }}">
{{ translation.source.object_repr }} ({{ translation.source.locale }})
</a>
</td>
<td>
{% with translation.get_target_instance as target_instance %}
<a href="{{ translation.get_target_instance_edit_url }}">
{{ target_instance.get_admin_display_title|default:target_instance }} ({{ translation.target_locale }})
</a>
{% endwith %}
</td>
<td>
{{ translation.get_status_display }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block no_results_message %}
<p>{% trans "No translations found." %}</p>
{% endblock %}
4 changes: 2 additions & 2 deletions wagtail_localize/tests/test_edit_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)
from rest_framework.settings import api_settings
from rest_framework.test import APITestCase
from wagtail.admin.panels import FieldPanel
from wagtail.admin.panels import FieldPanel, TitleFieldPanel
from wagtail.blocks import StreamValue
from wagtail.documents.models import Document
from wagtail.images.models import Image
Expand Down Expand Up @@ -1506,7 +1506,7 @@ def test_edit_page_translation_with_missing_panel(self):
# Hide fields that don't have a panel to edit them with
previous_panels = TestPage.content_panels
TestPage.content_panels = [
FieldPanel("title"),
TitleFieldPanel("title"),
FieldPanel("test_textfield"),
]
TestPage.get_edit_handler.cache_clear()
Expand Down
34 changes: 33 additions & 1 deletion wagtail_localize/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django_filters.constants import EMPTY_VALUES
from django_filters.fields import ModelChoiceField
from modelcluster.fields import ParentalKey
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin.filters import WagtailFilterSet
from wagtail.admin.views.reports import ReportView
from wagtail.coreutils import get_content_languages
Expand Down Expand Up @@ -135,9 +136,40 @@ class Meta:
fields = ["content_type", "source_title", "source_locale", "target_locale"]


def _adapt_wagtail_report_attributes(cls):
"""
A class decorator that adapts ReportView-derived classes for compatibility
with multiple versions of Wagtail by conditionally assigning attributes
based on the Wagtail version. This includes setting appropriate titles,
and adjusting template names and URL names for AJAX support since Wagtail 6.2.
Attributes adjusted:
- `title` or `page_title` based on Wagtail version for the display name of the report.
- For Wagtail 6.2 and above, additional attributes like `results_template_name`,
`index_results_url_name`, and `index_url_name` are set to support AJAX updates
and utilize the `wagtail.admin.ui.tables` framework.
"""
if WAGTAIL_VERSION < (6, 2):
cls.title = gettext_lazy("Translations")
else:
# The `title` attr was **changed** to `page_title` in Wagtail 6.2
cls.page_title = gettext_lazy("Translations")
# The `results_template_name` attr was **added** in Wagtail 6.2
# to support updating the listing via AJAX upon filtering and
# to allow the use of the `wagtail.admin.ui.tables` framework.
cls.results_template_name = (
"wagtail_localize/admin/translations_report_results.html"
)
# The `index_results_url_name` attr was **added** in Wagtail 6.2
# to support updating the listing via AJAX upon filtering.
cls.index_results_url_name = "wagtail_localize:translations_report_results"
cls.index_url_name = "wagtail_localize:translations_report"
return cls


@_adapt_wagtail_report_attributes
class TranslationsReportView(ReportView):
template_name = "wagtail_localize/admin/translations_report.html"
title = gettext_lazy("Translations")
header_icon = "site"

filterset_class = TranslationsReportFilterSet
Expand Down
11 changes: 11 additions & 0 deletions wagtail_localize/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy
from django.views.i18n import JavaScriptCatalog
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import hooks
from wagtail.admin.action_menu import ActionMenuItem as PageActionMenuItem
from wagtail.admin.menu import MenuItem
Expand Down Expand Up @@ -117,6 +118,16 @@ def register_admin_urls():
),
]

if WAGTAIL_VERSION >= (6, 2):
# Add a results-only view to add support for AJAX-based filtering
urls.append(
path(
"reports/translations/results/",
report.TranslationsReportView.as_view(results_only=True),
name="translations_report_results",
),
)

return [
path(
"localize/",
Expand Down

0 comments on commit 9741735

Please sign in to comment.