Enhance ImagesViewSet and Images component with site and sector filtering
- Added site_id and sector_id query parameter support in ImagesViewSet for filtering content and task-linked images. - Implemented event listeners in the Images component to refresh data on site and sector changes. - Updated image prompt handling to allow undefined values.
This commit is contained in:
@@ -663,17 +663,47 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
||||
|
||||
account = getattr(request, 'account', None)
|
||||
|
||||
# Get site_id and sector_id from query parameters
|
||||
site_id = request.query_params.get('site_id')
|
||||
sector_id = request.query_params.get('sector_id')
|
||||
|
||||
# Get all content that has images (either directly or via task)
|
||||
# First, get content with direct image links
|
||||
queryset = Content.objects.filter(images__isnull=False)
|
||||
if account:
|
||||
queryset = queryset.filter(account=account)
|
||||
|
||||
# Apply site/sector filtering if provided
|
||||
if site_id:
|
||||
try:
|
||||
queryset = queryset.filter(site_id=int(site_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if sector_id:
|
||||
try:
|
||||
queryset = queryset.filter(sector_id=int(sector_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
# Also get content from images linked via task
|
||||
task_linked_images = Images.objects.filter(task__isnull=False, content__isnull=True)
|
||||
if account:
|
||||
task_linked_images = task_linked_images.filter(account=account)
|
||||
|
||||
# Apply site/sector filtering to task-linked images
|
||||
if site_id:
|
||||
try:
|
||||
task_linked_images = task_linked_images.filter(site_id=int(site_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if sector_id:
|
||||
try:
|
||||
task_linked_images = task_linked_images.filter(sector_id=int(sector_id))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
# Get content IDs from task-linked images
|
||||
task_content_ids = set()
|
||||
for image in task_linked_images:
|
||||
@@ -694,6 +724,7 @@ class ImagesViewSet(SiteSectorModelViewSet):
|
||||
for content_id in content_ids:
|
||||
try:
|
||||
content = Content.objects.get(id=content_id)
|
||||
|
||||
# Get images linked directly to content OR via task
|
||||
content_images = Images.objects.filter(
|
||||
Q(content=content) | Q(task=content.task)
|
||||
|
||||
Reference in New Issue
Block a user