-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update field templates and styling for Wagtail 6.1 (#243)
Includes - Wagtail 5.1 upgrade consideration: Any direct usage of the jQuery widget in JavaScript should be removed - Wagtail 6.0 upgrade consideration: The global Javascript definition headerSearch has been removed - Update change logs, classifiers, test matrix on tox.ini - Add upgrading notes to include templates
- Loading branch information
Showing
22 changed files
with
185 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
src/wagtailmedia/templates/wagtailmedia/media/_file_field.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{% extends "wagtailadmin/shared/field.html" %} | ||
{% load i18n %} | ||
{% block form_field %} | ||
<a href="{{ media.url }}" class="icon icon-media">{{ media.filename }}</a><br /><br /> | ||
{% load i18n wagtailadmin_tags %} | ||
{% rawformattedfield field=field %} | ||
<a href="{{ media.url }}">{% icon name="media" classname="middle" %} {{ media.filename }}</a><br /><br /> | ||
{% trans "Change media file:" %} | ||
{{ field }} | ||
{% endblock %} | ||
{% endrawformattedfield %} |
11 changes: 9 additions & 2 deletions
11
src/wagtailmedia/templates/wagtailmedia/media/_file_field_as_li.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{% load wagtailadmin_tags %} | ||
{% load wagtailadmin_tags media_tags %} | ||
|
||
{% wagtail_version_gte "6.0" as wagtail_gte_60 %} | ||
|
||
<li class="{% if field.field.required %}required{% endif %} {{ wrapper_classes }} {{ li_classes }} {% if field.errors %}error{% endif %}"> | ||
{% include "wagtailmedia/media/_file_field.html" %} | ||
{% if wagtail_gte_60 %} | ||
{% include "wagtailmedia/media/_file_field.html" %} | ||
{% else %} | ||
{% include "wagtailmedia/media/_file_field_legacy.html" %} | ||
{% endif %} | ||
</li> |
7 changes: 7 additions & 0 deletions
7
src/wagtailmedia/templates/wagtailmedia/media/_file_field_legacy.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends "wagtailadmin/shared/field.html" %} | ||
{% load i18n %} | ||
{% block form_field %} | ||
<a href="{{ media.url }}" class="icon icon-media">{{ media.filename }}</a><br /><br /> | ||
{% trans "Change media file:" %} | ||
{{ field }} | ||
{% endblock %} |
9 changes: 4 additions & 5 deletions
9
src/wagtailmedia/templates/wagtailmedia/media/_thumbnail_field.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
{% extends "wagtailadmin/shared/field.html" %} | ||
{% load i18n %} | ||
{% block form_field %} | ||
{% load i18n wagtailadmin_tags %} | ||
{% rawformattedfield field=field %} | ||
<div class="w-field__wrapper"> | ||
{% if media.thumbnail %} | ||
<a href="{{ media.thumbnail.url }}" class="icon icon-image">{{ media.thumbnail_filename }}</a><br /><br /> | ||
<a href="{{ media.thumbnail.url }}">{% icon name="image" classname="middle" %} {{ media.thumbnail_filename }}</a><br /><br /> | ||
{% endif %} | ||
|
||
{{ field }} | ||
</div> | ||
{% endblock %} | ||
{% endrawformattedfield %} |
11 changes: 9 additions & 2 deletions
11
src/wagtailmedia/templates/wagtailmedia/media/_thumbnail_field_as_li.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
{% load wagtailadmin_tags %} | ||
{% load wagtailadmin_tags media_tags %} | ||
|
||
{% wagtail_version_gte "6.0" as wagtail_gte_60 %} | ||
|
||
<li class="{% if field.field.required %}required{% endif %} {{ wrapper_classes }} {{ li_classes }} {% if field.errors %}error{% endif %}"> | ||
{% include "wagtailmedia/media/_thumbnail_field.html" %} | ||
{% if wagtail_gte_60 %} | ||
{% include "wagtailmedia/media/_thumbnail_field.html" %} | ||
{% else %} | ||
{% include "wagtailmedia/media/_thumbnail_field_legacy.html" %} | ||
{% endif %} | ||
</li> |
11 changes: 11 additions & 0 deletions
11
src/wagtailmedia/templates/wagtailmedia/media/_thumbnail_field_legacy.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "wagtailadmin/shared/field.html" %} | ||
{% load i18n %} | ||
{% block form_field %} | ||
<div class="w-field__wrapper"> | ||
{% if media.thumbnail %} | ||
<a href="{{ media.thumbnail.url }}" class="icon icon-image">{{ media.thumbnail_filename }}</a><br /><br /> | ||
{% endif %} | ||
|
||
{{ field }} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.template import Library | ||
from wagtail.utils.version import get_main_version | ||
|
||
|
||
register = Library() | ||
|
||
|
||
@register.simple_tag | ||
def wagtail_version_gte(version: str) -> bool: | ||
return get_main_version() >= version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest | ||
|
||
from unittest.mock import patch | ||
|
||
from django import forms | ||
from django.http import HttpResponse | ||
from django.template import Context, Template | ||
from django.test import TestCase, override_settings | ||
from django.urls import path | ||
from django.views import View | ||
from wagtail import VERSION as WAGTAIL_VERSION | ||
|
||
|
||
class DummyForm(forms.Form): | ||
media_file = forms.FileField(label="Change media file:", required=False) | ||
|
||
|
||
class DummyFileFieldView(View): | ||
template_string = """ | ||
{% load media_tags %} | ||
{% wagtail_version_gte "6.0" as wagtail_gte_60 %} # Update version as needed | ||
{% if wagtail_gte_60 %} | ||
{% include "wagtailmedia/media/_file_field.html" %} | ||
{% else %} | ||
{% include "wagtailmedia/media/_file_field_legacy.html" %} | ||
{% endif %} | ||
""" | ||
|
||
def get(self, request, *args, **kwargs): | ||
template = Template(self.template_string) | ||
form = DummyForm() # Create an instance of the form | ||
context_data = self.get_context_data(form=form, **kwargs) | ||
return HttpResponse(template.render(Context(context_data))) | ||
|
||
def get_context_data(self, **kwargs): | ||
# Mock 'media' and 'field' as they are used in the templates | ||
return { | ||
"media": { | ||
"url": "http://example.com/media/file.mp3", | ||
"filename": "file.mp3", | ||
}, | ||
"field": kwargs["form"]["media_file"], # Passing the actual form field | ||
**kwargs, | ||
} | ||
|
||
|
||
urlpatterns = [ | ||
# Temporary URL for testing | ||
path( | ||
"test-filefield-template/", | ||
DummyFileFieldView.as_view(), | ||
name="test-filefield-template", | ||
), | ||
] | ||
|
||
|
||
@override_settings(ROOT_URLCONF=__name__) # Override ROOT_URLCONF during this test | ||
class WagtailVersionFileFieldTemplateTests(TestCase): | ||
@patch( | ||
"wagtailmedia.templatetags.media_tags.get_main_version", return_value="5.2" | ||
) # Version for legacy template | ||
def test_legacy_template_loaded(self, _mock): | ||
response = self.client.get("/test-filefield-template/") | ||
self.assertTemplateUsed(response, "wagtailmedia/media/_file_field_legacy.html") | ||
|
||
@unittest.skipUnless(WAGTAIL_VERSION >= (6, 0), "Requires Wagtail 6.0 or higher") | ||
@patch( | ||
"wagtailmedia.templatetags.media_tags.get_main_version", return_value="6.0" | ||
) # Version for new template | ||
def test_new_template_loaded(self, _mock): | ||
response = self.client.get("/test-filefield-template/") | ||
self.assertTemplateUsed(response, "wagtailmedia/media/_file_field.html") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
from wagtailmedia.templatetags.media_tags import wagtail_version_gte | ||
|
||
|
||
class MediaTagsTests(TestCase): | ||
def test_wagtail_version_gte(self): | ||
scenarios = [ | ||
("5.2", "5.2", True), | ||
("5.2.1", "5.2", True), | ||
("5.2", "5.2.1", False), | ||
("4.2", "5.2", False), | ||
] | ||
|
||
for wagtail_version, version_to_test, result in scenarios: | ||
with patch( | ||
"wagtailmedia.templatetags.media_tags.get_main_version", | ||
return_value=wagtail_version, | ||
): | ||
self.assertEqual(wagtail_version_gte(version_to_test), result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters