@valid_ajax_request_required
def reorder_view(request: WSGIRequest) -> JsonResponse:
body_data = json.loads(request.body.decode('utf-8'))
entry_id = body_data.get('entry_id', 0)
entry = get_object_or_null_obj(Entry, pk=entry_id)
if entry.id is None:
return JsonResponse({'type': 'error', 'message': 'Entry not found.'})
order = body_data.get('order', None)
if order is None:
return JsonResponse({'type': 'error', 'message': 'Order not found.'})
collection_id = body_data.get('collection_id', None)
collection = get_object_or_null_obj(Collection, pk=collection_id)
if collection.id is None:
return JsonResponse({'type': 'error', 'message': 'Collection not found.'})
entry.collection = collection
entry.save()
entry.ordering_services.processor.move_to_position(
destination_objects=(
collection.entries
.has_current_version()
.user_has_access(user=request.user)
.active()
),
position=order,
)
return JsonResponse({'type': 'success', 'message': 'Order reordered successfully'})