mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 01:03:11 +00:00
Changed **kwargs to update_attrs
This commit is contained in:
parent
1367669685
commit
bf03c05fa2
2 changed files with 9 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue