kopia lustrzana https://github.com/wagtail/wagtail
Allow changing the parent page when copying
rodzic
d4c5ec93ca
commit
b100d98d83
|
@ -621,11 +621,9 @@ def set_page_position(request, page_to_move_id):
|
|||
@permission_required('wagtailadmin.access_admin')
|
||||
def copy(request, page_id):
|
||||
page = Page.objects.get(id=page_id)
|
||||
parent_page = page.get_parent()
|
||||
|
||||
# Make sure this user has permission to add subpages on the parent
|
||||
if not parent_page.permissions_for_user(request.user).can_add_subpage():
|
||||
raise PermissionDenied
|
||||
# Parent page defaults to parent of source page
|
||||
parent_page = page.get_parent()
|
||||
|
||||
# Check if the user has permission to publish subpages on the parent
|
||||
can_publish = parent_page.permissions_for_user(request.user).can_publish_subpage()
|
||||
|
@ -634,31 +632,49 @@ def copy(request, page_id):
|
|||
form = CopyForm(request.POST or None, page=page, can_publish=can_publish)
|
||||
|
||||
# Check if user is submitting
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
# Copy the page
|
||||
new_page = page.copy(
|
||||
recursive=form.cleaned_data.get('copy_subpages'),
|
||||
update_attrs={
|
||||
'title': form.cleaned_data['new_title'],
|
||||
'slug': form.cleaned_data['new_slug'],
|
||||
},
|
||||
keep_live=(can_publish and form.cleaned_data.get('publish_copies')),
|
||||
)
|
||||
if request.method == 'POST':
|
||||
# Prefill parent_page in case the form is invalid (as prepopulated value for the form field,
|
||||
# because ModelChoiceField seems to not fall back to the user given value)
|
||||
parent_page = Page.objects.get(id=request.POST['new_parent_page'])
|
||||
|
||||
# Assign user of this request as the owner of all the new pages
|
||||
new_page.get_descendants(inclusive=True).update(owner=request.user)
|
||||
if form.is_valid():
|
||||
# Receive the parent page (this should never be empty)
|
||||
if form.cleaned_data['new_parent_page']:
|
||||
parent_page = form.cleaned_data['new_parent_page']
|
||||
|
||||
# Give a success message back to the user
|
||||
if form.cleaned_data.get('copy_subpages'):
|
||||
messages.success(request, _("Page '{0}' and {1} subpages copied.").format(page.title, new_page.get_descendants().count()))
|
||||
else:
|
||||
messages.success(request, _("Page '{0}' copied.").format(page.title))
|
||||
# Make sure this user has permission to add subpages on the parent
|
||||
if not parent_page.permissions_for_user(request.user).can_add_subpage():
|
||||
raise PermissionDenied
|
||||
|
||||
# Redirect to explore of parent page
|
||||
return redirect('wagtailadmin_explore', parent_page.id)
|
||||
# Re-check if the user has permission to publish subpages on the new parent
|
||||
can_publish = parent_page.permissions_for_user(request.user).can_publish_subpage()
|
||||
|
||||
# Copy the page
|
||||
new_page = page.copy(
|
||||
recursive=form.cleaned_data.get('copy_subpages'),
|
||||
to=parent_page,
|
||||
update_attrs={
|
||||
'title': form.cleaned_data['new_title'],
|
||||
'slug': form.cleaned_data['new_slug'],
|
||||
},
|
||||
keep_live=(can_publish and form.cleaned_data.get('publish_copies')),
|
||||
)
|
||||
|
||||
# Assign user of this request as the owner of all the new pages
|
||||
new_page.get_descendants(inclusive=True).update(owner=request.user)
|
||||
|
||||
# Give a success message back to the user
|
||||
if form.cleaned_data.get('copy_subpages'):
|
||||
messages.success(request, _("Page '{0}' and {1} subpages copied.").format(page.title, new_page.get_descendants().count()))
|
||||
else:
|
||||
messages.success(request, _("Page '{0}' copied.").format(page.title))
|
||||
|
||||
# Redirect to explore of parent page
|
||||
return redirect('wagtailadmin_explore', parent_page.id)
|
||||
|
||||
return render(request, 'wagtailadmin/pages/copy.html', {
|
||||
'page': page,
|
||||
'parent_page': parent_page,
|
||||
'form': form,
|
||||
})
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue