set_url_paths Django 1.10 friendly, add a test

pull/3101/merge
Benjamin Bach 2016-10-18 13:55:10 +02:00 zatwierdzone przez Matt Westcott
rodzic fb06f6c0c1
commit 4a92505c3b
4 zmienionych plików z 19 dodań i 3 usunięć

Wyświetl plik

@ -14,6 +14,7 @@ Changelog
* Fix: Parent page link in page search modal no longer disappears on hover (Dan Braghis)
* Fix: ModelAdmin views now consistently call `get_context_data` (Andy Babic)
* Fix: Header for search results on the redirects index page now shows the correct count when the listing is paginated (Nick Smith)
* Fix: `set_url_paths` management command is now compatible with Django 1.10 (Benjamin Bach)
1.7 (20.10.2016)

Wyświetl plik

@ -29,6 +29,7 @@ Bug fixes
* Parent page link in page search modal no longer disappears on hover (Dan Braghis)
* ModelAdmin views now consistently call ``get_context_data`` (Andy Babic)
* Header for search results on the redirects index page now shows the correct count when the listing is paginated (Nick Smith)
* ``set_url_paths`` management command is now compatible with Django 1.10 (Benjamin Bach)
Upgrade considerations
======================

Wyświetl plik

@ -1,17 +1,20 @@
from __future__ import absolute_import, unicode_literals
from django.core.management.base import NoArgsCommand
from django.core.management.base import BaseCommand
from wagtail.wagtailcore.models import Page
class Command(NoArgsCommand):
class Command(BaseCommand):
help = 'Resets url_path fields on each page recursively'
def set_subtree(self, root, root_path):
root.url_path = root_path
root.save(update_fields=['url_path'])
for child in root.get_children():
self.set_subtree(child, root_path + child.slug + '/')
def handle_noargs(self, **options):
def handle(self, *args, **options):
for node in Page.get_root_nodes():
self.set_subtree(node, '/')

Wyświetl plik

@ -132,6 +132,17 @@ class TestMovePagesCommand(TestCase):
self.assertEqual(Page.objects.get(id=page_id).get_parent(), about_us)
class TestSetUrlPathsCommand(TestCase):
fixtures = ['test.json']
def run_command(self):
management.call_command('set_url_paths', interactive=False, stdout=StringIO())
def test_set_url_paths(self):
self.run_command()
class TestReplaceTextCommand(TestCase):
fixtures = ['test.json']