Merge pull request #58 from ygwain/master

Ignore requests with wrong data
This commit is contained in:
Brandon Taylor
2013-11-03 06:26:02 -08:00
+4 -3
View File
@@ -216,6 +216,8 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
This view sets the ordering of the objects for the model type This view sets the ordering of the objects for the model type
and primary keys passed in. It must be an Ajax POST. and primary keys passed in. It must be an Ajax POST.
""" """
response = {'objects_sorted': False}
if request.is_ajax() and request.method == 'POST': if request.is_ajax() and request.method == 'POST':
try: try:
indexes = list(map(str, request.POST.get('indexes', []).split(','))) indexes = list(map(str, request.POST.get('indexes', []).split(',')))
@@ -240,10 +242,9 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
obj.save() obj.save()
start_index += step start_index += step
response = {'objects_sorted': True} response = {'objects_sorted': True}
except (KeyError, IndexError, klass.DoesNotExist, AttributeError): except (KeyError, IndexError, klass.DoesNotExist, AttributeError, ValueError):
pass pass
else:
response = {'objects_sorted': False}
return HttpResponse(json.dumps(response, ensure_ascii=False), return HttpResponse(json.dumps(response, ensure_ascii=False),
mimetype='application/json') mimetype='application/json')