Add bulk update functionality for image status
- Introduced a new endpoint in the backend to handle bulk updates of image statuses by content ID or image IDs. - Updated the frontend to include a new row action for updating image status and integrated a modal for status confirmation. - Enhanced the API service to support bulk status updates and updated the images page to manage status updates effectively.
This commit is contained in:
@@ -504,6 +504,28 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
||||
'type': 'TaskError'
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@action(detail=False, methods=['post'], url_path='bulk_update', url_name='bulk_update')
|
||||
def bulk_update(self, request):
|
||||
"""Bulk update image status by content_id or image IDs"""
|
||||
content_id = request.data.get('content_id')
|
||||
image_ids = request.data.get('ids', [])
|
||||
status_value = request.data.get('status')
|
||||
|
||||
if not status_value:
|
||||
return Response({'error': 'No status provided'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
queryset = self.get_queryset()
|
||||
|
||||
# Update by content_id if provided, otherwise by image IDs
|
||||
if content_id:
|
||||
updated_count = queryset.filter(content_id=content_id).update(status=status_value)
|
||||
elif image_ids:
|
||||
updated_count = queryset.filter(id__in=image_ids).update(status=status_value)
|
||||
else:
|
||||
return Response({'error': 'Either content_id or ids must be provided'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
return Response({'updated_count': updated_count}, status=status.HTTP_200_OK)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='content_images', url_name='content_images')
|
||||
def content_images(self, request):
|
||||
"""Get images grouped by content - one row per content with featured and in-article images"""
|
||||
|
||||
Reference in New Issue
Block a user