Commits

Steve Losh committed b0b2d4d

Fix the reorder-on-save issue.

Comments (0)

Files changed (2)

-# {{{
+# Imports {{{
 from django.conf import settings
 from django.contrib import admin
 from django.contrib.admin import helpers
 csrf_protect_m = method_decorator(csrf_protect)
 # }}}
 
+# Settings {{{
+PAGE_FIELDS = ['title', 'slug', 'template',]
+if not getattr(settings, 'STOAT_HIDE_NAVIGATION', False):
+    PAGE_FIELDS.append('show_in_nav')
+
+PAGE_COLS = ['indented_title', 'url']
+if getattr(settings, 'STOAT_DEBUG', False):
+    PAGE_COLS.append('template')
+# }}}
+
 def check_empty_dict(GET_dict):
     empty = True
     for k, v in GET_dict.items():
             return super(TreeChangeList, self).get_ordering()
         return None, 'asc'
 
-PAGE_FIELDS = ['title', 'slug', 'template',]
-if not getattr(settings, 'STOAT_HIDE_NAVIGATION', False):
-    PAGE_FIELDS.append('show_in_nav')
 
-PAGE_COLS = ['indented_title', 'url']
-if getattr(settings, 'STOAT_DEBUG', False):
-    PAGE_COLS.append('template')
 
 class PageAdmin(admin.ModelAdmin):
     save_on_top = True
     def get_changelist(self, request):
         return TreeChangeList
 
+
     def add_view(self, request, form_url='', extra_context=None):
         extra_context = extra_context or {}
 
         return super(PageAdmin, self).add_view(request, form_url=form_url,
                                                extra_context=extra_context)
 
+
     def save_model(self, request, obj, form, change):
         obj.save()
 
 
     def save(self, *args, **kwargs):
         cd = self.cleaned_data
-
         pid = cd.pop('parent', '')
         parent = Page.objects.get(pk=pid) if pid else None
 
             else:
                 self.instance = Page.add_root(**cd)
         else:
+            previous_parent = self.instance.get_parent()
             self.instance.save()
-            if parent:
-                self.instance.move(parent, pos='first-child')
-            else:
-                self.instance.move(Page.get_first_root_node(), pos='first-sibling')
+            if parent != previous_parent:
+                if parent:
+                    self.instance.move(parent, pos='first-child')
+                else:
+                    self.instance.move(Page.get_first_root_node(), pos='first-sibling')
 
         self.instance = Page.objects.get(pk=self.instance.pk)