Merge pull request #665 from mope/661-fix-page-reordering

Fix page reordering in Wagtail Admin
This commit is contained in:
Karl Hobley 2014-10-03 14:46:56 +01:00
commit f8bc358594
2 changed files with 13 additions and 7 deletions

View file

@ -9,12 +9,12 @@
{% include "wagtailadmin/shared/breadcrumb.html" with page=parent_page %}
</header>
<form id="page-reorder-form">
{% csrf_token %}
{% page_permissions parent_page as parent_page_perms %}
{% include "wagtailadmin/pages/list.html" with sortable=1 allow_navigation=1 full_width=1 parent_page=parent_page orderable=parent_page_perms.can_reorder_children %}
{% include "wagtailadmin/pages/list.html" with sortable=1 allow_navigation=1 full_width=1 parent_page=parent_page orderable=parent_page_perms.can_reorder_children %}
</form>
{% endblock %}
@ -30,9 +30,10 @@
var orderform = $('#page-reorder-form');
$('.listing tbody').sortable({
cursor: "move",
containment: "parent",
handle: ".handle",
cursor: "move",
tolerance: "pointer",
containment: "parent",
handle: ".handle",
items: "> tr",
axis: "y",
placeholder: "dropzone",

View file

@ -634,8 +634,13 @@ def set_page_position(request, page_to_move_id):
# so don't bother to catch InvalidMoveToDescendant
if position_page:
# Move page into this position
page_to_move.move(position_page, pos='left')
# If the page has been moved to the right, insert it to the
# right. If left, then left.
old_position = list(parent_page.get_children()).index(page_to_move)
if int(position) < old_position:
page_to_move.move(position_page, pos='left')
elif int(position) > old_position:
page_to_move.move(position_page, pos='right')
else:
# Move page to end
page_to_move.move(parent_page, pos='last-child')