Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wagtail_localize/locales/templates/wagtaillocales/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
{% endfor %}
{% endblock %}

{% include "wagtailadmin/shared/non_field_errors.html" %}

<ul class="fields">
{% block visible_fields %}
{% for field in form.visible_fields %}
Expand Down
83 changes: 46 additions & 37 deletions wagtail_localize/locales/templates/wagtaillocales/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,54 @@

{% block listing %}
<div class="nice-padding">
<div id="locales-list">
<table class="listing">
<thead>
<tr>
<th class="hostname">
{% if ordering == "name" %}
<a href="{% url 'wagtaillocales:index' %}" class="icon icon-arrow-down-after teal">
{% trans "Language" %}
</a>
{% else %}
<a href="{% url 'wagtaillocales:index' %}?ordering=name" class="icon icon-arrow-down-after">
{% trans "Language" %}
</a>
{% endif %}
</th>
<th>{% trans "Usage" %}</th>
</tr>
</thead>
<tbody>
{% for locale in locales %}
{% if locales %}
<div id="locales-list">
<table class="listing">
<thead>
<tr>
<td class="hostname title">
<div class="title-wrapper">
<a href="{% url 'wagtaillocales:edit' locale.id %}">{{ locale }}</a>
{% if not locale.language_code_is_valid %}
{% trans "This locale's language code is not supported" as error %}
{% include "wagtaillocales/_icon.html" with error=error only %}
{% endif %}
</div>
</td>
<td>
{# TODO Make this translatable #}
{{ locale.num_pages }} pages{% if locale.num_others %} + {{ locale.num_others }} others{% endif %}
</td>
<th class="hostname">
{% if ordering == "name" %}
<a href="{% url 'wagtaillocales:index' %}" class="icon icon-arrow-down-after teal">
{% trans "Language" %}
</a>
{% else %}
<a href="{% url 'wagtaillocales:index' %}?ordering=name" class="icon icon-arrow-down-after">
{% trans "Language" %}
</a>
{% endif %}
</th>
<th>{% trans "Usage" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for locale in locales %}
<tr>
<td class="hostname title">
<div class="title-wrapper">
<a href="{% url 'wagtaillocales:edit' locale.id %}">{{ locale }}</a>
{% if not locale.language_code_is_valid %}
{% trans "This locale's language code is not supported" as error %}
{% include "wagtaillocales/_icon.html" with error=error only %}
{% endif %}
</div>
</td>
<td>
{# TODO Make this translatable #}
{{ locale.num_pages }} pages{% if locale.num_others %} + {{ locale.num_others }} others{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p class="w-mt-8">{% trans "No locales have been created yet." %}</p>
{% endif %}
</div>

{% if locales and is_paginated %}
<div class="nice-padding">
{% include "wagtailadmin/shared/pagination_nav.html" with items=page_obj linkurl=index_url %}
</div>
</div>
{% endif %}
{% endblock %}
38 changes: 38 additions & 0 deletions wagtail_localize/locales/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from unittest.mock import patch

from django.contrib.messages import get_messages
from django.core.exceptions import ValidationError
from django.db.models.query import QuerySet
from django.test import TestCase, override_settings
from django.urls import reverse
Expand Down Expand Up @@ -84,6 +87,19 @@ def test_wagtail_version(self):
expected_wagtail_version = get_main_version()
self.assertEqual(response.context["wagtail_version"], expected_wagtail_version)

def test_pagination_displayed(self):
for index in range(21):
Locale.objects.create(language_code=f"zz{index:02d}")

response = self.execute_request("GET", "wagtaillocales:index")
self.assert_successful_response(response)
self.assertContains(response, "Page 1 of 2")
self.assertContains(response, "?p=2")

page_two = self.execute_request("GET", "wagtaillocales:index", params={"p": 2})
self.assert_successful_response(page_two)
self.assertContains(page_two, "Page 2 of 2")

def test_get_locale_usage(self):
# Test the get_locale_usage function with different scenarios
# For example, test with a locale that has no pages and others
Expand Down Expand Up @@ -229,6 +245,28 @@ def test_sync_from_required_when_enabled(self):
# Check that the locale was not created
self.assertFalse(Locale.objects.filter(language_code="fr").exists())

def test_component_non_field_error_is_rendered(self):
with patch(
"wagtail_localize.models.LocaleSynchronizationModelForm.validate_with_locale",
side_effect=ValidationError("Component non-field issue"),
):
response = self.post(
{
"language_code": "fr",
"component-wagtail_localize_localesynchronization-enabled": "on",
"component-wagtail_localize_localesynchronization-sync_from": self.english.id,
}
)

self.assertEqual(response.status_code, 200)

component_errors = []
for _, _, component_form in response.context["components"]:
component_errors.extend(component_form.non_field_errors())

self.assertIn("Component non-field issue", component_errors)
self.assertContains(response, "Component non-field issue")

def test_sync_from_not_required_when_disabled(self):
# Test creating a locale with synchronization disabled
response = self.post(
Expand Down
1 change: 1 addition & 0 deletions wagtail_localize/locales/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class IndexView(generic.IndexView):
add_item_label = gettext_lazy("Add a locale")
context_object_name = "locales"
queryset = Locale.all_objects.all()
paginate_by = 20

def get_context_data(self):
context = super().get_context_data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<h3>{{ component.heading }}</h3>
{% if component.help_text %}<p>{{ component.help_text }}</p>{% endif %}

{% include "wagtailadmin/shared/non_field_errors.html" with form=component_form %}

<ul class="fields component-form__fields">
{% for field in component_form.visible_fields %}
<li class="component-form__fieldname-{{ field.name }}">{% include "wagtailadmin/shared/field.html" %}</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

{% for field in form.hidden_fields %}{{ field }}{% endfor %}

{% include "wagtailadmin/shared/non_field_errors.html" %}

<ul class="fields">
{% block visible_fields %}
{% for field in form.visible_fields %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

{% for field in form.hidden_fields %}{{ field }}{% endfor %}

{% include "wagtailadmin/shared/non_field_errors.html" %}

<ul class="fields">
{% block visible_fields %}
{% for field in form.visible_fields %}
Expand Down
3 changes: 2 additions & 1 deletion wagtail_localize/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from modelcluster.models import ClusterableModel
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import blocks, telepath
from wagtail import blocks
from wagtail.admin import telepath
from wagtail.admin.panels import (
FieldPanel,
InlinePanel,
Expand Down
17 changes: 17 additions & 0 deletions wagtail_localize/tests/test_submit_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import transaction
from django.test import TestCase, override_settings
from django.urls import reverse
Expand Down Expand Up @@ -278,6 +279,22 @@ def test_post_submit_page_translation(self, _mock_on_commit):
response, reverse("wagtailadmin_pages:edit", args=[translated_page.id])
)

@patch("wagtail_localize.views.submit_translations.SubmitTranslationForm.clean")
def test_submit_translation_form_non_field_error_is_rendered(self, mock_clean):
mock_clean.side_effect = ValidationError("Form level problem")

response = self.client.post(
reverse(
"wagtail_localize:submit_page_translation",
args=[self.en_blog_index.id],
),
{"locales": [self.fr_locale.id]},
)

self.assertEqual(response.status_code, 200)
self.assertIn("Form level problem", response.context["form"].non_field_errors())
self.assertContains(response, "Form level problem")

@override_settings(WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE=False)
def test_post_submit_page_translation_draft(self):
self.client.post(
Expand Down