-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #624 from uktrade/hotfix-list-slug-linked-pages
Management command that lists pages containing slug-base hyperlinking
- Loading branch information
Showing
4 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.core.management import BaseCommand | ||
from django.core.management.base import no_translations | ||
from wagtail.core.models import Page | ||
|
||
from django.forms.models import model_to_dict | ||
from django.urls import reverse | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'List pages that contain hyperlinks using slugs to identify the target page' | ||
|
||
@no_translations | ||
def handle(self, *args, **options): | ||
for instance in Page.objects.all().specific(): | ||
for value in model_to_dict(instance).values(): | ||
if isinstance(value, str) and 'slug:' in value: | ||
url = reverse('wagtailadmin_pages:edit', args=(instance.pk,)) | ||
self.stdout.write(self.style.WARNING(url)) | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from io import StringIO | ||
|
||
import pytest | ||
|
||
from django.core.management import call_command | ||
from django.urls import reverse | ||
|
||
from tests.export_readiness.factories import ArticlePageFactory, CountryGuidePageFactory | ||
from tests.invest.factories import InfoPageFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_slug_links(root_page): | ||
stdout = StringIO() | ||
|
||
guide = CountryGuidePageFactory.create( | ||
slug='bar', | ||
parent=root_page, | ||
section_one_body=f'[things](pk:{root_page.pk}) are nice', | ||
) | ||
article = ArticlePageFactory.create( | ||
parent=root_page, | ||
article_body_text=f'[things](slug:{guide.slug}) are good', | ||
) | ||
info = InfoPageFactory.create( | ||
parent=root_page, | ||
content_en_gb=f'[things](slug:{guide.slug}) are great', | ||
) | ||
|
||
call_command('list_slug_links', stdout=stdout) | ||
stdout.seek(0) | ||
urls = stdout.read() | ||
|
||
assert reverse('wagtailadmin_pages:edit', args=(article.pk,)) in urls | ||
assert reverse('wagtailadmin_pages:edit', args=(guide.pk,)) not in urls | ||
assert reverse('wagtailadmin_pages:edit', args=(info.pk,)) in urls |