Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wagtail 6.0 #124

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
558d8ec
Fix test app import: Wagtail 5.0 - wagtailsearch.Query has moved to w…
katdom13 Feb 20, 2024
f95b06f
Update supported Wagtail versions
katdom13 Feb 20, 2024
0ca391f
Wagtail 6.0 upgrade consideration: use_json_field is no longer a requ…
katdom13 Feb 20, 2024
2335654
GoogleMapsField: Wagtail 6.0 upgrade consideration: The class WidgetW…
katdom13 Feb 21, 2024
9ea4801
Update tests from GoogleMapsFieldTestCase
katdom13 Feb 21, 2024
8633a23
GeocoderField: Wagtail 6.0 upgrade consideration: The class WidgetWit…
katdom13 Feb 21, 2024
a64a017
Update tests from GeocoderFieldTestCase
katdom13 Feb 21, 2024
bdd6b18
LeafletField: Wagtail 6.0 upgrade consideration: The class WidgetWith…
katdom13 Feb 21, 2024
807c4b7
Update tests from LeafletCase
katdom13 Feb 21, 2024
7e84d08
Linting
katdom13 Feb 21, 2024
e86f4fa
Update CHANGELOG.md
katdom13 Feb 21, 2024
2c88b65
Update TypeError messages on render
katdom13 Feb 21, 2024
a899a93
Merge pull request #2 from torchbox-forks/support/wagtail-60
katdom13 Mar 13, 2024
1ab86c6
Update wagtailgeowidget/widgets.py
katdom13 Apr 2, 2024
c26f821
Need to check if Point is defined before checking if self.value_data …
nickmoreton May 17, 2024
95da44e
Merge pull request #5 from torchbox-forks/fix/wagtail-60-value-data
katdom13 May 20, 2024
130646b
Add fixed to unreleased
katdom13 May 20, 2024
cab04e8
Update workflow actions, Add Wagtail 6.1
katdom13 May 17, 2024
6407f5e
Drop Django < 4.2, Update classifiers
katdom13 May 17, 2024
bb4e6b2
Update changelog
katdom13 May 17, 2024
67fcbe7
Merge pull request #4 from torchbox-forks/support/wagtail61
katdom13 May 24, 2024
e9ad06c
Wagtail 6.2
engineervix Aug 28, 2024
379a6b1
Bump postgres to v13 because Django 5.1 doesn't support v12
engineervix Aug 28, 2024
07ddecf
MaintainerDeprecated: Maintainer instruction is deprecated in favor o…
engineervix Aug 28, 2024
d20ea77
Add missing templates for testing
engineervix Aug 29, 2024
672f231
Fix super() call in tests.geopage.models.ClassicGeoPage
engineervix Aug 29, 2024
3b6602e
Add missing "wagtail.contrib.search_promotions" in test settings
engineervix Aug 29, 2024
fbce7b5
Merge pull request #6 from torchbox-forks/support/wagtail62
engineervix Sep 9, 2024
4d899ab
Adjust test matrix for Wagtail 6.3 and Django 5.1
nickmoreton Nov 26, 2024
55e04f4
Adjust matrix to ensure testing against Django 5.1
nickmoreton Nov 26, 2024
b448b5c
Update CHANGELOG
nickmoreton Nov 28, 2024
7575fd3
Merge pull request #7 from torchbox-forks/support/wagtail-63
nickmoreton Nov 29, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
wagtail-version:
- 4.1
- 5.1
- 5.2
- 6.0
services:
postgres:
image: postgis/postgis:12-2.5
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## [Unreleased]
### Added
- Add support for Wagtail 6.0 (@katdom13)

### Changed
### Fixed
- Implement stimulus approach to GoogleMapsField, GeocoderField, and LeafletField (@katdom13)

### Removed
- Drop support for Django 4.1 (@katdom13)

## [8.1.1] - 2023.12.29
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started-with-google-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Requirements

- Python 3.8+
- Wagtail 4.1+ and Django 3.2+
- Wagtail 5.2+ and Django 3.2+
- A Google account


Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started-with-leaflet.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Requirements

- Python 3.8+
- Wagtail 4.1+ and Django 3.2+
- Wagtail 5.2+ and Django 3.2+
- Access to a tile provider for Leaflet, this library includes built in support for Open Street Map


Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
Expand All @@ -62,7 +61,7 @@
],
extras_require={"test": test_extras},
install_requires=[
"Wagtail>=4.1",
"Wagtail>=5.2",
],
project_urls={
"Source": "https://github.com/Frojd/wagtail-geo-widget/",
Expand Down
4 changes: 2 additions & 2 deletions tests/geopage/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import django.db.models.deletion
import modelcluster.fields
from django.db import migrations, models
from wagtail import VERSION as WAGTAIL_VERSION
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields

import wagtailgeowidget.blocks


class Migration(migrations.Migration):

initial = True

dependencies = [
("wagtailcore", "0066_collection_management_permissions"),
]

streamfield_params = {"use_json_field": True}
streamfield_params = {"use_json_field": True} if WAGTAIL_VERSION < (6, 0) else {}

operations = [
migrations.CreateModel(
Expand Down
3 changes: 2 additions & 1 deletion tests/geopage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.utils.functional import cached_property
from django.utils.translation import gettext as _
from modelcluster.fields import ParentalKey
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import blocks
from wagtail.admin.panels import (
FieldPanel,
Expand Down Expand Up @@ -141,7 +142,7 @@ class GeoPageWithLeaflet(Page):


class GeoStreamPage(Page):
streamfield_params = {"use_json_field": True}
streamfield_params = {"use_json_field": True} if WAGTAIL_VERSION < (6, 0) else {}

body = StreamField(
[
Expand Down
4 changes: 2 additions & 2 deletions tests/geopage_nospatial/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Generated by Django 4.0.2 on 2022-02-20 16:35
import django.db.models.deletion
from django.db import migrations, models
from wagtail import VERSION as WAGTAIL_VERSION
import wagtail.blocks as wagtail_blocks
import wagtail.fields as wagtail_fields

import wagtailgeowidget.blocks


class Migration(migrations.Migration):

initial = True

dependencies = [
("wagtailcore", "0066_collection_management_permissions"),
]

streamfield_params = {"use_json_field": True}
streamfield_params = {"use_json_field": True} if WAGTAIL_VERSION < (6, 0) else {}

operations = [
migrations.CreateModel(
Expand Down
3 changes: 2 additions & 1 deletion tests/geopage_nospatial/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.functional import cached_property
from django.utils.translation import gettext as _
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.fields import StreamField
Expand Down Expand Up @@ -164,7 +165,7 @@ def lng(self):


class StreamPage(Page):
streamfield_params = {"use_json_field": True}
streamfield_params = {"use_json_field": True} if WAGTAIL_VERSION < (6, 0) else {}

body = StreamField(
[
Expand Down
1 change: 0 additions & 1 deletion tests/home/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion tests/search/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.shortcuts import render
from wagtail.contrib.search_promotions.models import Query
from wagtail.models import Page
from wagtail.search.models import Query


def search(request):
Expand Down
152 changes: 133 additions & 19 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
from django.test import TestCase
from wagtail import VERSION as WAGTAIL_VERSION

from wagtailgeowidget import app_settings, geocoders
from wagtailgeowidget.widgets import GeocoderField, GoogleMapsField, LeafletField
Expand All @@ -15,9 +17,18 @@ def test_google_maps_field_contains_constuct_regular(self):
},
)

self.assertIn("new GoogleMapsField", html)
if WAGTAIL_VERSION >= (6, 0):
self.assertIn(
'<input type="hidden" name="field" id="X" data-controller="google-maps-field"',
html,
)
else:
self.assertIn("new GoogleMapsField", html)

def test_google_maps_field_js_init_contains_construct(self):
if WAGTAIL_VERSION >= (6, 0):
pytest.skip("Test only runs on Wagtail versions lower than 6.0")

widget = GoogleMapsField()
html = widget.render_js_init("id", "field", "")

Expand All @@ -35,20 +46,52 @@ def test_leaflet_field_contains_constuct_regular(self):
},
)

self.assertIn("new LeafletField", html)
if WAGTAIL_VERSION >= (6, 0):
self.assertIn(
'<input type="hidden" name="field" id="X" data-controller="leaflet-field"',
html,
)
else:
self.assertIn("new LeafletField", html)

def test_leaflet_field_js_init_contains_construct(self):
widget = LeafletField()
html = widget.render_js_init("id", "field", "")

self.assertIn("new LeafletField", html)
if WAGTAIL_VERSION >= (6, 0):
html = widget.render(
"field",
"",
{
"id": "X",
},
)
self.assertIn(
'<input type="hidden" name="field" id="X" data-controller="leaflet-field"',
html,
)
else:
html = widget.render_js_init("id", "field", "")
self.assertIn("new LeafletField", html)

def test_value_are_parsed_properly(self):
widget = LeafletField()
html = widget.render_js_init("id", "field", "SRID=5432;POINT(12.0 13.0)")

self.assertIn('"lat": "13.0"', html)
self.assertIn('"lng": "12.0"', html)
if WAGTAIL_VERSION >= (6, 0):
from html import escape

html = widget.render(
"field",
"SRID=5432;POINT(12.0 13.0)",
{
"id": "X",
},
)
self.assertIn(escape('"lat": "13.0"'), html)
self.assertIn(escape('"lng": "12.0"'), html)
else:
html = widget.render_js_init("id", "field", "SRID=5432;POINT(12.0 13.0)")
self.assertIn('"lat": "13.0"', html)
self.assertIn('"lng": "12.0"', html)


class GeocoderFieldTestCase(TestCase):
Expand All @@ -66,41 +109,112 @@ def test_geocoder_field_contains_constuct_regular(self):
},
)

self.assertIn("new NominatimGeocoderField", html)
if WAGTAIL_VERSION >= (6, 0):
self.assertIn(
'<input type="text" name="field" id="X" data-controller="geocoder-field" data-geocoder-field-geocoder-value="nominatim"',
html,
)
else:
self.assertIn("new NominatimGeocoderField", html)

def test_geocoder_field_js_init_contains_construct(self):
if WAGTAIL_VERSION >= (6, 0):
pytest.skip("Test only runs on Wagtail versions lower than 6.0")

widget = GeocoderField()
html = widget.render_js_init("id", "field", "")

self.assertIn("new NominatimGeocoderField", html)

def test_googlemaps_geocoder_returns_googlemaps_field(self):
widget = GeocoderField(geocoder=geocoders.GOOGLE_MAPS)
html = widget.render_js_init("id", "field", "")

self.assertIn("new GoogleMapsGeocoderField", html)
if WAGTAIL_VERSION >= (6, 0):
html = widget.render(
"field",
"",
{
"id": "X",
},
)
self.assertIn(
'<input type="text" name="field" id="X" data-controller="geocoder-field" data-geocoder-field-geocoder-value="google_maps"',
html,
)
else:
html = widget.render_js_init("id", "field", "")
self.assertIn("new GoogleMapsGeocoderField", html)

def test_mapbox_geocoder_returns_googlemaps_field(self):
widget = GeocoderField(geocoder=geocoders.MAPBOX)
html = widget.render_js_init("id", "field", "")

self.assertIn("new MapboxGeocoderField", html)
self.assertIn('accessToken": null', html)
if WAGTAIL_VERSION >= (6, 0):
from html import escape

html = widget.render(
"field",
"",
{
"id": "X",
},
)
self.assertIn(
'<input type="text" name="field" id="X" data-controller="geocoder-field" data-geocoder-field-geocoder-value="mapbox"',
html,
)
self.assertIn(escape('accessToken": null'), html)
else:
html = widget.render_js_init("id", "field", "")
self.assertIn("new MapboxGeocoderField", html)
self.assertIn('accessToken": null', html)

def test_mapbox_access_token_gets_outputted(self):
app_settings.MAPBOX_ACCESS_TOKEN = "<MAPBOX ACCESS TOKEN>"

widget = GeocoderField(geocoder=geocoders.MAPBOX)
html = widget.render_js_init("id", "field", "")

self.assertIn("new MapboxGeocoderField", html)
self.assertIn('accessToken": "<MAPBOX ACCESS TOKEN>', html)
if WAGTAIL_VERSION >= (6, 0):
from html import escape

html = widget.render(
"field",
"",
{
"id": "X",
},
)
self.assertIn(
'<input type="text" name="field" id="X" data-controller="geocoder-field" data-geocoder-field-geocoder-value="mapbox"',
html,
)
self.assertIn(escape('accessToken": "<MAPBOX ACCESS TOKEN>'), html)
else:
html = widget.render_js_init("id", "field", "")
self.assertIn("new MapboxGeocoderField", html)
self.assertIn('accessToken": "<MAPBOX ACCESS TOKEN>', html)

app_settings.MAPBOX_ACCESS_TOKEN = None

def test_mapbox_language_parameter_gets_outputted(self):
widget = GeocoderField(geocoder=geocoders.MAPBOX)
html = widget.render_js_init("id", "field", "")

self.assertIn("new MapboxGeocoderField", html)
self.assertIn('language": "en', html)
if WAGTAIL_VERSION >= (6, 0):
from html import escape

html = widget.render(
"field",
"",
{
"id": "X",
},
)
self.assertIn(
'<input type="text" name="field" id="X" data-controller="geocoder-field" data-geocoder-field-geocoder-value="mapbox"',
html,
)
self.assertIn(escape('language": "en'), html)
else:
html = widget.render_js_init("id", "field", "")

self.assertIn("new MapboxGeocoderField", html)
self.assertIn('language": "en', html)
Loading
Loading