From bf03c05fa2a3a4734615c80be25e938f897cb908 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 26 Jun 2014 14:21:18 +0100 Subject: [PATCH] Changed **kwargs to update_attrs --- wagtail/wagtailcore/models.py | 7 ++++--- wagtail/wagtailcore/tests/test_page_model.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index e7cb616da..22d182284 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -556,7 +556,7 @@ class Page(MP_Node, ClusterableModel, Indexed): new_self.save() new_self._update_descendant_url_paths(old_url_path, new_url_path) - def copy(self, recursive=False, to=None, **update_fields): + def copy(self, recursive=False, to=None, update_attrs=None): # Make a copy page_copy = Page.objects.get(id=self.id).specific page_copy.pk = None @@ -565,8 +565,9 @@ class Page(MP_Node, ClusterableModel, Indexed): page_copy.numchild = 0 page_copy.path = None - for field, value in update_fields.items(): - setattr(page_copy, field, value) + if update_attrs: + for field, value in update_attrs.items(): + setattr(page_copy, field, value) if to: page_copy = to.add_child(instance=page_copy) diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index a109816ab..1b4ce76e8 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -233,7 +233,7 @@ class TestCopyPage(TestCase): about_us = SimplePage.objects.get(url_path='/home/about-us/') # Copy it - new_about_us = about_us.copy(title="New about us", slug='new-about-us') + new_about_us = about_us.copy(update_attrs={'title': "New about us", 'slug': 'new-about-us'}) # Check that new_about_us is correct self.assertIsInstance(new_about_us, SimplePage) @@ -250,7 +250,7 @@ class TestCopyPage(TestCase): christmas_event = EventPage.objects.get(url_path='/home/events/christmas/') # Copy it - new_christmas_event = christmas_event.copy(title="New christmas event", slug='new-christmas-event') + new_christmas_event = christmas_event.copy(update_attrs={'title': "New christmas event", 'slug': 'new-christmas-event'}) # Check that the speakers were copied self.assertEqual(new_christmas_event.speakers.count(), 1, "Child objects weren't copied") @@ -263,7 +263,7 @@ class TestCopyPage(TestCase): christmas_event = Page.objects.get(url_path='/home/events/christmas/') # Copy it - new_christmas_event = christmas_event.copy(title="New christmas event", slug='new-christmas-event') + new_christmas_event = christmas_event.copy(update_attrs={'title': "New christmas event", 'slug': 'new-christmas-event'}) # Check that the type of the new page is correct self.assertIsInstance(new_christmas_event, EventPage) @@ -275,7 +275,7 @@ class TestCopyPage(TestCase): events_index = EventIndex.objects.get(url_path='/home/events/') # Copy it - new_events_index = events_index.copy(recursive=True, title="New events index", slug='new-events-index') + new_events_index = events_index.copy(recursive=True, update_attrs={'title': "New events index", 'slug': 'new-events-index'}) # Get christmas event old_christmas_event = events_index.get_children().filter(slug='christmas').first() @@ -292,7 +292,7 @@ class TestCopyPage(TestCase): events_index = EventIndex.objects.get(url_path='/home/events/') # Copy it - new_events_index = events_index.copy(recursive=True, title="New events index", slug='new-events-index') + new_events_index = events_index.copy(recursive=True, update_attrs={'title': "New events index", 'slug': 'new-events-index'}) # Get christmas event old_christmas_event = events_index.get_children().filter(slug='christmas').first()