Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
marteinn committed Mar 23, 2023
2 parents ca2303a + cf1fae0 commit 114064b
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 83 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
wagtail-version:
- 2.14.2
- 2.15.1
- 2.16.1
- 3.0.1
- 4.1.3
- 4.2.1
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
58 changes: 46 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
# Changelog

## 0.3.0
## [Unreleased]
### Added
### Changed
### Fixed
### Removed

## [1.0.0] - 2023-03-23
### Added
- Add delete_stray_pages command for clearing stray pages in trash can (@marteinn)
- Add support for moving deleted pages to trash can when using bulk actions (@rinti)

### Fixed
- Add Wagtail 4.1 and 4.2 support (@marteinn)
- Add python 3.11 support (@marteinn)
- Remove wagtailadmin.W003 warning in development (@marteinn)
- Fix incorrect test alias in docker-entrypoint.sh (@marteinn)
- Fix bug where pages deleted from trashcan was not properly deleted (@marteinn)
- Fix bug where two pages with the same slug couldn't be in the trash can at the same time (@rinti)

### Removed
- Drop Wagtail 2 support
- Drop Wagtail 3 support

## Upgrade considerations
- Due to a bug in delete pages are not properly removed, this was fixed in 1.0.0. Run `python manage.py delete_stray_pages` to fix this

## [0.3.0] - 2022-07-29
### Added
- Add Wagtail 3.0 compatibility (Thanks @polesello!)
- Add code and tests verifying urls gets preserved when moving pages (Andreas Bernacca)

## 0.2.1
### Fixed
- Add code and tests verifying urls gets preserved when moving pages (Andreas Bernacca)

## [0.2.1] - 2022-02-13
### Added
- Add Wagtail 2.16 compability (Andreas Bernacca)
- Fix: Make datetime time zone aware (Martin Sandström)
- Fix: Add custom text for when trash can is empty

### Fixed
- Make datetime time zone aware (Martin Sandström)
- Add custom text for when trash can is empty

## 0.2.0

## [0.2.0] - 2022-02-12
### Added
- Add changelog (Andreas Bernacca)
- Add translations (Alexandre Marinho)
- Add spanish translations (Yamil Jaskolowsk)
- Add swedish translations (Martin Sandström)
- Drop Wagtail <2.14 support
- Drop Python 3.5 and 3.6 support
- Fix: Add CI/CD deployment (Martin Sandström)
- Fix: Add Django 4.0 compability

### Fixed
- Add CI/CD deployment (Martin Sandström)
- Add Django 4.0 compability

## 0.1.1
### Removed
- Drop Wagtail <2.14 support
- Drop Python 3.5 and 3.6 support

## [0.1.1] - 2021-06-09
### Fixed
- Rename template directory from the legacy name `wagtail_recycle_bin` to `wagtail_trash`. (cspollar)


## 0.1.0
## [0.1.0]

- Initial release
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ case "$CMD" in
wait_for_db

echo Running tests
exec pytest --ds=pipit.settings.test
exec python runtests.py
;;

* )
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
author="Andreas Bernacca",
author_email="[email protected]",
install_requires=[
"wagtail>=2.14",
"wagtail>=4.1",
],
extras_require={
"testing": testing_extras,
Expand All @@ -40,13 +40,13 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Framework :: Django",
"Framework :: Django :: 2.2",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"License :: OSI Approved :: MIT License",
],
project_urls={
Expand Down
2 changes: 1 addition & 1 deletion tests/app/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from wagtail.core.models import Page, PageManager
from wagtail.models import Page, PageManager

from wagtail_trash.managers import TrashManager

Expand Down
4 changes: 3 additions & 1 deletion tests/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"wagtail.documents",
"wagtail.images",
"wagtail.admin",
"wagtail.core",
"wagtail",
]

ROOT_URLCONF = "tests.app.urls"
Expand Down Expand Up @@ -80,3 +80,5 @@
},
},
]

WAGTAILADMIN_BASE_URL = "http://localhost:8080"
4 changes: 2 additions & 2 deletions tests/app/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import wagtail.admin.urls
import wagtail.core.urls
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, re_path
from wagtail import urls as wagtail_urls

urlpatterns = [
re_path(r"^admin/", include(wagtail.admin.urls)),
re_path(r"", include(wagtail.core.urls)),
re_path(r"", include(wagtail_urls)),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
90 changes: 84 additions & 6 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.shortcuts import reverse
from django.test import TestCase
from wagtail.core.models import Page
from wagtail.tests.utils import WagtailTestUtils
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

from wagtail_trash.models import TrashCan, TrashCanPage
from wagtail_trash.views import trash_delete
from wagtail_trash.views import trash_bulk_delete, trash_delete
from wagtail_trash.wagtail_hooks import TrashCanModelAdmin

trash_admin_url_helper = TrashCanModelAdmin().url_helper
Expand Down Expand Up @@ -82,6 +82,60 @@ def test_removing_page_sends_it_to_trash_can(self):
assert new_page.child_of(TrashCanPage.objects.first())
assert TrashCan.objects.count() == 1

def test_bulk_delete_sets_and_unsets_slug(self):
from wagtail_trash.wagtail_hooks import urlconf_time

root_page = Page.objects.get(url_path="/")

new_page1 = Page(title="new page 1")

p1 = root_page.add_child(instance=new_page1)

p1_slug = p1.slug

with self.register_hook("before_bulk_action", trash_bulk_delete):
delete_url = reverse(
"wagtail_bulk_action", args=("wagtailcore", "page", "delete")
)
id_query = "?id=" + "&id=".join([str(p1.id)])
self.client.post(delete_url + id_query)

p1.refresh_from_db()
self.assertEqual(f"trash-{p1.pk}-{p1_slug}", p1.slug)

with self.register_hook("register_admin_urls", urlconf_time):
restore_url = reverse("wagtail_trash_restore", args=(p1.pk,))
self.client.get(restore_url)

p1.refresh_from_db()
self.assertEqual(p1_slug, p1.slug)

def test_bulk_delete_sends_to_trash_can(self):
root_page = Page.objects.get(url_path="/")

new_page1 = Page(title="new page 1")
new_page2 = Page(title="new page 2")
new_page3 = Page(title="new page 3")
new_page4 = Page(title="new page 4")

p1 = root_page.add_child(instance=new_page1)
p2 = root_page.add_child(instance=new_page2)
p3 = root_page.add_child(instance=new_page3)
p4 = root_page.add_child(instance=new_page4)

assert TrashCan.objects.count() == 0

with self.register_hook("before_bulk_action", trash_bulk_delete):
delete_url = reverse(
"wagtail_bulk_action", args=("wagtailcore", "page", "delete")
)
id_query = "?id=" + "&id=".join(
[str(p1.id), str(p2.id), str(p3.id), str(p4.id)]
)
self.client.post(delete_url + id_query)

assert TrashCan.objects.count() == 4

def test_removing_page_from_bin_deletes_it(self):
root_page = Page.objects.get(url_path="/")

Expand All @@ -93,11 +147,35 @@ def test_removing_page_from_bin_deletes_it(self):
self.client.post(delete_url)
assert TrashCan.objects.count() == 1

delete_url = reverse("wagtailadmin_pages:delete", args=(new_page.id,))
trash_can_item = TrashCan.objects.first()
delete_url = trash_admin_url_helper.get_action_url(
"delete",
trash_can_item.id,
)
self.client.post(delete_url)
assert not Page.objects.filter(title="delete page")
assert TrashCan.objects.count() == 0

assert not Page.objects.filter(title="delete page")
assert TrashCan.objects.count() == 0
def test_removing_two_pages_with_same_slug(self):
root_page = Page.objects.get(url_path="/")

cat = Page(title="category 1", slug="category-1")
cat_instance = root_page.add_child(instance=cat)
cat_2 = Page(title="category 2", slug="category-2")
cat_instance_2 = root_page.add_child(instance=cat_2)

delete = Page(title="delete", slug="delete")
delete_instance = cat_instance.add_child(instance=delete)
delete_2 = Page(title="delete", slug="delete")
delete_instance_2 = cat_instance_2.add_child(instance=delete_2)

with self.register_hook("before_delete_page", trash_delete):
delete_url = reverse("wagtailadmin_pages:delete", args=(delete.id,))
self.client.post(delete_url)
delete_url = reverse("wagtailadmin_pages:delete", args=(delete_2.id,))
self.client.post(delete_url)

self.assertEqual(TrashCan.objects.count(), 2)

def test_removing_page_unpublishes_all_sub_pages(self):
root_page = Page.objects.get(url_path="/")
Expand Down
31 changes: 27 additions & 4 deletions tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from django.core.management import call_command
from django.test import TestCase
from django.utils import timezone
from wagtail.core.models import Page
from wagtail.tests.utils import WagtailTestUtils
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

from wagtail_trash.models import TrashCan
from wagtail_trash.models import TrashCan, TrashCanPage


class TestManagementCommands(TestCase, WagtailTestUtils):
class TestEmptyTrashCommand(TestCase, WagtailTestUtils):
def test_empty_bin_removes_pages_older_than_setting(self):
root_page = Page.objects.get(url_path="/")

Expand All @@ -31,3 +31,26 @@ def test_empty_bin_removes_pages_older_than_setting(self):
self.assertFalse(TrashCan.objects.filter(page_id=old_page.id).exists())
self.assertTrue(TrashCan.objects.filter(page_id=new_page.id).exists())
self.assertEqual(TrashCan.objects.count(), 1)


class TestDeleteStraypagesCommand(TestCase, WagtailTestUtils):
def test_delete_stray_pages_removes_pages_from_trash_can_witout_trashcan_association(
self,
):
root_page = Page.objects.get(url_path="/")

trash_can_page = TrashCanPage(title="Trash can")
root_page.add_child(instance=trash_can_page)

new_page = Page(title="New page")
trash_can_page.add_child(instance=new_page)
TrashCan.objects.create(page=new_page)

stray_page = Page(title="Stray page")
trash_can_page.add_child(instance=stray_page)

self.assertEqual(trash_can_page.get_children().count(), 2)

call_command("delete_stray_pages")

self.assertEqual(trash_can_page.get_children().count(), 1)
4 changes: 2 additions & 2 deletions tests/test_managers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import reverse
from django.test import TestCase
from wagtail.core.models import Page
from wagtail.tests.utils import WagtailTestUtils
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

from tests.app.models import TestPage
from wagtail_trash.models import TrashCan, TrashCanPage
Expand Down
4 changes: 2 additions & 2 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.contrib.auth.models import Group, Permission
from django.shortcuts import reverse
from django.test import TestCase
from wagtail.core.models import GroupPagePermission, Page
from wagtail.tests.utils import WagtailTestUtils
from wagtail.models import GroupPagePermission, Page
from wagtail.test.utils import WagtailTestUtils

from wagtail_trash.models import TrashCan, TrashCanPage
from wagtail_trash.views import trash_delete
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

from django.test import TestCase
from wagtail.core.models import Page
from wagtail.tests.utils import WagtailTestUtils
from wagtail.models import Page
from wagtail.test.utils import WagtailTestUtils

from wagtail_trash.utils import generate_page_data

Expand Down
25 changes: 25 additions & 0 deletions wagtail_trash/management/commands/delete_stray_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand

from wagtail_trash.models import TrashCan, TrashCanPage


class Command(BaseCommand):
"""
Delete stray pages from recycle bin(s)
Example:
./manage.py delete_stray_pages
"""

def handle(self, *args, **options):
trash_can_pages = TrashCanPage.objects.all()
num_deleted_pages = 0
for page in trash_can_pages:
for child_page in page.get_children():
if TrashCan.objects.filter(page=child_page).exists():
continue

child_page.delete()
num_deleted_pages += 1

self.stdout.write("Deleted {} stray pages".format(num_deleted_pages))
7 changes: 1 addition & 6 deletions wagtail_trash/managers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import wagtail
from django.db import models

if wagtail.VERSION >= (3, 0):
from wagtail.query import PageQuerySet
else:
from wagtail.core.query import PageQuerySet
from wagtail.query import PageQuerySet

from wagtail_trash.models import TrashCanPage

Expand Down
Loading

0 comments on commit 114064b

Please sign in to comment.