diff --git a/.gitignore b/.gitignore index 1f5d767..e7db9cd 100644 --- a/.gitignore +++ b/.gitignore @@ -177,6 +177,7 @@ bh_unicode_properties.cache # Sublime-github package stores a github token in this file # https://packagecontrol.io/packages/sublime-github GitHub.sublime-settings - +.idea +sandbox/db.sqlite3 # End of https://www.gitignore.io/api/osx,linux,python,sublimetext diff --git a/Makefile b/Makefile index e99bd17..60af9e7 100644 --- a/Makefile +++ b/Makefile @@ -5,3 +5,6 @@ translations: cd src/wagtail_nav_menus && \ django-admin makemessages -a && \ django-admin compilemessages + +makemigrations: + docker-compose run web python sandbox/manage.py makemigrations diff --git a/sandbox/sandbox/settings.py b/sandbox/sandbox/settings.py index 12c13ae..7eb2f56 100644 --- a/sandbox/sandbox/settings.py +++ b/sandbox/sandbox/settings.py @@ -22,7 +22,7 @@ "taggit", "modelcluster", "sandbox", - "wagtail.core", + "wagtail", "wagtail.admin", "wagtail.documents", "wagtail.snippets", @@ -49,7 +49,7 @@ ] if wagtail.VERSION[0] == 2 and wagtail.VERSION[1] < 9: MIDDLEWARE += [ - "wagtail.core.middleware.SiteMiddleware", + "wagtail.middleware.SiteMiddleware", ] MIDDLEWARE += [ "wagtail.contrib.redirects.middleware.RedirectMiddleware", diff --git a/sandbox/sandbox/urls.py b/sandbox/sandbox/urls.py index 058bc01..0fc1a69 100644 --- a/sandbox/sandbox/urls.py +++ b/sandbox/sandbox/urls.py @@ -17,7 +17,7 @@ from django.conf import settings from django.conf.urls.static import static from django.urls import include, re_path -from wagtail.core import urls as wagtail_urls +from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls from wagtail.search.signal_handlers import ( register_signal_handlers as wagtailsearch_register_signal_handlers, diff --git a/setup.py b/setup.py index bc9a876..56b0e92 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ packages = find_packages("src") install_requires = [ - "wagtail>=2.7,<4.1", + "wagtail>=3.0,<4.2", ] extras_require = { "development": ["flake8>=3.3.0", "tox>=2.7.0", "ipdb"], diff --git a/src/wagtail_nav_menus/defaults.py b/src/wagtail_nav_menus/defaults.py index 59278e4..9958c31 100644 --- a/src/wagtail_nav_menus/defaults.py +++ b/src/wagtail_nav_menus/defaults.py @@ -4,7 +4,7 @@ ("django_url", "wagtail_nav_menus.models", "DjangoURLBlock"), ("relative_url", "wagtail_nav_menus.models", "RelativeURLBlock"), ("image", "wagtail.images.blocks", "ImageChooserBlock"), - ("html", "wagtail.core.blocks", "RawHTMLBlock"), + ("html", "wagtail.blocks", "RawHTMLBlock"), ] WAGTAIL_NAV_MENU_CHOICES_DEFAULT = [ diff --git a/src/wagtail_nav_menus/migrations/0001_initial.py b/src/wagtail_nav_menus/migrations/0001_initial.py index ddddb0b..721cb55 100644 --- a/src/wagtail_nav_menus/migrations/0001_initial.py +++ b/src/wagtail_nav_menus/migrations/0001_initial.py @@ -3,8 +3,8 @@ from __future__ import unicode_literals from django.db import migrations, models -import wagtail.core.blocks -import wagtail.core.fields +import wagtail.blocks +import wagtail.fields import wagtail.images.blocks @@ -37,13 +37,13 @@ class Migration(migrations.Migration): ), ( "menu", - wagtail.core.fields.StreamField( + wagtail.fields.StreamField( ( ( "heading", - wagtail.core.blocks.CharBlock(classname="full title"), + wagtail.blocks.CharBlock(classname="full title"), ), - ("paragraph", wagtail.core.blocks.RichTextBlock()), + ("paragraph", wagtail.blocks.RichTextBlock()), ("image", wagtail.images.blocks.ImageChooserBlock()), ) ), diff --git a/src/wagtail_nav_menus/migrations/0002_auto_20190911_1745.py b/src/wagtail_nav_menus/migrations/0002_auto_20190911_1745.py index bf2b749..02708ba 100644 --- a/src/wagtail_nav_menus/migrations/0002_auto_20190911_1745.py +++ b/src/wagtail_nav_menus/migrations/0002_auto_20190911_1745.py @@ -2,8 +2,8 @@ from django.db import migrations, models import django.db.models.deletion -import wagtail.core.blocks -import wagtail.core.fields +import wagtail.blocks +import wagtail.fields import wagtail.images.blocks import wagtail_nav_menus.models @@ -58,105 +58,105 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="navmenu", name="menu", - field=wagtail.core.fields.StreamField( + field=wagtail.fields.StreamField( [ ( "nav_category", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("title", wagtail.core.blocks.CharBlock()), + ("title", wagtail.blocks.CharBlock()), ( "sub_nav", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page_link", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( required=False ), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock( + wagtail.blocks.BooleanBlock( required=False ), ), ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ] ), ), ( "external_link", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( required=False ), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock( + wagtail.blocks.BooleanBlock( required=False ), ), ( "link", - wagtail.core.blocks.URLBlock(), + wagtail.blocks.URLBlock(), ), ] ), ), ( "django_url", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( required=False ), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock( + wagtail.blocks.BooleanBlock( required=False ), ), ( "url_name", - wagtail.core.blocks.CharBlock(), + wagtail.blocks.CharBlock(), ), ] ), ), ( "relative_url", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( required=False ), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock( + wagtail.blocks.BooleanBlock( required=False ), ), ( "link", - wagtail.core.blocks.RegexBlock( + wagtail.blocks.RegexBlock( error_mesage={ "invalid": "Not a relative URL" }, @@ -172,7 +172,7 @@ class Migration(migrations.Migration): ), ( "html", - wagtail.core.blocks.RawHTMLBlock(), + wagtail.blocks.RawHTMLBlock(), ), ] ), @@ -182,67 +182,67 @@ class Migration(migrations.Migration): ), ( "page_link", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock(required=False), + wagtail.blocks.BooleanBlock(required=False), ), - ("page", wagtail.core.blocks.PageChooserBlock()), + ("page", wagtail.blocks.PageChooserBlock()), ] ), ), ( "external_link", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock(required=False), + wagtail.blocks.BooleanBlock(required=False), ), - ("link", wagtail.core.blocks.URLBlock()), + ("link", wagtail.blocks.URLBlock()), ] ), ), ( "django_url", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock(required=False), + wagtail.blocks.BooleanBlock(required=False), ), - ("url_name", wagtail.core.blocks.CharBlock()), + ("url_name", wagtail.blocks.CharBlock()), ] ), ), ( "relative_url", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "override_title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "open_in_new_tab", - wagtail.core.blocks.BooleanBlock(required=False), + wagtail.blocks.BooleanBlock(required=False), ), ( "link", - wagtail.core.blocks.RegexBlock( + wagtail.blocks.RegexBlock( error_mesage={"invalid": "Not a relative URL"}, regex="^(?!www\\.|(?:http|ftp)s?://|[A-Za-z]:\\\\|//).*", ), @@ -251,7 +251,7 @@ class Migration(migrations.Migration): ), ), ("image", wagtail.images.blocks.ImageChooserBlock()), - ("html", wagtail.core.blocks.RawHTMLBlock()), + ("html", wagtail.blocks.RawHTMLBlock()), ] ), ), diff --git a/src/wagtail_nav_menus/migrations/0004_alter_navmenu_menu.py b/src/wagtail_nav_menus/migrations/0004_alter_navmenu_menu.py new file mode 100644 index 0000000..a532d2c --- /dev/null +++ b/src/wagtail_nav_menus/migrations/0004_alter_navmenu_menu.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.5 on 2023-01-31 15:10 + +from django.db import migrations +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtail_nav_menus', '0003_auto_20191111_1655'), + ] + + operations = [ + migrations.AlterField( + model_name='navmenu', + name='menu', + field=wagtail.fields.StreamField([('nav_category', wagtail.blocks.StructBlock([('title', wagtail.blocks.CharBlock()), ('sub_nav', wagtail.blocks.StreamBlock([('page_link', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('page', wagtail.blocks.PageChooserBlock())])), ('external_link', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('link', wagtail.blocks.URLBlock())])), ('django_url', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('url_name', wagtail.blocks.CharBlock())])), ('relative_url', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('link', wagtail.blocks.RegexBlock(error_mesage={'invalid': 'Not a relative URL'}, regex='^(?!www\\.|(?:http|ftp)s?://|[A-Za-z]:\\\\|//).*'))])), ('image', wagtail.images.blocks.ImageChooserBlock()), ('html', wagtail.blocks.RawHTMLBlock())]))])), ('page_link', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('page', wagtail.blocks.PageChooserBlock())])), ('external_link', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('link', wagtail.blocks.URLBlock())])), ('django_url', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('url_name', wagtail.blocks.CharBlock())])), ('relative_url', wagtail.blocks.StructBlock([('override_title', wagtail.blocks.CharBlock(required=False)), ('open_in_new_tab', wagtail.blocks.BooleanBlock(required=False)), ('link', wagtail.blocks.RegexBlock(error_mesage={'invalid': 'Not a relative URL'}, regex='^(?!www\\.|(?:http|ftp)s?://|[A-Za-z]:\\\\|//).*'))])), ('image', wagtail.images.blocks.ImageChooserBlock()), ('html', wagtail.blocks.RawHTMLBlock())], use_json_field=True), + ), + ] diff --git a/src/wagtail_nav_menus/models.py b/src/wagtail_nav_menus/models.py index 5d5969d..645b913 100644 --- a/src/wagtail_nav_menus/models.py +++ b/src/wagtail_nav_menus/models.py @@ -4,11 +4,10 @@ from django.urls import reverse from django.urls import NoReverseMatch from django.utils.translation import gettext_lazy as _ -from wagtail import VERSION as WAGTAIL_VERSION -from wagtail.core.fields import StreamField -from wagtail.core import blocks -from wagtail.core.models import Site -from wagtail.admin.edit_handlers import FieldPanel +from wagtail.fields import StreamField +from wagtail import blocks +from wagtail.models import Site +from wagtail.admin.panels import FieldPanel from .loading import get_class from .utils import date_handler from .defaults import ( @@ -16,13 +15,6 @@ WAGTAIL_NAV_MENU_CHOICES_DEFAULT, ) -# See "Removal of special-purpose field panel types" -# https://docs.wagtail.org/en/stable/releases/3.0.html#removal-of-special-purpose-field-panel-types -if WAGTAIL_VERSION[0] >= 3: - from wagtail.admin.panels import FieldPanel as StreamFieldPanel # NOQA -else: - from wagtail.admin.edit_handlers import StreamFieldPanel # NOQA - NAV_MENU_CHOICES = getattr( settings, "WAGTAIL_NAV_MENU_CHOICES", WAGTAIL_NAV_MENU_CHOICES_DEFAULT @@ -149,13 +141,14 @@ class AbstractNavMenu(models.Model): [ ("nav_category", NavCategoryBlock()), ] - + nav_content + + nav_content, + use_json_field=True, ) panels = [ FieldPanel("site"), FieldPanel("name"), - StreamFieldPanel("menu"), + FieldPanel("menu"), ] class Meta: diff --git a/src/wagtail_nav_menus/templatetags/nav_menu_tags.py b/src/wagtail_nav_menus/templatetags/nav_menu_tags.py index 4cc7c69..6aeae39 100644 --- a/src/wagtail_nav_menus/templatetags/nav_menu_tags.py +++ b/src/wagtail_nav_menus/templatetags/nav_menu_tags.py @@ -1,5 +1,5 @@ from django import template -from wagtail.core.models import Site +from wagtail.models import Site from ..models import NavMenu register = template.Library() diff --git a/src/wagtail_nav_menus/tests.py b/src/wagtail_nav_menus/tests.py index 99a6e42..9684cee 100644 --- a/src/wagtail_nav_menus/tests.py +++ b/src/wagtail_nav_menus/tests.py @@ -1,6 +1,6 @@ from django.test import TestCase from rest_framework.test import APIRequestFactory -from wagtail.core.models import Site, Page +from wagtail.models import Site, Page from .viewsets import NavMenuViewSet from .models import NavMenu import json diff --git a/src/wagtail_nav_menus/viewsets.py b/src/wagtail_nav_menus/viewsets.py index 6e062e6..a1b462b 100644 --- a/src/wagtail_nav_menus/viewsets.py +++ b/src/wagtail_nav_menus/viewsets.py @@ -1,5 +1,5 @@ from rest_framework import viewsets -from wagtail.core.models import Site +from wagtail.models import Site from wagtail_nav_menus.models import NavMenu from wagtail_nav_menus.serializers import NavMenuSerializer diff --git a/tox.ini b/tox.ini index 1bc5fec..6dcccbe 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] -envlist = py{38,39,310}-django{320}-wagtail{215,300,400} - py{38,39,310}-django{400}-wagtail{300,400} - py{38,39,310}-django{410}-wagtail{400} +envlist = py{38,39,310}-django{320}-wagtail{300,400,410} + py{38,39,310}-django{400}-wagtail{300,400,410} + py{38,39,310}-django{410}-wagtail{400,410} [testenv] extras = development @@ -9,9 +9,9 @@ deps = django320: django>=3.2,<3.3 django400: django>=4.0,<4.1 django410: django>=4.1,<4.2 - wagtail215: wagtail>=2.15,<2.16 wagtail300: wagtail>=3.0,<3.1 wagtail400: wagtail>=4.0,<4.1 + wagtail410: wagtail>=4.1,<4.2 setenv = PYTHONWARNINGS = d commands =