Skip to content

Commit

Permalink
Merge pull request #3 from torchbox-forks/support/wagtail-52
Browse files Browse the repository at this point in the history
Wagtail 5.2
  • Loading branch information
katdom13 authored Nov 20, 2023
2 parents bf83d0e + cc8dde5 commit 13c1db1
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 168 deletions.
13 changes: 10 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ jobs:
build:
working_directory: ~/wagtail-autocomplete-repo
docker:
- image: randomknowledge/docker-pyenv-tox:maintenance_update-versions
- image: circleci/python:3.8-buster
steps:
- checkout
- run:
name: install dependencies
command: |
python -m venv venv
. venv/bin/activate
pip install -U pip
pip install ".[test]"
- run:
name: tests
command: tox
command: venv/bin/tox
- run:
name: flake8
command: tox -e flake8
command: venv/bin/tox -e flake8
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Features
~~~~~~~~

* Rapidly select related objects via a smooth autocomplete interface
* A drop-in alternative to ``PageChooserPanel`` or ``SnippetChooserPanel``
* A drop-in alternative to ``FieldPanel``
* Create new objects from the autocomplete input if your search turns up blank
* React component can be used outside of the Wagtail admin for public-facing forms
* Default theme shares the color scheme and styles of the Wagtail admin
Expand Down
10 changes: 5 additions & 5 deletions docs/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We have a ``BlogPage`` that lets the editor select an ``AuthorPage`` page.
)
The ``AuthorPage`` would traditionally be selected with a
:class:`~wagtail:wagtail.wagtailadmin.edit_handlers.PageChooserPanel`,
:class:`~wagtail:wagtail.admin.panels.PageChooserPanel`,
like the following.

.. code-block:: python
Expand Down Expand Up @@ -54,12 +54,12 @@ AutocompletePanel
to a model class or a model string in ``app_label.ModelName`` syntax.

.. note::
Unlike :class:`~wagtail:wagtail.wagtailadmin.edit_handlers.PageChooserPanel`,
``AutocompletePanel`` does not support receiving ``target_model`` as a list.
Unlike :class:`~wagtail:wagtail.admin.panels.PageChooserPanel`,
``AutocompletePanel`` does not take a ``page_type`` argument but uses ``target_model`` argument, but it cannot be a list.

.. note::
``AutocompletePanel`` does not support receiving the ``can_choose_root``
argument that :class:`~wagtail:wagtail.wagtailadmin.edit_handlers.PageChooserPanel`
argument that :class:`~wagtail:wagtail.admin.panels.PageChooserPanel`
does.

Multiple Selection With Clusterable Models
Expand All @@ -76,7 +76,7 @@ provide a multiple selection widget. For example:
.. code-block:: python
from django.db import models
from wagtail.core.models import Page
from wagtail.models import Page
from modelcluster.models import ClusterableModel
from modelcluster.fields import ParentalManyToManyField
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

Unreleased
----------

* Remove tests for Wagtail 4.2 and 5.0 as they have reached their EOL
* Added Wagtail 5.x compatibility
* Added tests for Python 3.10 and 3.11
* Remove support for versions of Wagtail < 4.1 (Wagtail 4.1 or later now required)

0.10 Release
------------

Expand Down
8 changes: 4 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ Add Wagtail Autocomplete's URL patterns to your project's URL config, usually in
from django.conf.urls import include, url
from wagtail.wagtailcore import urls as wagtail_urls
from wagtail import urls as wagtail_urls
from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls
urlpatterns = [
# ...
url(r'^admin/autocomplete/', include(autocomplete_admin_urls)),
url(r'^admin/', include(wagtailadmin_urls)),
path('admin/autocomplete/', include(autocomplete_admin_urls)),
path("admin/", include(wagtailadmin_urls)),
# ...
url(r'', include(wagtail_urls)),
path("", include(wagtail_urls)),
]
This makes available custom API endpoints that provide the search and creation behavior for the widget.
Expand Down
13 changes: 6 additions & 7 deletions docs/using_other_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ Selecting Snippets

For example, we have a Django model ``Link`` that we have registered as a snippet.
We also have a ``BlogPage`` model that would traditionally use a
:class:`~wagtail:wagtail.wagtailsnippets.edit_handlers.SnippetChooserPanel`
:class:`~wagtail:wagtail.admin.panels.FieldPanel`


.. code-block:: python
from django.db import models
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailcore.models import Page
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
from wagtail.wagtailsnippets.models import register_snippet
from wagtail.admin.panels import FieldPanel
from wagtail.models import Page
from wagtail.snippets.models import register_snippet
@register_snippet
class Link(models.Model):
Expand All @@ -43,11 +42,11 @@ We also have a ``BlogPage`` model that would traditionally use a
)
content_panels = [
SnippetChooserPanel('external_link'),
FieldPanel('external_link'),
]
We can replace the
:class:`~wagtail:wagtail.wagtailsnippets.edit_handlers.SnippetChooserPanel`
:class:`~wagtail:wagtail.admin.panels.FieldPanel`
usage with
:class:`AutocompletePanel`.

Expand Down
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
license='BSD-3-Clause',

install_requires=[
'wagtail>=2.15',
'wagtail>=4.1',
],

extras_require={
Expand All @@ -50,15 +50,19 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Framework :: Django',
'Framework :: Django :: 3',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4',
'Framework :: Django :: 4.1',
'Framework :: Django :: 4.2',
'Framework :: Wagtail',
'Framework :: Wagtail :: 2',
'Framework :: Wagtail :: 3',
'Framework :: Wagtail :: 4',
'Framework :: Wagtail :: 5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
Expand Down
23 changes: 14 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
skipsdist = True
usedevelop = True
envlist =
py{37,38,39}-dj{30,31,32}-wt{215}
py{37,38,39}-dj{32,40}-wt{216,30}
py{38,39,310}-dj{32,41}-wt{41,51,52}
py311-dj41-wt{41,51,52}
py311-dj42-wt{51,52}

[testenv]
install_command = pip install -e ".[test]" -U {opts} {packages}
commands = py.test
basepython =
py37: python3.7
py38: python3.8
py39: python3.9
py310: python3.10
py311: python3.11
deps =
dj30: django>=3.0,<3.1
dj31: django>=3.1,<3.2
dj32: django>=3.2,<4.0
wt215: wagtail>=2.15,<2.16
wt216: wagtail>=2.16,<3.0
wt30: wagtail>=3.0,<4.0
dj41: django>=4.1,<4.2
dj42: django>=4.2,<4.3
wt41: wagtail>=4.1,<4.2
wt42: wagtail>=4.2,<5.0
wt50: wagtail>=5.0,<5.1
wt51: wagtail>=5.1,<5.2
wt52: wagtail>=5.2,<5.3

[testenv:flake8]
basepython = python3.7
basepython = python3.8
deps = flake8>3.7
commands = flake8 wagtailautocomplete
19 changes: 6 additions & 13 deletions wagtailautocomplete/edit_handlers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.models import ManyToManyField
from django.utils.functional import cached_property
from wagtail import VERSION as WAGTAIL_VERSION

if WAGTAIL_VERSION >= (3, 0):
from wagtail.admin.panels import FieldPanel
from wagtail.coreutils import resolve_model_string
else:
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.utils import resolve_model_string
from wagtail.admin.panels import FieldPanel
from wagtail.coreutils import resolve_model_string

from .widgets import Autocomplete

Expand Down Expand Up @@ -48,11 +42,10 @@ def widget_overrides(self):
)
}

if WAGTAIL_VERSION >= (3, 0):
def get_form_options(self):
options = super().get_form_options()
options['widgets'] = self.widget_overrides()
return options
def get_form_options(self):
options = super().get_form_options()
options['widgets'] = self.widget_overrides()
return options

@cached_property
def target_model(self):
Expand Down
4 changes: 1 addition & 3 deletions wagtailautocomplete/tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from wagtail import VERSION as WAGTAIL_VERSION

SECRET_KEY = 'NOTSECRET'

DATABASES = {
Expand All @@ -14,7 +12,7 @@
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'wagtail' if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
'wagtail',
'wagtail.documents',
'wagtail.images',
'wagtail.admin',
Expand Down
8 changes: 1 addition & 7 deletions wagtailautocomplete/tests/test_autocomplete_views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.test import TestCase
from wagtail import VERSION as WAGTAIL_VERSION

if WAGTAIL_VERSION >= (3, 0):
from wagtail.models import Site
else:
from wagtail.core.models import Site
from wagtail.models import Site

from wagtailautocomplete.tests.testapp.models import House, Person


User = get_user_model()


Expand Down
Loading

0 comments on commit 13c1db1

Please sign in to comment.