Skip to content

Commit

Permalink
Merge pull request #84 from cfpb/upgrade/wagtail62
Browse files Browse the repository at this point in the history
Update for Wagtail 6.2 universal listing reports
  • Loading branch information
willbarton authored Sep 23, 2024
2 parents 601ad5f + 9e23409 commit 6a81357
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 103 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ jobs:

strategy:
matrix:
python: ['3.8', '3.12']
django: ['4.2']
wagtail: ['5.2', '6.0', '6.1']
python: ['3.12']
django: ['4.2', '5.0']
wagtail: ['6.2']
include:
- python: '3.12'
django: '5.0'
wagtail: '5.2'
- python: '3.12'
django: '5.0'
wagtail: '6.0'
- python: '3.12'
django: '5.0'
wagtail: '6.1'
- python: '3.8'
django: '4.2'
wagtail: '6.2'

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 4 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ Install the package using pip:
$ pip install wagtail-inventory
This will also install `django-autocomplete-light <https://django-autocomplete-light.readthedocs.io/>`_.

Add ``dal``, ``dal_select2``, and ``wagtailinventory`` as installed apps in your Django settings:
Add `wagtailinventory`` as an installed app in your Django settings:

.. code-block:: python
# in settings.py
INSTALLED_APPS = (
...
'dal',
'dal_select2',
'wagtailinventory',
...
)
Expand All @@ -54,9 +50,9 @@ Compatibility

This code has been tested for compatibility with:

* Python 3.8+
* Django 3.2 (LTS), 4.2 (LTS), 5.0
* Wagtail 3.0+, including 5.2 (LTS) and 6.0
* Python 3.8, 3.12
* Django 4.2 (LTS), 5.0
* Wagtail 6.2

It should be compatible with all intermediate versions, as well.
If you find that it is not, please `file an issue <https://github.com/cfpb/wagtail-inventory/issues/new>`_.
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ authors = [
]
dependencies = [
"tqdm>=4.15.0,<5",
"wagtail>=5.2",
"django-autocomplete-light>=3.9",
"wagtail>=6.2",
]
classifiers = [
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"License :: Public Domain",
Expand Down
8 changes: 3 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
skipsdist=True
envlist=
lint,
python3.8-django{4.2}-wagtail{5.2,6.0,6.1}
python3.12-django{4.2,5.0}-wagtail{5.2,6.0,6.1}
python3.8-django{4.2}-wagtail{6.2}
python3.12-django{4.2,5.0}-wagtail{6.2}
coverage

[testenv]
Expand All @@ -18,9 +18,7 @@ basepython=
deps=
django4.2: Django>=4.2,<4.3
django5.0: Django>=5.0,<5.1
wagtail5.2: wagtail>=5.2,<6.0
wagtail6.0: wagtail>=6.0,<6.1
wagtail6.1: wagtail>=6.1,<6.2
wagtail6.2: wagtail>=6.2,<6.3

[testenv:lint]
basepython=python3.12
Expand Down
2 changes: 0 additions & 2 deletions wagtailinventory/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
)
+ WAGTAIL_APPS
+ (
"dal",
"dal_select2",
"wagtailinventory",
"wagtailinventory.tests.testapp",
)
Expand Down
32 changes: 0 additions & 32 deletions wagtailinventory/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.core.management import call_command
from django.test import TestCase
from django.urls import reverse

Expand All @@ -11,37 +10,6 @@
User = get_user_model()


class BlockAutocompleteViewTestCase(WagtailTestUtils, TestCase):
fixtures = ["test_blocks.json"]

def setUp(self):
self.login()

def test_get_list(self):
call_command("block_inventory", verbosity=0)
response = self.client.get(
reverse("wagtailinventory:block_autocomplete")
)

json_response = response.json()
self.assertIn("results", json_response)

results = json_response["results"]

# There are six unique block types in our test fixture
self.assertEqual(len(results), 6)

# Make sure that one of the results matches our expected id/text
# pairing
self.assertIn(
{
"id": "wagtail.blocks.field_block.CharBlock",
"text": "wagtail.blocks.field_block.CharBlock",
},
results,
)


class BlockInventoryReportViewTestCase(WagtailTestUtils, TestCase):
fixtures = ["test_blocks.json"]

Expand Down
50 changes: 19 additions & 31 deletions wagtailinventory/views.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
import wagtail
from django.forms.widgets import SelectMultiple

from wagtail.admin.auth import permission_denied
from wagtail.admin.filters import ContentTypeFilter, WagtailFilterSet
from wagtail.admin.views.reports import PageReportView
from wagtail.models import Page
from wagtail.models import Page, get_page_content_types

import django_filters
from dal import autocomplete

from wagtailinventory.models import PageBlock


if wagtail.VERSION >= (6,):
from wagtail.models import get_page_content_types
else: # pragma: no cover
# For Wagtail < 6, use an older method to get the list of page types.
from wagtail.admin.views.reports.aging_pages import (
get_content_types_for_filter,
)

def get_page_content_types(include_base_page_type=True):
return get_content_types_for_filter()


class BlockAutocompleteView(autocomplete.Select2ListView):
def get_list(self):
return (
PageBlock.objects.distinct()
.order_by("block")
.values_list("block", flat=True)
)
def get_block_choices():
return [
(page_block, page_block)
for page_block in PageBlock.objects.distinct()
.order_by("block")
.values_list("block", flat=True)
]


class BlockInventoryFilterSet(WagtailFilterSet):
include_page_blocks = django_filters.AllValuesMultipleFilter(
include_page_blocks = django_filters.MultipleChoiceFilter(
field_name="page_blocks__block",
label="Include Blocks",
distinct=True,
widget=autocomplete.Select2Multiple(
url="wagtailinventory:block_autocomplete"
),
choices=get_block_choices,
widget=SelectMultiple(attrs={"style": "overflow: auto"}),
)
exclude_page_blocks = django_filters.AllValuesMultipleFilter(
exclude_page_blocks = django_filters.MultipleChoiceFilter(
field_name="page_blocks__block",
label="Exclude Blocks",
distinct=True,
exclude=True,
widget=autocomplete.Select2Multiple(
url="wagtailinventory:block_autocomplete"
),
choices=get_block_choices,
widget=SelectMultiple(attrs={"style": "overflow: auto"}),
)
content_type = ContentTypeFilter(
label="Page Type",
Expand All @@ -60,9 +46,11 @@ class Meta:


class BlockInventoryReportView(PageReportView):
title = "Block inventory"
page_title = "Block inventory"
header_icon = "placeholder"
filterset_class = BlockInventoryFilterSet
index_url_name = "wagtailinventory:block_inventory_report"
index_results_url_name = "wagtailinventory:block_inventory_report_results"

@classmethod
def check_permissions(cls, request):
Expand Down
11 changes: 4 additions & 7 deletions wagtailinventory/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
delete_page_inventory,
update_page_inventory,
)
from wagtailinventory.views import (
BlockAutocompleteView,
BlockInventoryReportView,
)
from wagtailinventory.views import BlockInventoryReportView


@hooks.register("after_create_page")
Expand Down Expand Up @@ -61,9 +58,9 @@ def register_inventory_report_url():
name="block_inventory_report",
),
path(
"block-autocomplete/",
BlockAutocompleteView.as_view(),
name="block_autocomplete",
"results/",
BlockInventoryReportView.as_view(results_only=True),
name="block_inventory_report_results",
),
]

Expand Down

0 comments on commit 6a81357

Please sign in to comment.