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 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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)