Skip to content

Commit 701fcfe

Browse files
committed
add support for UUID to parentadmin.py
1 parent 4d3b3e3 commit 701fcfe

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

polymorphic_tree/admin/parentadmin.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import json, django
1+
import json
2+
import django
3+
from django.utils.six import integer_types
24
from future.builtins import str, int
35
from distutils.version import StrictVersion
46
from django.conf import settings
@@ -178,10 +180,19 @@ def api_node_moved_view(self, request):
178180
Update the position of a node, from a API request.
179181
"""
180182
try:
181-
moved_id = int(request.POST['moved_id'])
182-
target_id = int(request.POST['target_id'])
183+
try:
184+
moved_id = int(request.POST['moved_id'])
185+
target_id = int(request.POST['target_id'])
186+
except ValueError:
187+
moved_id = request.POST['moved_id']
188+
target_id = request.POST['target_id']
189+
183190
position = request.POST['position']
184-
previous_parent_id = int(request.POST['previous_parent_id']) or None
191+
192+
if isinstance(moved_id, integer_types) and isinstance(target_id, integer_types):
193+
previous_parent_id = int(request.POST['previous_parent_id']) or None
194+
else:
195+
previous_parent_id = request.POST['previous_parent_id'] or None
185196

186197
# Not using .non_polymorphic() so all models are downcasted to the derived model.
187198
# This causes the signal below to be emitted from the proper class as well.
@@ -198,7 +209,7 @@ def api_node_moved_view(self, request):
198209
'moved_id': moved_id,
199210
'error': _(u'Cannot place \u2018{0}\u2019 below \u2018{1}\u2019; a {2} does not allow children!').format(moved, target, target._meta.verbose_name)
200211
}), content_type='application/json', status=409) # Conflict
201-
if moved.parent_id != previous_parent_id:
212+
if str(moved.parent_id) != str(previous_parent_id):
202213
return HttpResponse(json.dumps({
203214
'action': 'reload',
204215
'error': 'Client seems to be out-of-sync, please reload!'
@@ -253,4 +264,3 @@ def _get_opt(model):
253264
return model._meta.app_label, model._meta.model_name # Django 1.7 format
254265
except AttributeError:
255266
return model._meta.app_label, model._meta.module_name
256-

0 commit comments

Comments
 (0)